Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,26 @@
|
|
1 |
-
# app.py (simplified
|
2 |
|
3 |
import os
|
4 |
import json
|
5 |
import time
|
6 |
import uuid
|
|
|
7 |
import gradio as gr
|
8 |
-
from transformers import pipeline
|
9 |
import numpy as np
|
10 |
import librosa # pip install librosa
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
# --- External logging: push to a HF Dataset repo on each submit (no local storage) ---
|
13 |
from datasets import Dataset, Features, Value, Audio, load_dataset
|
14 |
|
@@ -88,12 +100,15 @@ def _push_row_to_hf_dataset(row, audio_file_path):
|
|
88 |
)
|
89 |
return "Pushed to HF Dataset."
|
90 |
|
91 |
-
# ---
|
|
|
|
|
92 |
language_models = {
|
93 |
"Akan (Asante Twi)": "FarmerlineML/w2v-bert-2.0_twi_alpha_v1",
|
94 |
"Ewe": "FarmerlineML/w2v-bert-2.0_ewe_2",
|
95 |
"Kiswahili": "FarmerlineML/w2v-bert-2.0_swahili_alpha",
|
96 |
"Luganda": "FarmerlineML/w2v-bert-2.0_luganda",
|
|
|
97 |
"Brazilian Portuguese": "FarmerlineML/w2v-bert-2.0_brazilian_portugese_alpha",
|
98 |
"Fante": "misterkissi/w2v2-lg-xls-r-300m-fante",
|
99 |
"Bemba": "DarliAI/kissi-w2v2-lg-xls-r-300m-bemba",
|
@@ -115,7 +130,6 @@ language_models = {
|
|
115 |
# "HAITIAN CREOLE": "misterkissi/whisper-small-haitian-creole",
|
116 |
# "KABYLE": "misterkissi/w2v2-lg-xls-r-1b-kabyle",
|
117 |
"Yoruba": "FarmerlineML/w2v-bert-2.0_yoruba_v1",
|
118 |
-
"Luganda": "FarmerlineML/luganda_fkd",
|
119 |
"Luo": "FarmerlineML/w2v-bert-2.0_luo_v2",
|
120 |
"Somali": "FarmerlineML/w2v-bert-2.0_somali_alpha",
|
121 |
"Pidgin": "FarmerlineML/pidgin_nigerian",
|
@@ -143,10 +157,15 @@ def _evict_if_needed():
|
|
143 |
pass
|
144 |
|
145 |
def get_asr_pipeline(language_display: str):
|
|
|
|
|
|
|
146 |
if language_display in _PIPELINE_CACHE:
|
147 |
_touch_cache(language_display)
|
148 |
return _PIPELINE_CACHE[language_display]
|
|
|
149 |
model_id = language_models[language_display]
|
|
|
150 |
pipe = pipeline(
|
151 |
task="automatic-speech-recognition",
|
152 |
model=model_id,
|
|
|
1 |
+
# app.py (simplified + fixed language alignment; Luganda fkd commented out)
|
2 |
|
3 |
import os
|
4 |
import json
|
5 |
import time
|
6 |
import uuid
|
7 |
+
import logging
|
8 |
import gradio as gr
|
9 |
+
from transformers import pipeline
|
10 |
import numpy as np
|
11 |
import librosa # pip install librosa
|
12 |
|
13 |
+
# Optional: modest thread hints for CPU Spaces
|
14 |
+
try:
|
15 |
+
import torch
|
16 |
+
torch.set_num_threads(2)
|
17 |
+
torch.set_num_interop_threads(1)
|
18 |
+
except Exception:
|
19 |
+
pass
|
20 |
+
|
21 |
+
# Basic logging so we can verify which model is loaded per inference
|
22 |
+
logging.basicConfig(level=logging.INFO)
|
23 |
+
|
24 |
# --- External logging: push to a HF Dataset repo on each submit (no local storage) ---
|
25 |
from datasets import Dataset, Features, Value, Audio, load_dataset
|
26 |
|
|
|
100 |
)
|
101 |
return "Pushed to HF Dataset."
|
102 |
|
103 |
+
# --- Map display names to your HF Hub model IDs ---
|
104 |
+
# NOTE: Previously there were duplicate keys for "Luganda". We keep only the w2v-bert model
|
105 |
+
# and comment out the fkd variant to avoid accidental overrides.
|
106 |
language_models = {
|
107 |
"Akan (Asante Twi)": "FarmerlineML/w2v-bert-2.0_twi_alpha_v1",
|
108 |
"Ewe": "FarmerlineML/w2v-bert-2.0_ewe_2",
|
109 |
"Kiswahili": "FarmerlineML/w2v-bert-2.0_swahili_alpha",
|
110 |
"Luganda": "FarmerlineML/w2v-bert-2.0_luganda",
|
111 |
+
# "Luganda (fkd)": "FarmerlineML/luganda_fkd", # commented out per request
|
112 |
"Brazilian Portuguese": "FarmerlineML/w2v-bert-2.0_brazilian_portugese_alpha",
|
113 |
"Fante": "misterkissi/w2v2-lg-xls-r-300m-fante",
|
114 |
"Bemba": "DarliAI/kissi-w2v2-lg-xls-r-300m-bemba",
|
|
|
130 |
# "HAITIAN CREOLE": "misterkissi/whisper-small-haitian-creole",
|
131 |
# "KABYLE": "misterkissi/w2v2-lg-xls-r-1b-kabyle",
|
132 |
"Yoruba": "FarmerlineML/w2v-bert-2.0_yoruba_v1",
|
|
|
133 |
"Luo": "FarmerlineML/w2v-bert-2.0_luo_v2",
|
134 |
"Somali": "FarmerlineML/w2v-bert-2.0_somali_alpha",
|
135 |
"Pidgin": "FarmerlineML/pidgin_nigerian",
|
|
|
157 |
pass
|
158 |
|
159 |
def get_asr_pipeline(language_display: str):
|
160 |
+
if language_display not in language_models:
|
161 |
+
raise ValueError(f"Unknown language selection: {language_display}")
|
162 |
+
|
163 |
if language_display in _PIPELINE_CACHE:
|
164 |
_touch_cache(language_display)
|
165 |
return _PIPELINE_CACHE[language_display]
|
166 |
+
|
167 |
model_id = language_models[language_display]
|
168 |
+
logging.info(f"[ASR] Loading pipeline for '{language_display}' -> {model_id}")
|
169 |
pipe = pipeline(
|
170 |
task="automatic-speech-recognition",
|
171 |
model=model_id,
|