Luigi commited on
Commit
ac441da
Β·
1 Parent(s): 6ffa7d7

do not make path check in choose_file() as model has not been downloaded yet

Browse files
Files changed (1) hide show
  1. 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
- resolving relative paths to absolute, only returning ones that actually exist,
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
- # 3) sanity: drop any that aren’t real files
226
- if e8 and not os.path.exists(e8):
227
- print(f"[DEBUG] [{component}] int8 path does not exist, dropping: {e8!r}")
228
- e8 = None
229
- if e32 and not os.path.exists(e32):
230
- print(f"[DEBUG] [{component}] fp32 path does not exist, dropping: {e32!r}")
231
- e32 = None
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
- # 5) if exactly one exists β†’ pick it
241
  if (e8 is None) != (e32 is None):
242
- selected = e8 or e32
243
- print(f"[DEBUG] [{component}] Only one available, selecting: {selected!r}")
244
- return selected
245
 
246
- # 6) otherwise, both exist β†’ int8 if requested & available, else fp32
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