Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,23 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
|
|
3 |
|
4 |
-
|
|
|
|
|
5 |
|
6 |
def transcribe(audio):
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
return text
|
9 |
|
|
|
10 |
demo = gr.Interface(fn=transcribe, inputs=gr.Audio(type="filepath"), outputs="text")
|
11 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
import torch
|
4 |
+
import librosa
|
5 |
|
6 |
+
# Load ASR pipeline
|
7 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
+
asr_pipeline = pipeline("automatic-speech-recognition", model="monadical-labs/whisper-medium.en", device=device)
|
9 |
|
10 |
def transcribe(audio):
|
11 |
+
if audio is None:
|
12 |
+
return "Error: No audio file received."
|
13 |
+
|
14 |
+
# Load the audio file correctly
|
15 |
+
audio_data, sr = librosa.load(audio, sr=16000) # Resample to 16kHz (Whisper requirement)
|
16 |
+
|
17 |
+
# Process the audio
|
18 |
+
text = asr_pipeline(audio_data)["text"]
|
19 |
return text
|
20 |
|
21 |
+
# Create Gradio interface
|
22 |
demo = gr.Interface(fn=transcribe, inputs=gr.Audio(type="filepath"), outputs="text")
|
23 |
+
demo.launch()
|