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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -32
app.py CHANGED
@@ -59,6 +59,7 @@ def save_uploaded_file(uploaded_file):
59
  return file_path
60
 
61
  def display_results(video_url, video_file, description):
 
62
  if video_url:
63
  video_path = download_video(video_url)
64
  elif video_file:
@@ -66,45 +67,39 @@ def display_results(video_url, video_file, description):
66
  else:
67
  return "No video provided", None, None
68
 
 
 
69
  scenes = find_scenes(video_path)
70
  if not scenes:
71
  return "No scenes detected", None, None
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
 
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:
 
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