Add comprehensive error handling with traceback
Browse files
app.py
CHANGED
|
@@ -240,56 +240,66 @@ def transcribe(audio_upload: Any, lang_disp: str, return_ts: bool, progress=gr.P
|
|
| 240 |
"""
|
| 241 |
Main transcription function with ZeroGPU support.
|
| 242 |
"""
|
| 243 |
-
|
| 244 |
-
return "", "", None, "<div style='color:#666'>Please upload an audio file first.</div>"
|
| 245 |
-
|
| 246 |
-
# Debug: log the type and content of audio_upload
|
| 247 |
-
print(f"[DEBUG] audio_upload type: {type(audio_upload)}")
|
| 248 |
-
print(f"[DEBUG] audio_upload: {audio_upload}")
|
| 249 |
|
| 250 |
try:
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
|
| 294 |
|
| 295 |
def visualize_timestamps(audio_upload: Any, timestamps_json: Any):
|
|
|
|
| 240 |
"""
|
| 241 |
Main transcription function with ZeroGPU support.
|
| 242 |
"""
|
| 243 |
+
import traceback
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
|
| 245 |
try:
|
| 246 |
+
if audio_upload is None:
|
| 247 |
+
return "", "", None, "<div style='color:#666'>Please upload an audio file first.</div>"
|
| 248 |
+
|
| 249 |
+
# Debug: log the type and content of audio_upload
|
| 250 |
+
print(f"[DEBUG] audio_upload type: {type(audio_upload)}")
|
| 251 |
+
print(f"[DEBUG] audio_upload: {audio_upload}")
|
| 252 |
+
|
| 253 |
+
try:
|
| 254 |
+
audio_obj = _parse_audio_any(audio_upload)
|
| 255 |
+
except ValueError as e:
|
| 256 |
+
return "", "", None, f"<div style='color:red'>Error: {str(e)}<br>Debug: type={type(audio_upload)}, value={audio_upload}</div>"
|
| 257 |
+
|
| 258 |
+
language = None
|
| 259 |
+
if lang_disp and lang_disp != "Auto":
|
| 260 |
+
language = lang_map.get(lang_disp, lang_disp)
|
| 261 |
+
|
| 262 |
+
# Get model (lazy-loaded on first use when GPU is available)
|
| 263 |
+
print("[DEBUG] Loading ASR model...")
|
| 264 |
+
asr = get_asr_model()
|
| 265 |
+
print("[DEBUG] Model loaded, transcribing...")
|
| 266 |
+
|
| 267 |
+
# Perform transcription
|
| 268 |
+
results = asr.transcribe(
|
| 269 |
+
audio=audio_obj,
|
| 270 |
+
language=language,
|
| 271 |
+
return_time_stamps=return_ts,
|
| 272 |
+
)
|
| 273 |
+
print(f"[DEBUG] Transcription complete, results: {results}")
|
| 274 |
+
|
| 275 |
+
if not isinstance(results, list) or len(results) != 1:
|
| 276 |
+
return "", "", None, "<div style='color:red'>Unexpected result format.</div>"
|
| 277 |
+
|
| 278 |
+
r = results[0]
|
| 279 |
+
|
| 280 |
+
# Extract timestamps
|
| 281 |
+
ts_payload = None
|
| 282 |
+
if return_ts and hasattr(r, "time_stamps") and r.time_stamps:
|
| 283 |
+
ts_payload = [
|
| 284 |
+
dict(
|
| 285 |
+
text=getattr(t, "text", ""),
|
| 286 |
+
start_time=getattr(t, "start_time", 0),
|
| 287 |
+
end_time=getattr(t, "end_time", 0),
|
| 288 |
+
)
|
| 289 |
+
for t in r.time_stamps
|
| 290 |
+
]
|
| 291 |
+
|
| 292 |
+
# Note: Visualization is generated separately when user clicks "Visualize Timestamps"
|
| 293 |
+
return (
|
| 294 |
+
getattr(r, "language", "") or "",
|
| 295 |
+
getattr(r, "text", "") or "",
|
| 296 |
+
ts_payload,
|
| 297 |
+
"", # Empty HTML - visualization is triggered by separate button
|
| 298 |
+
)
|
| 299 |
+
except Exception as e:
|
| 300 |
+
error_trace = traceback.format_exc()
|
| 301 |
+
print(f"[ERROR] Exception in transcribe: {error_trace}")
|
| 302 |
+
return "", "", None, f"<div style='color:red'>Error: {str(e)}<br><pre>{error_trace}</pre></div>"
|
| 303 |
|
| 304 |
|
| 305 |
def visualize_timestamps(audio_upload: Any, timestamps_json: Any):
|