Commit
·
bb657cb
1
Parent(s):
1e083bf
Fix deployment issues: permissions, short videos, and AI responses
Browse files- Fix permission error by using /tmp/temp_segments with proper permissions
- Add minimum video length check (2x segment_length) for meaningful highlights
- Improve AI prompting for 256M model: max_new_tokens=8, greedy decoding
- Simplify prompt to force ONE WORD answers: YES or NO only
- Handle very short videos gracefully with informative error message
huggingface_exact_approach.py
CHANGED
|
@@ -154,7 +154,7 @@ class VideoHighlightDetector:
|
|
| 154 |
"role": "user",
|
| 155 |
"content": [
|
| 156 |
{"type": "video", "path": video_path},
|
| 157 |
-
{"type": "text", "text": f"""
|
| 158 |
}
|
| 159 |
]
|
| 160 |
|
|
@@ -169,9 +169,9 @@ class VideoHighlightDetector:
|
|
| 169 |
|
| 170 |
outputs = self.model.generate(
|
| 171 |
**inputs,
|
| 172 |
-
max_new_tokens=
|
| 173 |
-
do_sample=
|
| 174 |
-
temperature=0.
|
| 175 |
)
|
| 176 |
response = self.processor.decode(outputs[0], skip_special_tokens=True)
|
| 177 |
|
|
@@ -332,6 +332,15 @@ class VideoHighlightDetector:
|
|
| 332 |
|
| 333 |
print(f"📹 Video duration: {duration:.1f}s ({duration/60:.1f} minutes)")
|
| 334 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
# Step 1: Analyze overall video content
|
| 336 |
print("🎬 Step 1: Analyzing overall video content...")
|
| 337 |
video_desc = self.analyze_video_content(video_path)
|
|
@@ -349,8 +358,8 @@ class VideoHighlightDetector:
|
|
| 349 |
print()
|
| 350 |
|
| 351 |
# Step 3: Split video into segments
|
| 352 |
-
temp_dir = "temp_segments"
|
| 353 |
-
os.makedirs(temp_dir, exist_ok=True)
|
| 354 |
|
| 355 |
kept_segments1 = []
|
| 356 |
kept_segments2 = []
|
|
|
|
| 154 |
"role": "user",
|
| 155 |
"content": [
|
| 156 |
{"type": "video", "path": video_path},
|
| 157 |
+
{"type": "text", "text": f"""Looking for these highlights:\n{highlight_types}\n\nDoes this video segment match ANY of these highlights?\n\nAnswer with ONE WORD ONLY:\nYES or NO\n\nNothing else. Just YES or NO."""}]
|
| 158 |
}
|
| 159 |
]
|
| 160 |
|
|
|
|
| 169 |
|
| 170 |
outputs = self.model.generate(
|
| 171 |
**inputs,
|
| 172 |
+
max_new_tokens=8, # Force very short responses
|
| 173 |
+
do_sample=False, # Use greedy decoding for consistency
|
| 174 |
+
temperature=0.1 # Very low temperature for strict adherence
|
| 175 |
)
|
| 176 |
response = self.processor.decode(outputs[0], skip_special_tokens=True)
|
| 177 |
|
|
|
|
| 332 |
|
| 333 |
print(f"📹 Video duration: {duration:.1f}s ({duration/60:.1f} minutes)")
|
| 334 |
|
| 335 |
+
# Check if video is too short for meaningful highlights
|
| 336 |
+
if duration < segment_length * 2:
|
| 337 |
+
return {
|
| 338 |
+
"error": f"Video too short ({duration:.1f}s). Need at least {segment_length * 2:.1f}s for meaningful highlights.",
|
| 339 |
+
"video_description": "Video too short for analysis",
|
| 340 |
+
"total_segments": 0,
|
| 341 |
+
"selected_segments": 0
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
# Step 1: Analyze overall video content
|
| 345 |
print("🎬 Step 1: Analyzing overall video content...")
|
| 346 |
video_desc = self.analyze_video_content(video_path)
|
|
|
|
| 358 |
print()
|
| 359 |
|
| 360 |
# Step 3: Split video into segments
|
| 361 |
+
temp_dir = os.path.join("/tmp", "temp_segments")
|
| 362 |
+
os.makedirs(temp_dir, mode=0o755, exist_ok=True)
|
| 363 |
|
| 364 |
kept_segments1 = []
|
| 365 |
kept_segments2 = []
|