Spaces:
Build error
Build error
create app.py
Browse filesUsing distil-whisper model to convert speech to text
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import spaces
|
| 4 |
+
|
| 5 |
+
# Load the Whisper model from Hugging Face
|
| 6 |
+
model = pipeline("automatic-speech-recognition", model="distil-whisper/distil-large-v3", chunk_length_s=30, device=0)
|
| 7 |
+
|
| 8 |
+
# Function to process audio input and transcribe it
|
| 9 |
+
@spaces.GPU
|
| 10 |
+
def transcribe(audio):
|
| 11 |
+
# Load and preprocess the audio
|
| 12 |
+
transcription = model(audio,batch_size=1000, generate_kwargs={"task": "transcribe"}, return_timestamps=True)["text"]
|
| 13 |
+
return transcription
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# Gradio interface
|
| 17 |
+
interface = gr.Interface(
|
| 18 |
+
fn=transcribe,
|
| 19 |
+
inputs=gr.Audio(sources="microphone", type="filepath"),
|
| 20 |
+
outputs="text",
|
| 21 |
+
title="Whisper Voice Transcription with Hugging Face"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Launch the app
|
| 25 |
+
interface.launch()
|