Spaces:
Sleeping
Sleeping
added whisper models in dropdown to choose and transcribe.
Browse files
app.py
CHANGED
@@ -2,20 +2,46 @@ import torch
|
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
|
5 |
-
|
|
|
6 |
model="openai/whisper-small",
|
7 |
device="cuda" if torch.cuda.is_available() else "cpu")
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
def transcribe(audio):
|
10 |
text = pipe(audio)["text"]
|
11 |
return text
|
12 |
|
|
|
13 |
interface = gr.Interface(
|
14 |
-
fn=transcribe,
|
15 |
-
inputs=gr.Audio(sources=["microphone", "upload"], type="filepath"),
|
16 |
outputs="text",
|
17 |
title="Whisper Small",
|
18 |
description="Realtime demo for Speech recognition using a Whisper small model.",
|
19 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
if __name__ == "__main__":
|
21 |
interface.launch()
|
|
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
|
5 |
+
models = ["openai/whisper-small", "openai/whisper-base", "openai/whisper-medium", "openai/whisper-large"]
|
6 |
+
pipe = pipeline(task="automatic-speech-recognition",
|
7 |
model="openai/whisper-small",
|
8 |
device="cuda" if torch.cuda.is_available() else "cpu")
|
9 |
|
10 |
+
|
11 |
+
# Initialize the pipeline with the selected model
|
12 |
+
def initialize_pipeline(model_name):
|
13 |
+
# Placeholder for the actual pipeline initialization
|
14 |
+
return model_name
|
15 |
+
|
16 |
+
|
17 |
def transcribe(audio):
|
18 |
text = pipe(audio)["text"]
|
19 |
return text
|
20 |
|
21 |
+
|
22 |
interface = gr.Interface(
|
23 |
+
fn=transcribe,
|
24 |
+
inputs=gr.Audio(sources=["microphone", "upload"], type="filepath"),
|
25 |
outputs="text",
|
26 |
title="Whisper Small",
|
27 |
description="Realtime demo for Speech recognition using a Whisper small model.",
|
28 |
)
|
29 |
+
|
30 |
+
with gr.Blocks() as interface:
|
31 |
+
# Dropdown to select the model
|
32 |
+
model_dropdown = gr.Dropdown(choices=models, value=models[0], label="Select Model")
|
33 |
+
|
34 |
+
# Audio input component
|
35 |
+
audio_input = gr.Audio(sources=["microphone", "upload"], type="filepath", label="Upload or Record Audio")
|
36 |
+
# Text output component
|
37 |
+
text_output = gr.Textbox(label="Transcribed Text")
|
38 |
+
# Button to trigger transcription
|
39 |
+
transcribe_button = gr.Button("Transcribe")
|
40 |
+
# Event listener to initialize the pipeline when the model is selected
|
41 |
+
model_dropdown.change(fn=initialize_pipeline, inputs=model_dropdown, outputs=None)
|
42 |
+
# Event listener to transcribe the audio when the button is clicked
|
43 |
+
transcribe_button.click(fn=transcribe, inputs=[audio_input, model_dropdown], outputs=text_output)
|
44 |
+
# Event listener to show the download button when audio is uploaded or recorded
|
45 |
+
|
46 |
if __name__ == "__main__":
|
47 |
interface.launch()
|