jschwab21 commited on
Commit
32e394e
·
verified ·
1 Parent(s): 3278cee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -86
app.py CHANGED
@@ -1,11 +1,11 @@
1
  import gradio as gr
2
- from video_processing import process_video, download_video, find_scenes, analyze_scenes, extract_best_scene, cleanup_temp_files
3
  from gradio.themes.base import Base
4
  from gradio.themes.utils import colors, fonts, sizes
5
- from typing import Iterable
6
  import uuid
7
  import os
8
- import matplotlib as plt
 
9
 
10
  class CustomTheme(Base):
11
  def __init__(
@@ -50,49 +50,6 @@ class CustomTheme(Base):
50
 
51
  custom_theme = CustomTheme()
52
 
53
- def save_uploaded_file(uploaded_file):
54
- upload_dir = "uploaded_videos"
55
- os.makedirs(upload_dir, exist_ok=True)
56
- file_path = os.path.join(upload_dir, f"{uuid.uuid4()}.mp4")
57
- with open(file_path, "wb") as f:
58
- f.write(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:
65
- video_path = save_uploaded_file(video_file)
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, 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
-
96
  # Custom CSS for additional styling
97
  css = """
98
  body {
@@ -122,10 +79,7 @@ body {
122
  color: #ffffff;
123
  border: 2px solid #ffffff;
124
  }
125
- label[for="video_url"] {
126
- color: #eb5726 !important;
127
- }
128
- label[for="description"] {
129
  color: #eb5726 !important;
130
  }
131
  h3 {
@@ -143,50 +97,20 @@ h3 {
143
  }
144
  """
145
 
146
- def save_uploaded_file(uploaded_file):
147
- upload_dir = "uploaded_videos"
148
- os.makedirs(upload_dir, exist_ok=True)
149
- file_path = os.path.join(upload_dir, f"{uuid.uuid4()}.mp4")
150
- with open(file_path, "wb") as f:
151
- f.write(uploaded_file)
152
- return file_path
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():
179
  gr.Markdown("# **Sickstadium AI**", elem_classes="centered-markdown", elem_id="sickstadium-title")
180
- gr.Markdown("### Upload your videos. Find sick clips. Tell your truth.", elem_classes="centered-markdown")
181
- gr.Markdown("**Welcome to Sickstadium AI. Our goal is to empower content creators with the ability to tell their stories without the friction of traditional video editing software. Skip the timeline, and don't worry about your video editing skills. Upload your video, describe the clip you want, and let our AI video editor do the work for you. Get more info about the Sickstadium project at [Strongholdlabs.io](https://strongholdlabs.io/)**", elem_classes="centered-markdown")
182
  video_url = gr.Textbox(label="Video URL:", elem_id="video_url")
183
- video_file = gr.File(label="Upload Video File:", interactive=True, file_types=["video"], type="binary")
184
  description = gr.Textbox(label="Describe your clip:", elem_id="description")
185
  submit_button = gr.Button("Process Video", elem_id="submit_button")
186
  video_output = gr.Video(label="Processed Video", elem_id="video_output")
187
- download_output = gr.File(label="Download Processed Video", elem_id="download_output", type="binary") # Define this here
188
- sentiment_plot = gr.Plot(label="Sentiment Distribution", elem_id="sentiment_plot") # Adding elem_id for clarity
189
-
190
  submit_button.click(
191
  fn=display_results,
192
  inputs=[video_url, video_file, description],
 
1
  import gradio as gr
2
+ from video_processing import process_video
3
  from gradio.themes.base import Base
4
  from gradio.themes.utils import colors, fonts, sizes
 
5
  import uuid
6
  import os
7
+ import matplotlib.pyplot as plt
8
+ import numpy as np
9
 
10
  class CustomTheme(Base):
11
  def __init__(
 
50
 
51
  custom_theme = CustomTheme()
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  # Custom CSS for additional styling
54
  css = """
55
  body {
 
79
  color: #ffffff;
80
  border: 2px solid #ffffff;
81
  }
82
+ label[for="video_url"], label[for="description"], label[for="video_file"] {
 
 
 
83
  color: #eb5726 !important;
84
  }
85
  h3 {
 
97
  }
98
  """
99
 
100
+ def display_results(video_url, video_file, description):
101
+ video_path = process_video(video_url or video_file, description)
102
+ return video_path, video_path # This should be updated based on actual function output
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
  with gr.Blocks(theme=custom_theme, css=css) as demo:
105
  with gr.Column():
106
  gr.Markdown("# **Sickstadium AI**", elem_classes="centered-markdown", elem_id="sickstadium-title")
 
 
107
  video_url = gr.Textbox(label="Video URL:", elem_id="video_url")
108
+ video_file = gr.File(label="Upload Video File:", type="binary", interactive=True, file_types=["video"], elem_id="video_file")
109
  description = gr.Textbox(label="Describe your clip:", elem_id="description")
110
  submit_button = gr.Button("Process Video", elem_id="submit_button")
111
  video_output = gr.Video(label="Processed Video", elem_id="video_output")
112
+ download_output = gr.File(label="Download Processed Video", elem_id="download_output")
113
+ sentiment_plot = gr.Plot(label="Sentiment Distribution", elem_id="sentiment_plot")
 
114
  submit_button.click(
115
  fn=display_results,
116
  inputs=[video_url, video_file, description],