jschwab21 commited on
Commit
15637ee
·
verified ·
1 Parent(s): cfeee3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -42
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
- print("Starting video processing...")
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
- return "No video provided", None, None
69
-
70
- print(f"Video path: {video_path}")
71
-
72
- scenes = find_scenes(video_path)
73
- if not scenes:
74
- return "No scenes detected", None, None
75
-
76
- best_scene_info = analyze_scenes(video_path, scenes, description)
77
- if not best_scene_info:
78
- return "Analysis failed", None, None
79
-
80
- best_scene, sentiment_distribution = best_scene_info if isinstance(best_scene_info, tuple) else (None, None)
81
- print(f"Best scene: {best_scene}, Sentiments: {sentiment_distribution}")
82
-
83
- if best_scene:
84
- final_clip = extract_best_scene(video_path, best_scene)
85
- if final_clip:
86
- output_dir = "output"
87
- os.makedirs(output_dir, exist_ok=True)
88
- final_clip_path = os.path.join(output_dir, f"{uuid.uuid4()}_final_clip.mp4")
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
- return final_clip_path, "No sentiment data available"
99
  else:
100
- return "No matching scene found", None
101
- else:
102
- return "No suitable scenes found", None
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.Markdown("# **Sickstadium AI**", elem_classes="centered-markdown", elem_id="sickstadium-title")
155
- gr.Markdown("### Upload your videos. Find sick clips. Tell your truth.", elem_classes="centered-markdown")
156
- video_url = gr.Textbox(label="Video URL:", elem_id="video_url")
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
- sentiment_plot = gr.Plot(label="Sentiment Distribution", elem_id="sentiment_plot")
 
162
  submit_button.click(
163
  fn=display_results,
164
- inputs=[video_url, video_file, description],
165
- outputs=[video_output, sentiment_plot]
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()