Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers.utils import logging
|
| 2 |
+
logging.set_verbosity_error()
|
| 3 |
+
# from datasets import load_dataset
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
# dataset = load_dataset("librispeech_asr",
|
| 7 |
+
# split="train.clean.100",
|
| 8 |
+
# streaming=True,
|
| 9 |
+
# trust_remote_code=True)
|
| 10 |
+
|
| 11 |
+
asr = pipeline(task="automatic-speech-recognition",
|
| 12 |
+
model="openai/whisper-small")
|
| 13 |
+
|
| 14 |
+
demo = gr.Blocks()
|
| 15 |
+
|
| 16 |
+
def transcribe_long_form(filepath):
|
| 17 |
+
if filepath is None:
|
| 18 |
+
gr.Warning("No audio found, please retry.")
|
| 19 |
+
return ""
|
| 20 |
+
output = asr(
|
| 21 |
+
filepath,
|
| 22 |
+
max_new_tokens=256,
|
| 23 |
+
chunk_length_s=30,
|
| 24 |
+
batch_size=8,
|
| 25 |
+
)
|
| 26 |
+
return output["text"]
|
| 27 |
+
|
| 28 |
+
mic_transcribe = gr.Interface(
|
| 29 |
+
fn=transcribe_long_form,
|
| 30 |
+
inputs=gr.Audio(sources="microphone",
|
| 31 |
+
type="filepath"),
|
| 32 |
+
outputs=gr.Textbox(label="Transcription",
|
| 33 |
+
lines=3),
|
| 34 |
+
allow_flagging="never")
|
| 35 |
+
|
| 36 |
+
file_transcribe = gr.Interface(
|
| 37 |
+
fn=transcribe_long_form,
|
| 38 |
+
inputs=gr.Audio(sources="upload",
|
| 39 |
+
type="filepath"),
|
| 40 |
+
outputs=gr.Textbox(label="Transcription",
|
| 41 |
+
lines=3),
|
| 42 |
+
allow_flagging="never",
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
with demo:
|
| 46 |
+
gr.TabbedInterface(
|
| 47 |
+
[mic_transcribe,
|
| 48 |
+
file_transcribe],
|
| 49 |
+
["Transcribe Microphone",
|
| 50 |
+
"Transcribe Audio File"],
|
| 51 |
+
)
|
| 52 |
+
demo.launch(share=True)
|