Spaces:
Sleeping
Sleeping
Murali Chandran commited on
Commit ·
51d1560
1
Parent(s): f7ecc76
updated the app
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
-
import torchaudio
|
| 4 |
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
| 5 |
|
| 6 |
MODEL_ID = "codeninja3d/whisper-small-ls100"
|
|
@@ -10,19 +9,22 @@ model = WhisperForConditionalGeneration.from_pretrained(MODEL_ID)
|
|
| 10 |
model = model.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 11 |
|
| 12 |
def transcribe(audio):
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 15 |
pred_ids = model.generate(**inputs)
|
| 16 |
text = processor.batch_decode(pred_ids, skip_special_tokens=True)[0]
|
| 17 |
return text
|
| 18 |
|
| 19 |
demo = gr.Interface(
|
| 20 |
fn=transcribe,
|
| 21 |
-
inputs=gr.Audio(sources=["upload", "microphone"], type="
|
| 22 |
outputs="text",
|
| 23 |
-
title="Whisper Small LS100 - Fine-tuned
|
| 24 |
-
description="Upload or record
|
| 25 |
)
|
| 26 |
|
| 27 |
if __name__ == "__main__":
|
| 28 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
|
|
|
| 3 |
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
| 4 |
|
| 5 |
MODEL_ID = "codeninja3d/whisper-small-ls100"
|
|
|
|
| 9 |
model = model.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 10 |
|
| 11 |
def transcribe(audio):
|
| 12 |
+
# audio is (numpy array, sample_rate)
|
| 13 |
+
if audio is None:
|
| 14 |
+
return "⚠️ No audio input detected."
|
| 15 |
+
speech, sr = audio
|
| 16 |
+
inputs = processor(speech, sampling_rate=sr, return_tensors="pt").to(model.device)
|
| 17 |
pred_ids = model.generate(**inputs)
|
| 18 |
text = processor.batch_decode(pred_ids, skip_special_tokens=True)[0]
|
| 19 |
return text
|
| 20 |
|
| 21 |
demo = gr.Interface(
|
| 22 |
fn=transcribe,
|
| 23 |
+
inputs=gr.Audio(sources=["upload", "microphone"], type="numpy"),
|
| 24 |
outputs="text",
|
| 25 |
+
title="Whisper Small LS100 - Fine-tuned English ASR",
|
| 26 |
+
description="🎙 Upload or record audio (16 kHz) to get transcription."
|
| 27 |
)
|
| 28 |
|
| 29 |
if __name__ == "__main__":
|
| 30 |
+
demo.launch(share=True)
|