ApurvaKondekar commited on
Commit
83ae7f7
·
verified ·
1 Parent(s): 16e5e3a
Files changed (1) hide show
  1. app.py +35 -6
app.py CHANGED
@@ -338,13 +338,24 @@ def extract_audio_from_video(video_path):
338
  audio_path
339
  ]
340
 
341
- subprocess.run(
342
  command,
343
- stdout=subprocess.DEVNULL,
344
- stderr=subprocess.DEVNULL,
345
- check=True
346
  )
347
 
 
 
 
 
 
 
 
 
 
 
 
 
348
  return audio_path
349
 
350
  # =========================================================
@@ -443,8 +454,25 @@ def predict_emotion(video_file):
443
 
444
  try:
445
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
446
  audio_path = extract_audio_from_video(
447
- video_file
448
  )
449
 
450
  transcribed_text = transcribe_audio(
@@ -460,7 +488,7 @@ def predict_emotion(video_file):
460
  ) = preprocess_inputs(
461
  audio_path,
462
  transcribed_text,
463
- video_file
464
  )
465
 
466
  with torch.no_grad():
@@ -1522,6 +1550,7 @@ with gr.Blocks(
1522
  video_input = gr.Video(
1523
  label="Video Input",
1524
  height=360,
 
1525
  elem_classes="black-label"
1526
  )
1527
 
 
338
  audio_path
339
  ]
340
 
341
+ result = subprocess.run(
342
  command,
343
+ stdout=subprocess.PIPE,
344
+ stderr=subprocess.PIPE
 
345
  )
346
 
347
+ if result.returncode != 0:
348
+ error_msg = result.stderr.decode("utf-8", errors="replace")
349
+ print(f"[DEBUG] ffmpeg error: {error_msg}")
350
+ raise RuntimeError(
351
+ f"ffmpeg failed to extract audio: {error_msg[-200:]}"
352
+ )
353
+
354
+ if not os.path.exists(audio_path) or os.path.getsize(audio_path) == 0:
355
+ raise RuntimeError(
356
+ "ffmpeg produced no audio output — video may have no audio track"
357
+ )
358
+
359
  return audio_path
360
 
361
  # =========================================================
 
454
 
455
  try:
456
 
457
+ # Handle both string paths and dict inputs from Gradio
458
+ if isinstance(video_file, dict):
459
+ video_path = video_file.get("video", video_file.get("name", None))
460
+ else:
461
+ video_path = video_file
462
+
463
+ if video_path is None or not os.path.exists(video_path):
464
+ return (
465
+ "⚠ VIDEO FILE NOT FOUND — The recorded/uploaded file could not be located.",
466
+ None,
467
+ ""
468
+ )
469
+
470
+ print(f"[DEBUG] Processing video: {video_path}")
471
+ print(f"[DEBUG] File exists: {os.path.exists(video_path)}")
472
+ print(f"[DEBUG] File size: {os.path.getsize(video_path)} bytes")
473
+
474
  audio_path = extract_audio_from_video(
475
+ video_path
476
  )
477
 
478
  transcribed_text = transcribe_audio(
 
488
  ) = preprocess_inputs(
489
  audio_path,
490
  transcribed_text,
491
+ video_path
492
  )
493
 
494
  with torch.no_grad():
 
1550
  video_input = gr.Video(
1551
  label="Video Input",
1552
  height=360,
1553
+ sources=["upload", "webcam"],
1554
  elem_classes="black-label"
1555
  )
1556