jschwab21 commited on
Commit
7e4a743
·
verified ·
1 Parent(s): a10ca18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -17
app.py CHANGED
@@ -72,26 +72,39 @@ def display_results(video_url, video_file, description):
72
 
73
  best_scene_info = analyze_scenes(video_path, scenes, description)
74
  if best_scene_info:
75
- best_scene = best_scene_info[0]
76
- sentiment_distribution = best_scene_info[4] # Ensure you're accessing the correct index for sentiment_distribution
77
- final_clip = extract_best_scene(video_path, best_scene)
78
- if final_clip:
79
- output_dir = "output"
80
- os.makedirs(output_dir, exist_ok=True)
81
- final_clip_path = os.path.join(output_dir, f"{uuid.uuid4()}_final_clip.mp4")
82
- final_clip.write_videofile(final_clip_path, codec='libx264', audio_codec='aac')
83
- cleanup_temp_files()
 
 
 
 
 
 
 
 
 
 
84
 
85
- # Check if sentiment_distribution is correctly obtained
86
- if sentiment_distribution:
87
- plot = create_radial_plot(sentiment_distribution)
88
- return final_clip_path, plot
 
 
89
  else:
90
- return final_clip_path, "No sentiment data available"
91
  else:
92
- return "No matching scene found", None
93
- else:
94
- return "No suitable scenes found", None
 
95
 
96
 
97
  # Custom CSS for additional styling
 
72
 
73
  best_scene_info = analyze_scenes(video_path, scenes, description)
74
  if best_scene_info:
75
+ # Check if best_scene_info is a dictionary
76
+ if isinstance(best_scene_info, dict):
77
+ best_scene = best_scene_info.get('best_scene')
78
+ sentiment_distribution = best_scene_info.get('sentiment_distribution')
79
+ # Or if it's a tuple/list
80
+ elif isinstance(best_scene_info, (tuple, list)):
81
+ best_scene = best_scene_info[0]
82
+ sentiment_distribution = best_scene_info[-1] # Assuming it is the last element
83
+ else:
84
+ return "Unexpected data structure from analysis", None, None
85
+
86
+ if best_scene:
87
+ final_clip = extract_best_scene(video_path, best_scene)
88
+ if final_clip:
89
+ output_dir = "output"
90
+ os.makedirs(output_dir, exist_ok=True)
91
+ final_clip_path = os.path.join(output_dir, f"{uuid.uuid4()}_final_clip.mp4")
92
+ final_clip.write_videofile(final_clip_path, codec='libx264', audio_codec='aac')
93
+ cleanup_temp_files()
94
 
95
+ # Create the radial plot using sentiment_distribution
96
+ if sentiment_distribution:
97
+ plot = create_radial_plot(sentiment_distribution)
98
+ return final_clip_path, plot
99
+ else:
100
+ return final_clip_path, "No sentiment data available"
101
  else:
102
+ return "No matching scene found", None
103
  else:
104
+ return "No suitable scenes found", None
105
+
106
+ return "Analysis failed", None, None
107
+
108
 
109
 
110
  # Custom CSS for additional styling