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