Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
import librosa
|
| 4 |
-
from transformers import
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
model = Wav2Vec2ForCTC.from_pretrained("facebook/wav2vec2-base-960h")
|
| 9 |
|
| 10 |
def transcribe(audio):
|
| 11 |
audio, sr = librosa.load(audio, sr=16000)
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
logits = model(inputs.input_values).logits
|
| 16 |
-
|
| 17 |
-
predicted_ids = torch.argmax(logits, dim=-1)
|
| 18 |
-
transcription = processor.batch_decode(predicted_ids)[0]
|
| 19 |
-
|
| 20 |
-
return transcription
|
| 21 |
-
|
| 22 |
-
interface = gr.Interface(
|
| 23 |
fn=transcribe,
|
| 24 |
inputs=gr.Audio(type="filepath"),
|
| 25 |
outputs="text",
|
| 26 |
title="Speech to Text",
|
| 27 |
-
description="Upload audio file and get transcription"
|
| 28 |
)
|
| 29 |
|
| 30 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
import librosa
|
| 4 |
+
from transformers import pipeline
|
| 5 |
|
| 6 |
+
# Use pipeline instead (lighter + safer)
|
| 7 |
+
pipe = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-base-960h")
|
|
|
|
| 8 |
|
| 9 |
def transcribe(audio):
|
| 10 |
audio, sr = librosa.load(audio, sr=16000)
|
| 11 |
+
result = pipe(audio)
|
| 12 |
+
return result["text"]
|
| 13 |
|
| 14 |
+
iface = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
fn=transcribe,
|
| 16 |
inputs=gr.Audio(type="filepath"),
|
| 17 |
outputs="text",
|
| 18 |
title="Speech to Text",
|
|
|
|
| 19 |
)
|
| 20 |
|
| 21 |
+
iface.launch()
|