Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -69,21 +69,29 @@ def display_results(video_url, video_file, description):
|
|
69 |
if not scenes:
|
70 |
return "No scenes detected", None, "No data"
|
71 |
|
72 |
-
best_scene_times, sentiments = analyze_scenes(video_path, scenes, description)
|
73 |
if not best_scene_times:
|
74 |
return "No matching scene found", None, "No data"
|
75 |
|
76 |
-
final_clip = extract_best_scene(video_path, best_scene_times)
|
77 |
if final_clip:
|
78 |
output_dir = "output"
|
79 |
os.makedirs(output_dir, exist_ok=True)
|
80 |
final_clip_path = os.path.join(output_dir, f"{uuid.uuid4()}_final_clip.mp4")
|
81 |
final_clip.write_videofile(final_clip_path, codec='libx264', audio_codec='aac')
|
82 |
cleanup_temp_files()
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
return final_clip_path, final_clip_path, sentiment_display
|
85 |
else:
|
86 |
return "No matching scene found", None, "No data"
|
|
|
87 |
|
88 |
|
89 |
# Custom CSS for additional styling
|
|
|
69 |
if not scenes:
|
70 |
return "No scenes detected", None, "No data"
|
71 |
|
72 |
+
best_scene_times, sentiments = analyze_scenes(video_path, scenes, description)
|
73 |
if not best_scene_times:
|
74 |
return "No matching scene found", None, "No data"
|
75 |
|
76 |
+
final_clip = extract_best_scene(video_path, best_scene_times)
|
77 |
if final_clip:
|
78 |
output_dir = "output"
|
79 |
os.makedirs(output_dir, exist_ok=True)
|
80 |
final_clip_path = os.path.join(output_dir, f"{uuid.uuid4()}_final_clip.mp4")
|
81 |
final_clip.write_videofile(final_clip_path, codec='libx264', audio_codec='aac')
|
82 |
cleanup_temp_files()
|
83 |
+
|
84 |
+
# Calculate the total sum of sentiment scores
|
85 |
+
total_score = sum(sentiments.values())
|
86 |
+
if total_score == 0:
|
87 |
+
sentiment_display = "\n".join(f"**{k}:** 0%" for k in sentiments) # Handle case where all scores are zero
|
88 |
+
else:
|
89 |
+
sentiment_display = "\n".join(f"**{k}:** {v / total_score * 100:.1f}%" for k, v in sentiments.items())
|
90 |
+
|
91 |
return final_clip_path, final_clip_path, sentiment_display
|
92 |
else:
|
93 |
return "No matching scene found", None, "No data"
|
94 |
+
|
95 |
|
96 |
|
97 |
# Custom CSS for additional styling
|