Spaces:
Runtime error
Runtime error
shReYas0363
commited on
Commit
•
ff9d204
1
Parent(s):
1814983
first commit
Browse files- app.py +27 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import WhisperForConditionalGeneration, WhisperProcessor, WhisperTokenizer
|
4 |
+
import librosa
|
5 |
+
|
6 |
+
model_name = "shReYas0363/whisper-tiny-fine-tuned"
|
7 |
+
processor = WhisperProcessor.from_pretrained("openai/whisper-tiny")
|
8 |
+
tokenizer=WhisperTokenizer.from_pretrained("openai/whisper-tiny")
|
9 |
+
model = WhisperForConditionalGeneration.from_pretrained(model_name)
|
10 |
+
|
11 |
+
def transcribe(audio_file_path):
|
12 |
+
audio, sr = librosa.load(audio_file_path, sr=16000)
|
13 |
+
input_features = processor(audio, return_tensors="pt", sampling_rate=16000).input_features
|
14 |
+
with torch.no_grad():
|
15 |
+
predicted_ids = model.generate(input_features)
|
16 |
+
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
|
17 |
+
return transcription
|
18 |
+
|
19 |
+
interface = gr.Interface(
|
20 |
+
fn=transcribe,
|
21 |
+
inputs=gr.Audio(sources=["upload","microphone"], type="filepath"),
|
22 |
+
outputs="Transcription",
|
23 |
+
title="Whisper Tiny ASR",
|
24 |
+
description="Fine-tuned on AI4Bharat's svarah dataset"
|
25 |
+
)
|
26 |
+
|
27 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
torch
|
3 |
+
transformers
|
4 |
+
librosa
|