Spaces:
Runtime error
Runtime error
create app
Browse files- app.py +40 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
model_id = "mmhamdy/whisper-tiny-finetuned-minds14-en-us"
|
5 |
+
pipe = pipeline("automatic-speech-recognition", model=model_id)
|
6 |
+
|
7 |
+
def transcribe_speech(filepath):
|
8 |
+
output = pipe(
|
9 |
+
filepath,
|
10 |
+
max_new_tokens=256,
|
11 |
+
generate_kwargs={
|
12 |
+
"task": "transcribe",
|
13 |
+
"language": "english",
|
14 |
+
},
|
15 |
+
chunk_length_s=30,
|
16 |
+
batch_size=8,
|
17 |
+
)
|
18 |
+
return output["text"]
|
19 |
+
|
20 |
+
demo = gr.Blocks()
|
21 |
+
|
22 |
+
mic_transcribe = gr.Interface(
|
23 |
+
fn=transcribe_speech,
|
24 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
25 |
+
outputs=gr.outputs.Textbox(),
|
26 |
+
)
|
27 |
+
|
28 |
+
file_transcribe = gr.Interface(
|
29 |
+
fn=transcribe_speech,
|
30 |
+
inputs=gr.Audio(source="upload", type="filepath"),
|
31 |
+
outputs=gr.outputs.Textbox(),
|
32 |
+
)
|
33 |
+
|
34 |
+
with demo:
|
35 |
+
gr.TabbedInterface(
|
36 |
+
[mic_transcribe, file_transcribe],
|
37 |
+
["Transcribe Microphone", "Transcribe Audio File"],
|
38 |
+
)
|
39 |
+
|
40 |
+
demo.launch(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|