Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
asr = pipeline(task = "automatic-speech-recognition",
|
5 |
+
model = "openai/whisper-large-v3")
|
6 |
+
|
7 |
+
demo = gr.Blocks()
|
8 |
+
|
9 |
+
def transcribe_speech(filepath):
|
10 |
+
if filepath is None:
|
11 |
+
gr.Warning("No audio file found, please retry!")
|
12 |
+
return ""
|
13 |
+
output = asr(filepath)
|
14 |
+
return output["text"]
|
15 |
+
|
16 |
+
mic_transcribe = gr.Interface(
|
17 |
+
fn = transcribe_speech,
|
18 |
+
inputs = gr.Audio(sources = "microphone",
|
19 |
+
type = "filepath"),
|
20 |
+
outputs = gr.Textbox(label = "Transcription",
|
21 |
+
lines = 3),
|
22 |
+
allow_flagging = "never"
|
23 |
+
)
|
24 |
+
|
25 |
+
file_transcribe = gr.Interface (
|
26 |
+
fn = transcribe_speech,
|
27 |
+
inputs = gr.Audio(sources = "upload",
|
28 |
+
type = "filepath"),
|
29 |
+
outputs = gr.Textbox(label = "Transcription",
|
30 |
+
lines = 3),
|
31 |
+
allow_flagging = "never"
|
32 |
+
)
|
33 |
+
|
34 |
+
with demo:
|
35 |
+
gr.TabbedInterface(
|
36 |
+
[mic_transcribe,
|
37 |
+
file_transcribe],
|
38 |
+
["Transcribe Microphone",
|
39 |
+
"Transcribe Audio File"],
|
40 |
+
)
|
41 |
+
demo.launch()
|