Hokiman commited on
Commit
d8e6d38
·
1 Parent(s): c7b762e

Add comprehensive error handling with traceback

Browse files
Files changed (1) hide show
  1. app.py +58 -48
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
- if audio_upload is None:
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
- audio_obj = _parse_audio_any(audio_upload)
252
- except ValueError as e:
253
- return "", "", None, f"<div style='color:red'>Error: {str(e)}<br>Debug: type={type(audio_upload)}, value={audio_upload}</div>"
254
-
255
- language = None
256
- if lang_disp and lang_disp != "Auto":
257
- language = lang_map.get(lang_disp, lang_disp)
258
-
259
- # Get model (lazy-loaded on first use when GPU is available)
260
- asr = get_asr_model()
261
-
262
- # Perform transcription
263
- results = asr.transcribe(
264
- audio=audio_obj,
265
- language=language,
266
- return_time_stamps=return_ts,
267
- )
268
-
269
- if not isinstance(results, list) or len(results) != 1:
270
- return "", "", None, "<div style='color:red'>Unexpected result format.</div>"
271
-
272
- r = results[0]
273
-
274
- # Extract timestamps
275
- ts_payload = None
276
- if return_ts and hasattr(r, "time_stamps") and r.time_stamps:
277
- ts_payload = [
278
- dict(
279
- text=getattr(t, "text", ""),
280
- start_time=getattr(t, "start_time", 0),
281
- end_time=getattr(t, "end_time", 0),
282
- )
283
- for t in r.time_stamps
284
- ]
285
-
286
- # Note: Visualization is generated separately when user clicks "Visualize Timestamps"
287
- return (
288
- getattr(r, "language", "") or "",
289
- getattr(r, "text", "") or "",
290
- ts_payload,
291
- "", # Empty HTML - visualization is triggered by separate button
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):