jschwab21 commited on
Commit
7b7fbb7
·
verified ·
1 Parent(s): 55ea255

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -23
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
- final_clip = extract_best_scene(video_path, best_scene)
75
- if final_clip:
76
- output_dir = "output"
77
- os.makedirs(output_dir, exist_ok=True)
78
- final_clip_path = os.path.join(output_dir, f"{uuid.uuid4()}_final_clip.mp4")
79
- final_clip.write_videofile(final_clip_path, codec='libx264', audio_codec='aac')
80
- cleanup_temp_files()
81
- plot = create_radial_plot(sentiment_distribution)
82
- return final_clip_path, plot
 
 
 
 
 
 
 
 
83
  else:
84
- return "No matching scene found", None
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
- values = list(sentiments.values())
 
152
 
153
- # Create radial plot
154
- angles = np.linspace(0, 2 * np.pi, len(labels), endpoint=False).tolist()
 
155
 
156
  fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(polar=True))
157
- ax.fill(angles, values, color='red', alpha=0.25)
 
158
  ax.set_yticklabels([])
159
- ax.set_xticks(angles)
160
  ax.set_xticklabels(labels)
161
 
162
- # Save plot to a string buffer
163
- from io import BytesIO
164
- buf = BytesIO()
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():