Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the model
|
5 |
+
pipe = pipeline("automatic-speech-recognition", model="vargha/whisper-large-v3")
|
6 |
+
|
7 |
+
# Define the inference function
|
8 |
+
def transcribe_audio(audio):
|
9 |
+
if audio is None:
|
10 |
+
return "No audio file uploaded. Please try again."
|
11 |
+
|
12 |
+
try:
|
13 |
+
# Perform transcription
|
14 |
+
result = pipe(audio)["text"]
|
15 |
+
return result
|
16 |
+
except Exception as e:
|
17 |
+
return f"Error during transcription: {str(e)}"
|
18 |
+
|
19 |
+
# Create a Gradio interface for uploading audio or using the microphone
|
20 |
+
with gr.Blocks() as interface:
|
21 |
+
gr.Markdown("# Whisper Large V3 Speech Recognition")
|
22 |
+
gr.Markdown("Upload an audio file or use your microphone to transcribe speech to text.")
|
23 |
+
|
24 |
+
# Create the input and output components
|
25 |
+
audio_input = gr.Audio(type="filepath", label="Input Audio")
|
26 |
+
output_text = gr.Textbox(label="Transcription")
|
27 |
+
|
28 |
+
# Add a button to trigger the transcription
|
29 |
+
transcribe_button = gr.Button("Transcribe")
|
30 |
+
|
31 |
+
# Bind the transcribe_audio function to the button click
|
32 |
+
transcribe_button.click(fn=transcribe_audio, inputs=audio_input, outputs=output_text)
|
33 |
+
|
34 |
+
# Launch the Gradio app
|
35 |
+
interface.launch()
|