Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -71,17 +71,25 @@ def display_results(video_url, video_file, description):
|
|
71 |
return "No scenes detected", None, None
|
72 |
|
73 |
best_scene, sentiment_distribution = analyze_scenes(video_path, scenes, description)
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
else:
|
84 |
-
return "No
|
85 |
|
86 |
|
87 |
|
@@ -145,27 +153,26 @@ def save_uploaded_file(uploaded_file):
|
|
145 |
|
146 |
import matplotlib.pyplot as plt
|
147 |
|
|
|
148 |
def create_radial_plot(sentiments):
|
149 |
-
# Convert sentiment dictionary to lists
|
150 |
labels = list(sentiments.keys())
|
151 |
-
|
|
|
152 |
|
153 |
-
|
154 |
-
|
|
|
155 |
|
156 |
fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(polar=True))
|
157 |
-
ax.fill(angles,
|
|
|
158 |
ax.set_yticklabels([])
|
159 |
-
ax.set_xticks(angles)
|
160 |
ax.set_xticklabels(labels)
|
161 |
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
plt.savefig(buf, format='png')
|
166 |
-
plt.close(fig)
|
167 |
-
buf.seek(0)
|
168 |
-
return buf
|
169 |
|
170 |
with gr.Blocks(theme=custom_theme, css=css) as demo:
|
171 |
with gr.Column():
|
|
|
71 |
return "No scenes detected", None, None
|
72 |
|
73 |
best_scene, sentiment_distribution = analyze_scenes(video_path, scenes, description)
|
74 |
+
if best_scene:
|
75 |
+
final_clip = extract_best_scene(video_path, best_scene)
|
76 |
+
if final_clip:
|
77 |
+
output_dir = "output"
|
78 |
+
os.makedirs(output_dir, exist_ok=True)
|
79 |
+
final_clip_path = os.path.join(output_dir, f"{uuid.uuid4()}_final_clip.mp4")
|
80 |
+
final_clip.write_videofile(final_clip_path, codec='libx264', audio_codec='aac')
|
81 |
+
cleanup_temp_files()
|
82 |
+
|
83 |
+
# Create the radial plot using sentiment_distribution
|
84 |
+
if sentiment_distribution:
|
85 |
+
plot = create_radial_plot(sentiment_distribution)
|
86 |
+
return final_clip_path, plot
|
87 |
+
else:
|
88 |
+
return final_clip_path, "No sentiment data available"
|
89 |
+
else:
|
90 |
+
return "No matching scene found", None
|
91 |
else:
|
92 |
+
return "No suitable scenes found", None
|
93 |
|
94 |
|
95 |
|
|
|
153 |
|
154 |
import matplotlib.pyplot as plt
|
155 |
|
156 |
+
|
157 |
def create_radial_plot(sentiments):
|
|
|
158 |
labels = list(sentiments.keys())
|
159 |
+
stats = list(sentiments.values())
|
160 |
+
num_vars = len(labels)
|
161 |
|
162 |
+
angles = np.linspace(0, 2 * np.pi, num_vars, endpoint=False).tolist()
|
163 |
+
stats += stats[:1]
|
164 |
+
angles += angles[:1]
|
165 |
|
166 |
fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(polar=True))
|
167 |
+
ax.fill(angles, stats, color='red', alpha=0.25)
|
168 |
+
ax.plot(angles, stats, color='red', linewidth=2)
|
169 |
ax.set_yticklabels([])
|
170 |
+
ax.set_xticks(angles[:-1])
|
171 |
ax.set_xticklabels(labels)
|
172 |
|
173 |
+
plt.show()
|
174 |
+
|
175 |
+
return fig
|
|
|
|
|
|
|
|
|
176 |
|
177 |
with gr.Blocks(theme=custom_theme, css=css) as demo:
|
178 |
with gr.Column():
|