Spaces:
Running
Running
do not make path check in choose_file() as model has not been downloaded yet
Browse files- app/asr_worker.py +13 -43
app/asr_worker.py
CHANGED
@@ -203,53 +203,23 @@ def resample_audio(audio: np.ndarray, orig_sr: int, target_sr: int) -> np.ndarra
|
|
203 |
|
204 |
def choose_file(entry: dict, component: str, precision: str) -> str | None:
|
205 |
"""
|
206 |
-
Pick the best file for the given component ('encoder', 'decoder', or 'joiner')
|
207 |
-
|
208 |
-
and printing debug info at each step.
|
209 |
-
"""
|
210 |
-
# 1) grab the two candidates
|
211 |
-
raw8 = entry.get(f'{component}_int8')
|
212 |
-
raw32 = entry.get(f'{component}_fp32')
|
213 |
-
print(f"[DEBUG] [{component}] raw paths β int8: {raw8!r}, fp32: {raw32!r}")
|
214 |
-
|
215 |
-
# 2) resolve relative paths
|
216 |
-
def _abs(path: str | None) -> str | None:
|
217 |
-
if path and not os.path.isabs(path):
|
218 |
-
return os.path.abspath(path)
|
219 |
-
return path
|
220 |
-
|
221 |
-
e8 = _abs(raw8)
|
222 |
-
e32 = _abs(raw32)
|
223 |
-
print(f"[DEBUG] [{component}] abs paths β int8: {e8!r}, fp32: {e32!r}")
|
224 |
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
print(f"[DEBUG] [{component}] available after existence check β int8: {e8!r}, fp32: {e32!r}")
|
234 |
-
|
235 |
-
# 4) if neither exists, error out
|
236 |
-
if e8 is None and e32 is None:
|
237 |
-
print(f"[ERROR] [{component}] No available files (neither int8 nor fp32 found).")
|
238 |
-
return None
|
239 |
|
240 |
-
#
|
241 |
if (e8 is None) != (e32 is None):
|
242 |
-
|
243 |
-
print(f"[DEBUG] [{component}] Only one available, selecting: {selected!r}")
|
244 |
-
return selected
|
245 |
|
246 |
-
#
|
247 |
-
if precision == 'int8' and e8
|
248 |
-
print(f"[DEBUG] [{component}] Both available, precision='{precision}', selecting int8: {e8!r}")
|
249 |
-
return e8
|
250 |
-
else:
|
251 |
-
print(f"[DEBUG] [{component}] Both available, selecting fp32: {e32!r}")
|
252 |
-
return e32
|
253 |
|
254 |
# Create an online recognizer for a given model and precision
|
255 |
# model_id: full HF repo ID
|
|
|
203 |
|
204 |
def choose_file(entry: dict, component: str, precision: str) -> str | None:
|
205 |
"""
|
206 |
+
Pick the best file for the given component ('encoder', 'decoder', or 'joiner')
|
207 |
+
without checking whether the path exists (e.g. before downloading).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
|
209 |
+
1) Look up the two candidates.
|
210 |
+
2) If exactly one is present (non-None), return it.
|
211 |
+
3) Otherwise, if precision=='int8' and that candidate exists, return int8.
|
212 |
+
Else return fp32.
|
213 |
+
"""
|
214 |
+
e8 = entry.get(f'{component}_int8')
|
215 |
+
e32 = entry.get(f'{component}_fp32')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
|
217 |
+
# 1) If exactly one is present, pick it
|
218 |
if (e8 is None) != (e32 is None):
|
219 |
+
return e8 or e32
|
|
|
|
|
220 |
|
221 |
+
# 2) Otherwise, fallback to βint8 if requested & available, else fp32β
|
222 |
+
return e8 if precision == 'int8' and e8 else e32
|
|
|
|
|
|
|
|
|
|
|
223 |
|
224 |
# Create an online recognizer for a given model and precision
|
225 |
# model_id: full HF repo ID
|