jschwab21 commited on
Commit
54d1b5f
·
verified ·
1 Parent(s): 4393803

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -10
app.py CHANGED
@@ -5,6 +5,8 @@ from gradio.themes.utils import colors, fonts, sizes
5
  from typing import Iterable
6
  import uuid
7
  import os
 
 
8
 
9
  class CustomTheme(Base):
10
  def __init__(
@@ -57,21 +59,29 @@ def save_uploaded_file(uploaded_file):
57
  f.write(uploaded_file)
58
  return file_path
59
 
 
 
 
 
 
 
 
 
60
  def display_results(video_url, video_file, description):
61
  if video_url:
62
  video_path = download_video(video_url)
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_times, sentiments = analyze_scenes(video_path, scenes, description)
73
  if not best_scene_times:
74
- return "No matching scene found", None, "No data"
75
 
76
  final_clip = extract_best_scene(video_path, best_scene_times)
77
  if final_clip:
@@ -84,13 +94,34 @@ def display_results(video_url, video_file, description):
84
  # Calculate the total sum of sentiment scores
85
  total_score = sum(sentiments.values())
86
  if total_score == 0:
87
- sentiment_display = "\n".join(f"**{k}:** 0%" for k in sentiments) # Handle case where all scores are zero
88
- else:
89
- sentiment_display = "\n".join(f"**{k}:** {v / total_score * 100:.1f}%" for k, v in sentiments.items())
 
 
 
 
 
 
 
 
 
 
90
 
91
- return final_clip_path, final_clip_path, sentiment_display
 
 
 
 
 
 
 
 
 
92
  else:
93
- return "No matching scene found", None, "No data"
 
 
94
 
95
 
96
 
@@ -152,7 +183,7 @@ def save_uploaded_file(uploaded_file):
152
  f.write(uploaded_file)
153
  return file_path
154
 
155
- with gr.Blocks(theme=custom_theme, css=css) as demo:
156
  with gr.Column():
157
  gr.Markdown("# **Sickstadium AI**")
158
  video_url = gr.Textbox(label="Video URL:")
@@ -161,7 +192,7 @@ with gr.Blocks(theme=custom_theme, css=css) as demo:
161
  submit_button = gr.Button("Process Video")
162
  video_output = gr.Video(label="Processed Video")
163
  download_output = gr.File(label="Download Processed Video")
164
- sentiment_output = gr.Markdown(label="Sentiment Scores") # Using Markdown to display sentiment scores
165
  submit_button.click(fn=display_results, inputs=[video_url, video_file, description], outputs=[video_output, download_output, sentiment_output])
166
 
167
  demo.launch()
 
5
  from typing import Iterable
6
  import uuid
7
  import os
8
+ import plotly.graph_objects as go
9
+
10
 
11
  class CustomTheme(Base):
12
  def __init__(
 
59
  f.write(uploaded_file)
60
  return file_path
61
 
62
+ import gradio as gr
63
+ from video_processing import process_video, download_video, find_scenes, analyze_scenes, extract_best_scene, cleanup_temp_files
64
+ import plotly.graph_objects as go
65
+ import os
66
+ import uuid
67
+
68
+ # Assuming CustomTheme and other setups are defined above this snippet
69
+
70
  def display_results(video_url, video_file, description):
71
  if video_url:
72
  video_path = download_video(video_url)
73
  elif video_file:
74
  video_path = save_uploaded_file(video_file)
75
  else:
76
+ return "No video provided", None, None
77
 
78
  scenes = find_scenes(video_path)
79
  if not scenes:
80
+ return "No scenes detected", None, None
81
 
82
  best_scene_times, sentiments = analyze_scenes(video_path, scenes, description)
83
  if not best_scene_times:
84
+ return "No matching scene found", None, None
85
 
86
  final_clip = extract_best_scene(video_path, best_scene_times)
87
  if final_clip:
 
94
  # Calculate the total sum of sentiment scores
95
  total_score = sum(sentiments.values())
96
  if total_score == 0:
97
+ # Ensure there's no division by zero
98
+ sentiments = {k: 0 for k in sentiments}
99
+
100
+ # Prepare data for the radial chart
101
+ labels = list(sentiments.keys())
102
+ values = [v / total_score * 100 for v in sentiments.values()] # Normalize to percentages
103
+
104
+ # Create a polar chart
105
+ fig = go.Figure(data=go.Scatterpolar(
106
+ r=values,
107
+ theta=labels,
108
+ fill='toself'
109
+ ))
110
 
111
+ fig.update_layout(
112
+ polar=dict(
113
+ radialaxis=dict(
114
+ visible=True,
115
+ range=[0, max(values) if values else 1]
116
+ )),
117
+ showlegend=False
118
+ )
119
+
120
+ return final_clip_path, final_clip_path, fig
121
  else:
122
+ return "No matching scene found", None, None
123
+
124
+ # Assuming Gradio Blocks setup is defined below this snippet
125
 
126
 
127
 
 
183
  f.write(uploaded_file)
184
  return file_path
185
 
186
+ with gr.Blocks(theme=custom_theme) as demo:
187
  with gr.Column():
188
  gr.Markdown("# **Sickstadium AI**")
189
  video_url = gr.Textbox(label="Video URL:")
 
192
  submit_button = gr.Button("Process Video")
193
  video_output = gr.Video(label="Processed Video")
194
  download_output = gr.File(label="Download Processed Video")
195
+ sentiment_output = gr.Plot(label="Sentiment Analysis") # Changed from Markdown to Plot
196
  submit_button.click(fn=display_results, inputs=[video_url, video_file, description], outputs=[video_output, download_output, sentiment_output])
197
 
198
  demo.launch()