Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,24 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load the Whisper model for speech recognition
|
| 5 |
+
pipe = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
| 6 |
+
|
| 7 |
+
# Function to handle the speech recognition
|
| 8 |
+
def transcribe_audio(audio):
|
| 9 |
+
# Use the pipeline to transcribe the audio
|
| 10 |
+
result = pipe(audio)["text"]
|
| 11 |
+
return result
|
| 12 |
+
|
| 13 |
+
# Create a Gradio interface for the audio input and transcription output
|
| 14 |
+
interface = gr.Interface(
|
| 15 |
+
fn=transcribe_audio, # Function that handles the transcription
|
| 16 |
+
inputs=gr.Audio(source="microphone", type="filepath"), # Input as audio from mic
|
| 17 |
+
outputs="text", # Output as text
|
| 18 |
+
title="Whisper Speech Recognition",
|
| 19 |
+
description="Transcribe speech to text using OpenAI's Whisper model."
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Launch the Gradio interface
|
| 23 |
+
if __name__ == "__main__":
|
| 24 |
+
interface.launch()
|