ducduan2207 commited on
Commit
cc87f8a
Β·
verified Β·
1 Parent(s): 3199da5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -23
app.py CHANGED
@@ -1,7 +1,4 @@
1
  import os
2
- import sys
3
-
4
- # Disable hf_transfer to avoid whisperx crash
5
  os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "0"
6
 
7
  import gradio as gr
@@ -10,6 +7,7 @@ import tempfile
10
  import subprocess
11
  import shutil
12
  from pathlib import Path
 
13
 
14
  # ── Ensure uvx on PATH ───────────────────────────────────────────────────────
15
  def ensure_uvx():
@@ -26,25 +24,40 @@ def ensure_uvx():
26
 
27
  ensure_uvx()
28
 
29
- # ── Patch: skip whisperx entirely, return empty transcript ───────────────────
30
- # tribev2 uses whisperx only to get word-level text timing.
31
- # Skipping it means the model runs on video+audio only (no text modality).
32
- # Brain activation results are still valid for visual/auditory cortex analysis.
33
- def _skip_transcript(self, wav_filename, language):
34
- print("Skipping whisperx transcription (text modality disabled)")
35
- import pandas as pd
36
- return pd.DataFrame(columns=["word", "start", "end", "score"]) # empty transcript
37
-
38
- try:
39
- import tribev2.eventstransforms as _et
40
- # Find the right class name dynamically
41
- for name in dir(_et):
42
- cls = getattr(_et, name)
43
- if isinstance(cls, type) and hasattr(cls, '_get_transcript_from_audio'):
44
- setattr(cls, '_get_transcript_from_audio', _skip_transcript)
45
- print(f"Patched {name}._get_transcript_from_audio")
46
- except Exception as e:
47
- print(f"Patch warning: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
  # ── Lazy model loading ────────────────────────────────────────────────────────
50
  _model = None
@@ -91,7 +104,7 @@ def predict(video_file):
91
 
92
  overall = float(np.abs(preds).mean())
93
  md = "## 🧠 Brain Engagement Report\n\n"
94
- md += "> ℹ️ _Analysed using video + audio modalities (text modality disabled on CPU)_\n\n"
95
  md += f"**Overall score: `{overall:.3f}`**\n\n"
96
  md += "| Region | Activation | Level |\n|---|---|---|\n"
97
  for name, sl in ROIS.items():
 
1
  import os
 
 
 
2
  os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "0"
3
 
4
  import gradio as gr
 
7
  import subprocess
8
  import shutil
9
  from pathlib import Path
10
+ import pandas as pd
11
 
12
  # ── Ensure uvx on PATH ───────────────────────────────────────────────────────
13
  def ensure_uvx():
 
24
 
25
  ensure_uvx()
26
 
27
+ # ── Patch: intercept _get_transcript_from_audio to return empty DataFrame ────
28
+ # From traceback line 184: transcript.to_csv(...) β†’ transcript must be a DataFrame
29
+ # with columns: word, start, end (at minimum)
30
+ def _patch_tribev2():
31
+ try:
32
+ import tribev2.eventstransforms as et
33
+ import inspect
34
+
35
+ EMPTY_TRANSCRIPT = pd.DataFrame(columns=["word", "start", "end", "score"])
36
+
37
+ def _skip_transcript(self, wav_filename, language):
38
+ print(f"[PATCH] Skipping whisperx for {wav_filename}")
39
+ return EMPTY_TRANSCRIPT
40
+
41
+ patched = False
42
+ for name in dir(et):
43
+ obj = getattr(et, name)
44
+ if isinstance(obj, type) and hasattr(obj, '_get_transcript_from_audio'):
45
+ obj._get_transcript_from_audio = _skip_transcript
46
+ print(f"[PATCH] Patched {name}._get_transcript_from_audio β†’ empty DataFrame")
47
+ patched = True
48
+
49
+ if not patched:
50
+ # Fallback: patch at module level if class not found directly
51
+ print("[PATCH] No class found, trying module-level patch")
52
+ src = inspect.getsource(et)
53
+ print("[PATCH] Classes in eventstransforms:",
54
+ [name for name in dir(et) if isinstance(getattr(et, name), type)])
55
+
56
+ except Exception as e:
57
+ import traceback
58
+ print(f"[PATCH ERROR] {e}\n{traceback.format_exc()}")
59
+
60
+ _patch_tribev2()
61
 
62
  # ── Lazy model loading ────────────────────────────────────────────────────────
63
  _model = None
 
104
 
105
  overall = float(np.abs(preds).mean())
106
  md = "## 🧠 Brain Engagement Report\n\n"
107
+ md += "> ℹ️ _Analysed using video + audio (text modality disabled on CPU)_\n\n"
108
  md += f"**Overall score: `{overall:.3f}`**\n\n"
109
  md += "| Region | Activation | Level |\n|---|---|---|\n"
110
  for name, sl in ROIS.items():