Spaces:
Sleeping
Sleeping
Igoni Agent commited on
Commit ·
b9b2df9
1
Parent(s): c40f26e
fix: skip audio extraction on CPU (audio extractor needs CUDA)
Browse filesExtractAudioFromVideo extracts WAV, then audio extractor tries to
process it with CUDA which fails on HF CPU Spaces.
Now detects CUDA availability:
- CPU: Video events with filepath only -> visual extractor reads real frames
- GPU: Full pipeline with audio extraction
app.py
CHANGED
|
@@ -156,14 +156,15 @@ def _score_preds(pred_array) -> dict:
|
|
| 156 |
def _predict_file(file_path: str, mode: str = "video"):
|
| 157 |
"""Build proper events with filepath so the model actually processes media.
|
| 158 |
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
"""
|
| 166 |
import pandas as pd
|
|
|
|
| 167 |
from neuralset.events.utils import standardize_events
|
| 168 |
from neuralset.events.transforms import (
|
| 169 |
ExtractAudioFromVideo,
|
|
@@ -171,6 +172,8 @@ def _predict_file(file_path: str, mode: str = "video"):
|
|
| 171 |
RemoveMissing,
|
| 172 |
)
|
| 173 |
|
|
|
|
|
|
|
| 174 |
# Build initial event with filepath -- this is the critical part
|
| 175 |
event_type = "Audio" if mode == "audio" else "Video"
|
| 176 |
event = {
|
|
@@ -182,21 +185,24 @@ def _predict_file(file_path: str, mode: str = "video"):
|
|
| 182 |
}
|
| 183 |
events_df = pd.DataFrame([event])
|
| 184 |
|
| 185 |
-
#
|
| 186 |
-
# but with audio_only=True to skip whisperx/uvx transcription
|
| 187 |
transforms = [
|
| 188 |
-
ExtractAudioFromVideo(),
|
| 189 |
-
ChunkEvents(event_type_to_chunk="Audio", max_duration=60, min_duration=30),
|
| 190 |
ChunkEvents(event_type_to_chunk="Video", max_duration=60, min_duration=30),
|
| 191 |
-
RemoveMissing(),
|
| 192 |
]
|
| 193 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
events_df = standardize_events(events_df)
|
| 195 |
for transform in transforms:
|
| 196 |
events_df = transform(events_df)
|
| 197 |
events_df = standardize_events(events_df)
|
| 198 |
|
| 199 |
-
print(f"[Tribe V2] Events created: {len(events_df)} events, types: {events_df['type'].value_counts().to_dict()}", flush=True)
|
| 200 |
|
| 201 |
result = _model.predict(events_df, verbose=True)
|
| 202 |
pred_array = result[0] if isinstance(result, tuple) else result
|
|
|
|
| 156 |
def _predict_file(file_path: str, mode: str = "video"):
|
| 157 |
"""Build proper events with filepath so the model actually processes media.
|
| 158 |
|
| 159 |
+
The critical difference from the old code: we create Video events
|
| 160 |
+
with 'filepath' pointing to the actual file, so the visual extractor
|
| 161 |
+
reads real frame data.
|
| 162 |
|
| 163 |
+
On CPU Spaces: skip audio extraction (audio extractor needs CUDA).
|
| 164 |
+
On GPU local: enable full pipeline with audio.
|
| 165 |
"""
|
| 166 |
import pandas as pd
|
| 167 |
+
import torch
|
| 168 |
from neuralset.events.utils import standardize_events
|
| 169 |
from neuralset.events.transforms import (
|
| 170 |
ExtractAudioFromVideo,
|
|
|
|
| 172 |
RemoveMissing,
|
| 173 |
)
|
| 174 |
|
| 175 |
+
has_cuda = torch.cuda.is_available()
|
| 176 |
+
|
| 177 |
# Build initial event with filepath -- this is the critical part
|
| 178 |
event_type = "Audio" if mode == "audio" else "Video"
|
| 179 |
event = {
|
|
|
|
| 185 |
}
|
| 186 |
events_df = pd.DataFrame([event])
|
| 187 |
|
| 188 |
+
# Build transforms -- skip audio extraction on CPU
|
|
|
|
| 189 |
transforms = [
|
|
|
|
|
|
|
| 190 |
ChunkEvents(event_type_to_chunk="Video", max_duration=60, min_duration=30),
|
|
|
|
| 191 |
]
|
| 192 |
|
| 193 |
+
if has_cuda:
|
| 194 |
+
# Full pipeline: extract audio from video, then chunk both
|
| 195 |
+
transforms.insert(0, ExtractAudioFromVideo())
|
| 196 |
+
transforms.append(ChunkEvents(event_type_to_chunk="Audio", max_duration=60, min_duration=30))
|
| 197 |
+
|
| 198 |
+
transforms.append(RemoveMissing())
|
| 199 |
+
|
| 200 |
events_df = standardize_events(events_df)
|
| 201 |
for transform in transforms:
|
| 202 |
events_df = transform(events_df)
|
| 203 |
events_df = standardize_events(events_df)
|
| 204 |
|
| 205 |
+
print(f"[Tribe V2] Events created: {len(events_df)} events, types: {events_df['type'].value_counts().to_dict()}, cuda={has_cuda}", flush=True)
|
| 206 |
|
| 207 |
result = _model.predict(events_df, verbose=True)
|
| 208 |
pred_array = result[0] if isinstance(result, tuple) else result
|