| import gradio as gr | |
| import whisper | |
| import os | |
| def transcribe_audio(audio_file): | |
| if not os.path.exists(audio_file): | |
| print(f"Cannot locate file: {audio_file}") | |
| return "Error: Audio file not found!" | |
| else: | |
| print(f"Processing file: {audio_file}") | |
| model = whisper.load_model("base") | |
| result = model.transcribe(audio_file, fp16=False) | |
| return result["text"] | |
| def main(): | |
| audio_input = gr.Audio(sources=["microphone"], type="filepath") | |
| output_text = gr.Textbox(label="Transcription") | |
| iface = gr.Interface(fn=transcribe_audio, | |
| inputs=audio_input, | |
| outputs=output_text, | |
| title="Audio Transcription App", | |
| description="Record an audio file and hit the 'Submit' button" | |
| ) | |
| iface.launch( | |
| share=True, | |
| debug=True, | |
| ssr_mode=False, | |
| server_port=7860, | |
| #prevent_thread_lock=True | |
| ) | |
| if __name__ == '__main__': | |
| main() | |