Luigi commited on
Commit
f95c465
·
1 Parent(s): a6f5dad

fix for relative weight path

Browse files
Files changed (1) hide show
  1. app/asr_worker.py +23 -12
app/asr_worker.py CHANGED
@@ -204,33 +204,44 @@ def resample_audio(audio: np.ndarray, orig_sr: int, target_sr: int) -> np.ndarra
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
- but only if it really exists on disk.
208
 
209
- 1) Look up the two candidates.
210
- 2) Discard any whose path doesn’t exist.
211
- 3) If neither exists, print an error.
212
- 4) If exactly one remains, return it.
213
- 5) Otherwise, fall back to “int8 if requested & available, else fp32”.
 
214
  """
215
- e8 = entry.get(f'{component}_int8')
216
- e32 = entry.get(f'{component}_fp32')
 
217
 
218
- # Sanity: drop any that aren’t real files
 
 
 
 
 
 
 
 
 
219
  if e8 and not os.path.exists(e8):
220
  e8 = None
221
  if e32 and not os.path.exists(e32):
222
  e32 = None
223
 
224
- # If neither exists, error out
225
  if e8 is None and e32 is None:
226
  print(f"Error: no available files for component '{component}' (neither int8 nor fp32 found).")
227
  return None
228
 
229
- # If exactly one exists → pick it
230
  if (e8 is None) != (e32 is None):
231
  return e8 or e32
232
 
233
- # Otherwise, fall back to int8 if requested & available, else fp32
234
  return e8 if precision == 'int8' and e8 else e32
235
 
236
  # Create an online recognizer for a given model and precision
 
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, and only returning ones that actually exist.
208
 
209
+ 1) Grab the two candidates from the entry.
210
+ 2) If a path is relative, turn it into an absolute via os.path.abspath().
211
+ 3) Discard any whose path doesn’t exist on disk.
212
+ 4) If neither exists, print an error and return None.
213
+ 5) If exactly one exists, return that one.
214
+ 6) Otherwise (both exist), if precision=='int8' pick int8, else pick fp32.
215
  """
216
+ # 1) grab whatever the entry says
217
+ raw8 = entry.get(f'{component}_int8')
218
+ raw32 = entry.get(f'{component}_fp32')
219
 
220
+ # 2) resolve relative paths
221
+ def _abs(path: str | None) -> str | None:
222
+ if path and not os.path.isabs(path):
223
+ return os.path.abspath(path)
224
+ return path
225
+
226
+ e8 = _abs(raw8)
227
+ e32 = _abs(raw32)
228
+
229
+ # 3) sanity: drop any that aren’t real files
230
  if e8 and not os.path.exists(e8):
231
  e8 = None
232
  if e32 and not os.path.exists(e32):
233
  e32 = None
234
 
235
+ # 4) if neither exists, error out
236
  if e8 is None and e32 is None:
237
  print(f"Error: no available files for component '{component}' (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
  return e8 or e32
243
 
244
+ # 6) otherwise, both exist int8 if requested & available, else fp32
245
  return e8 if precision == 'int8' and e8 else e32
246
 
247
  # Create an online recognizer for a given model and precision