Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -72,26 +72,39 @@ def display_results(video_url, video_file, description):
|
|
72 |
|
73 |
best_scene_info = analyze_scenes(video_path, scenes, description)
|
74 |
if best_scene_info:
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
89 |
else:
|
90 |
-
return
|
91 |
else:
|
92 |
-
return "No
|
93 |
-
|
94 |
-
|
|
|
95 |
|
96 |
|
97 |
# Custom CSS for additional styling
|
|
|
72 |
|
73 |
best_scene_info = analyze_scenes(video_path, scenes, description)
|
74 |
if best_scene_info:
|
75 |
+
# Check if best_scene_info is a dictionary
|
76 |
+
if isinstance(best_scene_info, dict):
|
77 |
+
best_scene = best_scene_info.get('best_scene')
|
78 |
+
sentiment_distribution = best_scene_info.get('sentiment_distribution')
|
79 |
+
# Or if it's a tuple/list
|
80 |
+
elif isinstance(best_scene_info, (tuple, list)):
|
81 |
+
best_scene = best_scene_info[0]
|
82 |
+
sentiment_distribution = best_scene_info[-1] # Assuming it is the last element
|
83 |
+
else:
|
84 |
+
return "Unexpected data structure from analysis", None, None
|
85 |
+
|
86 |
+
if best_scene:
|
87 |
+
final_clip = extract_best_scene(video_path, best_scene)
|
88 |
+
if final_clip:
|
89 |
+
output_dir = "output"
|
90 |
+
os.makedirs(output_dir, exist_ok=True)
|
91 |
+
final_clip_path = os.path.join(output_dir, f"{uuid.uuid4()}_final_clip.mp4")
|
92 |
+
final_clip.write_videofile(final_clip_path, codec='libx264', audio_codec='aac')
|
93 |
+
cleanup_temp_files()
|
94 |
|
95 |
+
# Create the radial plot using sentiment_distribution
|
96 |
+
if sentiment_distribution:
|
97 |
+
plot = create_radial_plot(sentiment_distribution)
|
98 |
+
return final_clip_path, plot
|
99 |
+
else:
|
100 |
+
return final_clip_path, "No sentiment data available"
|
101 |
else:
|
102 |
+
return "No matching scene found", None
|
103 |
else:
|
104 |
+
return "No suitable scenes found", None
|
105 |
+
|
106 |
+
return "Analysis failed", None, None
|
107 |
+
|
108 |
|
109 |
|
110 |
# Custom CSS for additional styling
|