Spaces:
Running
Running
fix for relative weight path
Browse files- 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 |
-
|
208 |
|
209 |
-
1)
|
210 |
-
2)
|
211 |
-
3)
|
212 |
-
4) If
|
213 |
-
5)
|
|
|
214 |
"""
|
215 |
-
|
216 |
-
|
|
|
217 |
|
218 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
#
|
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 |
-
#
|
230 |
if (e8 is None) != (e32 is None):
|
231 |
return e8 or e32
|
232 |
|
233 |
-
#
|
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
|