| import gradio as gr |
| import torch |
| from transformers import pipeline |
|
|
| MODEL = "openai/whisper-tiny" |
|
|
| |
| device = 0 if torch.cuda.is_available() else -1 |
|
|
| transcriber = pipeline( |
| "automatic-speech-recognition", |
| model=MODEL, |
| device=device |
| ) |
|
|
| def transcribe(audio): |
| if audio is None: |
| return "Please upload or record audio." |
|
|
| result = transcriber(audio) |
| return result["text"] |
|
|
|
|
| demo = gr.Interface( |
| fn=transcribe, |
| inputs=gr.Audio( |
| sources=["microphone", "upload"], |
| type="filepath" |
| ), |
| outputs=gr.Textbox(label="Transcription"), |
| title="๐ Voice to Text", |
| description="Upload or record audio. Powered by Whisper running locally in HF Spaces." |
| ) |
|
|
| if __name__ == "__main__": |
| demo.launch() |