sifujohn commited on
Commit
2d25adc
·
verified ·
1 Parent(s): d634148

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import pipeline
4
+
5
+ MODEL = "openai/whisper-tiny" # good balance of speed + accuracy
6
+
7
+ # Load model once at startup
8
+ device = 0 if torch.cuda.is_available() else -1
9
+
10
+ transcriber = pipeline(
11
+ "automatic-speech-recognition",
12
+ model=MODEL,
13
+ device=device
14
+ )
15
+
16
+ def transcribe(audio):
17
+ if audio is None:
18
+ return "Please upload or record audio."
19
+
20
+ result = transcriber(audio)
21
+ return result["text"]
22
+
23
+
24
+ demo = gr.Interface(
25
+ fn=transcribe,
26
+ inputs=gr.Audio(
27
+ sources=["microphone", "upload"],
28
+ type="filepath"
29
+ ),
30
+ outputs=gr.Textbox(label="Transcription"),
31
+ title="🎙 Voice to Text",
32
+ description="Upload or record audio. Powered by Whisper running locally in HF Spaces."
33
+ )
34
+
35
+ if __name__ == "__main__":
36
+ demo.launch()