Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -6,11 +6,8 @@ import librosa
|
|
6 |
import json
|
7 |
|
8 |
model_id = "cawoylel/windanam_mms-1b-tts_v2"
|
9 |
-
|
10 |
-
|
11 |
-
# model = BetterTransformer.transform(model)
|
12 |
-
|
13 |
-
pipe = pipeline("automatic-speech-recognition", model=model_id) #, tokenizer=processor.tokenizer, feature_extractor=processor.feature_extractor)
|
14 |
|
15 |
def transcribe(audio_file_mic=None, audio_file_upload=None):
|
16 |
if audio_file_mic:
|
@@ -25,7 +22,18 @@ def transcribe(audio_file_mic=None, audio_file_upload=None):
|
|
25 |
if sample_rate != 16000:
|
26 |
speech = librosa.resample(speech, orig_sr=sample_rate, target_sr=16000)
|
27 |
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
|
31 |
description = '''Automatic Speech Recognition with [MMS](https://ai.facebook.com/blog/multilingual-model-speech-recognition/) (Massively Multilingual Speech) by Meta.
|
|
|
6 |
import json
|
7 |
|
8 |
model_id = "cawoylel/windanam_mms-1b-tts_v2"
|
9 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
10 |
+
model = Wav2Vec2ForCTC.from_pretrained(model_id)
|
|
|
|
|
|
|
11 |
|
12 |
def transcribe(audio_file_mic=None, audio_file_upload=None):
|
13 |
if audio_file_mic:
|
|
|
22 |
if sample_rate != 16000:
|
23 |
speech = librosa.resample(speech, orig_sr=sample_rate, target_sr=16000)
|
24 |
|
25 |
+
# Keep the same model in memory and simply switch out the language adapters by calling load_adapter() for the model and set_target_lang() for the tokenizer
|
26 |
+
processor.tokenizer.set_target_lang("ful")
|
27 |
+
model.load_adapter(language_code)
|
28 |
+
|
29 |
+
inputs = processor(speech, sampling_rate=16_000, return_tensors="pt")
|
30 |
+
|
31 |
+
with torch.no_grad():
|
32 |
+
outputs = model(**inputs).logits
|
33 |
+
|
34 |
+
ids = torch.argmax(outputs, dim=-1)[0]
|
35 |
+
transcription = processor.decode(ids)
|
36 |
+
return transcription
|
37 |
|
38 |
|
39 |
description = '''Automatic Speech Recognition with [MMS](https://ai.facebook.com/blog/multilingual-model-speech-recognition/) (Massively Multilingual Speech) by Meta.
|