Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,23 @@
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def transcribe(audio):
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
return text
|
| 9 |
|
| 10 |
iface = gr.Interface(
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
+
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
| 4 |
+
import librosa
|
| 5 |
+
import numpy as np
|
| 6 |
|
| 7 |
+
device = 'cpu'
|
| 8 |
+
processor = WhisperProcessor.from_pretrained("Neurai/Persian_ASR")
|
| 9 |
+
model = WhisperForConditionalGeneration.from_pretrained("Neurai/Persian_ASR").to(device)
|
| 10 |
+
forced_decoder_ids = processor.get_decoder_prompt_ids(language="fa", task="transcribe")
|
| 11 |
|
| 12 |
def transcribe(audio):
|
| 13 |
+
array, sample_rate = librosa.load(audio, sr=16000,mono=True)
|
| 14 |
+
array = librosa.to_mono(array)
|
| 15 |
+
array = librosa.resample(array, orig_sr=sample_rate, target_sr=16000)
|
| 16 |
+
array = list(array)
|
| 17 |
+
input_features = processor(arrs[0:int(14*16000)], sampling_rate=16000, return_tensors="pt").input_features
|
| 18 |
+
predicted_ids = model.generate(input_features.to(device))
|
| 19 |
+
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
|
| 20 |
+
text= transcription[0]
|
| 21 |
return text
|
| 22 |
|
| 23 |
iface = gr.Interface(
|