Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import whisper | |
| # Load the smallest model variant for fast CPU inference | |
| model = whisper.load_model("base") | |
| def transcribe_audio(audio_file): | |
| """ | |
| Transcribe the audio file using Whisper | |
| """ | |
| try: | |
| # Transcribe the audio | |
| result = model.transcribe(audio_file) | |
| return result["text"] | |
| except Exception as e: | |
| return f"Error during transcription: {str(e)}" | |
| # Create the Gradio interface | |
| interface = gr.Interface( | |
| fn=transcribe_audio, | |
| inputs=gr.Audio(type="filepath"), # Updated syntax | |
| outputs="text", | |
| title="Speech to Text Converter", | |
| description="Upload an audio file to convert speech to text using Whisper", | |
| examples=[["sample1.mp3"], ["sample2.wav"]], | |
| cache_examples=True | |
| ) | |
| # Launch the app | |
| if __name__ == "__main__": | |
| interface.launch(share=True) |