Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import torch
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
6 |
+
|
7 |
+
pipe = pipeline(
|
8 |
+
"automatic-speech-recognition",
|
9 |
+
model="openai/whisper-small.en",
|
10 |
+
chunk_length_s=30,
|
11 |
+
device=device,
|
12 |
+
)
|
13 |
+
|
14 |
+
# Function to transcribe audio
|
15 |
+
def transcribe(audio):
|
16 |
+
text = pipe(audio)["text"]
|
17 |
+
return text
|
18 |
+
|
19 |
+
# Gradio components
|
20 |
+
audio_input = gr.Audio(sources=["microphone"], type="filepath", label="Record Audio")
|
21 |
+
text_output = gr.Textbox(label="Transcription")
|
22 |
+
submit_button = gr.Button("Transcribe")
|
23 |
+
|
24 |
+
# Create the interface
|
25 |
+
with gr.Blocks() as demo:
|
26 |
+
with gr.Row():
|
27 |
+
audio_input.render()
|
28 |
+
submit_button.render()
|
29 |
+
with gr.Row():
|
30 |
+
text_output.render()
|
31 |
+
|
32 |
+
submit_button.click(fn=transcribe, inputs=audio_input, outputs=text_output)
|
33 |
+
|
34 |
+
|
35 |
+
demo.launch()
|