Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -63,13 +63,13 @@ def display_results(video_url, video_file, description):
|
|
63 |
elif video_file:
|
64 |
video_path = save_uploaded_file(video_file)
|
65 |
else:
|
66 |
-
return "No video provided", None
|
67 |
|
68 |
scenes = find_scenes(video_path)
|
69 |
if not scenes:
|
70 |
-
return "No scenes detected", None
|
71 |
|
72 |
-
best_scene = analyze_scenes(video_path, scenes, description)
|
73 |
final_clip = extract_best_scene(video_path, best_scene)
|
74 |
if final_clip:
|
75 |
output_dir = "output"
|
@@ -77,9 +77,10 @@ def display_results(video_url, video_file, description):
|
|
77 |
final_clip_path = os.path.join(output_dir, f"{uuid.uuid4()}_final_clip.mp4")
|
78 |
final_clip.write_videofile(final_clip_path, codec='libx264', audio_codec='aac')
|
79 |
cleanup_temp_files()
|
80 |
-
|
|
|
81 |
else:
|
82 |
-
return "No matching scene found", None
|
83 |
|
84 |
|
85 |
# Custom CSS for additional styling
|
@@ -151,6 +152,7 @@ with gr.Blocks(theme=custom_theme, css=css) as demo:
|
|
151 |
submit_button = gr.Button("Process Video", elem_id="submit_button")
|
152 |
video_output = gr.Video(label="Processed Video", elem_id="video_output")
|
153 |
download_output = gr.File(label="Download Processed Video", elem_id="download_output")
|
154 |
-
|
|
|
155 |
|
156 |
demo.launch()
|
|
|
63 |
elif video_file:
|
64 |
video_path = save_uploaded_file(video_file)
|
65 |
else:
|
66 |
+
return "No video provided", None, "No data"
|
67 |
|
68 |
scenes = find_scenes(video_path)
|
69 |
if not scenes:
|
70 |
+
return "No scenes detected", None, "No data"
|
71 |
|
72 |
+
best_scene, sentiments = analyze_scenes(video_path, scenes, description) # Ensure this function also returns sentiment data
|
73 |
final_clip = extract_best_scene(video_path, best_scene)
|
74 |
if final_clip:
|
75 |
output_dir = "output"
|
|
|
77 |
final_clip_path = os.path.join(output_dir, f"{uuid.uuid4()}_final_clip.mp4")
|
78 |
final_clip.write_videofile(final_clip_path, codec='libx264', audio_codec='aac')
|
79 |
cleanup_temp_files()
|
80 |
+
sentiment_display = "\n".join(f"{k}: {v:.2f}%" for k, v in sentiments.items()) # Format sentiment data
|
81 |
+
return final_clip_path, final_clip_path, sentiment_display
|
82 |
else:
|
83 |
+
return "No matching scene found", None, "No data"
|
84 |
|
85 |
|
86 |
# Custom CSS for additional styling
|
|
|
152 |
submit_button = gr.Button("Process Video", elem_id="submit_button")
|
153 |
video_output = gr.Video(label="Processed Video", elem_id="video_output")
|
154 |
download_output = gr.File(label="Download Processed Video", elem_id="download_output")
|
155 |
+
sentiment_output = gr.Textbox(label="Sentiment Scores", elem_id="sentiment_output", readonly=True)
|
156 |
+
submit_button.click(fn=display_results, inputs=[video_url, video_file, description], outputs=[video_output, download_output, sentiment_output])
|
157 |
|
158 |
demo.launch()
|