Spaces:
Running
Running
| import gradio as gr | |
| import whisper | |
| # Initialize the Whisper model | |
| model = whisper.load_model("large") | |
| def transcribe(audio_file): | |
| # Whisper expects a filepath, so we use the 'filepath' type in gr.Audio | |
| # audio_file now directly contains the path to the uploaded file | |
| audio = whisper.load_audio(audio_file) | |
| audio = whisper.pad_or_trim(audio) | |
| mel = whisper.log_mel_spectrogram(audio).to(model.device) | |
| options = whisper.DecodingOptions() | |
| result = whisper.decode(model, mel, options) | |
| return result.text | |
| # Create the Gradio interface | |
| iface = gr.Interface( | |
| fn=transcribe, | |
| inputs=gr.Audio(label="Upload your audio file", type="filepath"), | |
| outputs="text", | |
| title="Whisper ASR", | |
| description="Upload an audio file and it will be transcribed using OpenAI's Whisper model." | |
| ) | |
| # Launch the app | |
| if __name__ == "__main__": | |
| iface.launch() | |