Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -59,47 +59,40 @@ def save_uploaded_file(uploaded_file):
|
|
59 |
return file_path
|
60 |
|
61 |
def display_results(video_url, video_file, description):
|
62 |
-
|
63 |
if video_url:
|
64 |
video_path = download_video(video_url)
|
65 |
elif video_file:
|
66 |
video_path = save_uploaded_file(video_file)
|
67 |
else:
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
final_clip.write_videofile(final_clip_path, codec='libx264', audio_codec='aac')
|
90 |
-
cleanup_temp_files()
|
91 |
-
|
92 |
-
print(f"Final clip saved to: {final_clip_path}")
|
93 |
-
|
94 |
-
if sentiment_distribution:
|
95 |
-
plot = create_radial_plot(sentiment_distribution)
|
96 |
return final_clip_path, plot
|
97 |
else:
|
98 |
-
|
99 |
else:
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
|
104 |
|
105 |
# Custom CSS for additional styling
|
@@ -148,21 +141,19 @@ h3 {
|
|
148 |
text-transform: uppercase;
|
149 |
}
|
150 |
"""
|
151 |
-
|
152 |
with gr.Blocks(theme=custom_theme, css=css) as demo:
|
153 |
with gr.Column():
|
154 |
-
gr.
|
155 |
-
gr.
|
156 |
-
|
157 |
-
video_file = gr.File(label="Upload Video File:", interactive=True, file_types=["video"], type="binary")
|
158 |
-
description = gr.Textbox(label="Describe your clip:", elem_id="description")
|
159 |
submit_button = gr.Button("Process Video", elem_id="submit_button")
|
160 |
video_output = gr.Video(label="Processed Video", elem_id="video_output")
|
161 |
-
|
|
|
162 |
submit_button.click(
|
163 |
fn=display_results,
|
164 |
-
inputs=[
|
165 |
-
outputs=[video_output,
|
166 |
)
|
167 |
|
168 |
demo.launch()
|
|
|
59 |
return file_path
|
60 |
|
61 |
def display_results(video_url, video_file, description):
|
62 |
+
output_message = None
|
63 |
if video_url:
|
64 |
video_path = download_video(video_url)
|
65 |
elif video_file:
|
66 |
video_path = save_uploaded_file(video_file)
|
67 |
else:
|
68 |
+
output_message = "No video provided"
|
69 |
+
|
70 |
+
if not output_message:
|
71 |
+
scenes = find_scenes(video_path)
|
72 |
+
if not scenes:
|
73 |
+
output_message = "No scenes detected"
|
74 |
+
|
75 |
+
if not output_message:
|
76 |
+
best_scene_info = analyze_scenes(video_path, scenes, description)
|
77 |
+
if best_scene_info:
|
78 |
+
best_scene = best_scene_info[0] if isinstance(best_scene_info, tuple) else None
|
79 |
+
sentiment_distribution = best_scene_info[-1] if isinstance(best_scene_info, tuple) else None
|
80 |
+
final_clip = extract_best_scene(video_path, best_scene) if best_scene else None
|
81 |
+
if final_clip:
|
82 |
+
output_dir = "output"
|
83 |
+
os.makedirs(output_dir, exist_ok=True)
|
84 |
+
final_clip_path = os.path.join(output_dir, f"{uuid.uuid4()}_final_clip.mp4")
|
85 |
+
final_clip.write_videofile(final_clip_path, codec='libx264', audio_codec='aac')
|
86 |
+
cleanup_temp_files()
|
87 |
+
|
88 |
+
plot = create_radial_plot(sentiment_distribution) if sentiment_distribution else "No sentiment data available"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
return final_clip_path, plot
|
90 |
else:
|
91 |
+
output_message = "No matching scene found"
|
92 |
else:
|
93 |
+
output_message = "Analysis failed or no suitable scenes found"
|
94 |
+
|
95 |
+
return None, output_message
|
96 |
|
97 |
|
98 |
# Custom CSS for additional styling
|
|
|
141 |
text-transform: uppercase;
|
142 |
}
|
143 |
"""
|
|
|
144 |
with gr.Blocks(theme=custom_theme, css=css) as demo:
|
145 |
with gr.Column():
|
146 |
+
video_url_input = gr.Textbox(label="Video URL:", elem_id="video_url")
|
147 |
+
video_file_input = gr.File(label="Upload Video File:", interactive=True, file_types=["video"], type="binary")
|
148 |
+
description_input = gr.Textbox(label="Describe your clip:", elem_id="description")
|
|
|
|
|
149 |
submit_button = gr.Button("Process Video", elem_id="submit_button")
|
150 |
video_output = gr.Video(label="Processed Video", elem_id="video_output")
|
151 |
+
sentiment_plot_output = gr.Plot(label="Sentiment Distribution", elem_id="sentiment_plot")
|
152 |
+
|
153 |
submit_button.click(
|
154 |
fn=display_results,
|
155 |
+
inputs=[video_url_input, video_file_input, description_input],
|
156 |
+
outputs=[video_output, sentiment_plot_output]
|
157 |
)
|
158 |
|
159 |
demo.launch()
|