jschwab21 commited on
Commit
f9d282c
·
verified ·
1 Parent(s): 15637ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -43
app.py CHANGED
@@ -2,10 +2,9 @@ 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
  import uuid
6
  import os
7
- from typing import Iterable
8
-
9
 
10
  class CustomTheme(Base):
11
  def __init__(
@@ -57,43 +56,31 @@ def save_uploaded_file(uploaded_file):
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
- output_message = None
63
  if video_url:
64
  video_path = download_video(video_url)
65
  elif video_file:
66
  video_path = save_uploaded_file(video_file)
67
  else:
68
- output_message = "No video provided"
69
-
70
- if not output_message:
71
- scenes = find_scenes(video_path)
72
- if not scenes:
73
- output_message = "No scenes detected"
74
-
75
- if not output_message:
76
- best_scene_info = analyze_scenes(video_path, scenes, description)
77
- if best_scene_info:
78
- best_scene = best_scene_info[0] if isinstance(best_scene_info, tuple) else None
79
- sentiment_distribution = best_scene_info[-1] if isinstance(best_scene_info, tuple) else None
80
- final_clip = extract_best_scene(video_path, best_scene) if best_scene else None
81
- if final_clip:
82
- output_dir = "output"
83
- os.makedirs(output_dir, exist_ok=True)
84
- final_clip_path = os.path.join(output_dir, f"{uuid.uuid4()}_final_clip.mp4")
85
- final_clip.write_videofile(final_clip_path, codec='libx264', audio_codec='aac')
86
- cleanup_temp_files()
87
 
88
- plot = create_radial_plot(sentiment_distribution) if sentiment_distribution else "No sentiment data available"
89
- return final_clip_path, plot
90
- else:
91
- output_message = "No matching scene found"
92
- else:
93
- output_message = "Analysis failed or no suitable scenes found"
94
-
95
- return None, output_message
96
 
 
 
 
 
 
 
 
 
 
 
 
 
97
 
98
  # Custom CSS for additional styling
99
  css = """
@@ -124,7 +111,10 @@ body {
124
  color: #ffffff;
125
  border: 2px solid #ffffff;
126
  }
127
- label[for="video_url"], label[for="description"] {
 
 
 
128
  color: #eb5726 !important;
129
  }
130
  h3 {
@@ -141,19 +131,26 @@ h3 {
141
  text-transform: uppercase;
142
  }
143
  """
 
 
 
 
 
 
 
 
 
144
  with gr.Blocks(theme=custom_theme, css=css) as demo:
145
  with gr.Column():
146
- video_url_input = gr.Textbox(label="Video URL:", elem_id="video_url")
147
- video_file_input = gr.File(label="Upload Video File:", interactive=True, file_types=["video"], type="binary")
148
- description_input = gr.Textbox(label="Describe your clip:", elem_id="description")
 
 
 
149
  submit_button = gr.Button("Process Video", elem_id="submit_button")
150
  video_output = gr.Video(label="Processed Video", elem_id="video_output")
151
- sentiment_plot_output = gr.Plot(label="Sentiment Distribution", elem_id="sentiment_plot")
152
-
153
- submit_button.click(
154
- fn=display_results,
155
- inputs=[video_url_input, video_file_input, description_input],
156
- outputs=[video_output, sentiment_plot_output]
157
- )
158
 
159
- demo.launch()
 
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
 
9
  class CustomTheme(Base):
10
  def __init__(
 
56
  with open(file_path, "wb") as f:
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
+ scenes = find_scenes(video_path)
69
+ if not scenes:
70
+ return "No scenes detected", None
 
 
 
 
 
71
 
72
+ best_scene = analyze_scenes(video_path, scenes, description)
73
+ final_clip = extract_best_scene(video_path, best_scene)
74
+ if final_clip:
75
+ output_dir = "output"
76
+ os.makedirs(output_dir, exist_ok=True)
77
+ final_clip_path = os.path.join(output_dir, f"{uuid.uuid4()}_final_clip.mp4")
78
+ final_clip.write_videofile(final_clip_path, codec='libx264', audio_codec='aac')
79
+ cleanup_temp_files()
80
+ return final_clip_path, final_clip_path
81
+ else:
82
+ return "No matching scene found", None
83
+
84
 
85
  # Custom CSS for additional styling
86
  css = """
 
111
  color: #ffffff;
112
  border: 2px solid #ffffff;
113
  }
114
+ label[for="video_url"] {
115
+ color: #eb5726 !important;
116
+ }
117
+ label[for="description"] {
118
  color: #eb5726 !important;
119
  }
120
  h3 {
 
131
  text-transform: uppercase;
132
  }
133
  """
134
+
135
+ def save_uploaded_file(uploaded_file):
136
+ upload_dir = "uploaded_videos"
137
+ os.makedirs(upload_dir, exist_ok=True)
138
+ file_path = os.path.join(upload_dir, f"{uuid.uuid4()}.mp4")
139
+ with open(file_path, "wb") as f:
140
+ f.write(uploaded_file)
141
+ return file_path
142
+
143
  with gr.Blocks(theme=custom_theme, css=css) as demo:
144
  with gr.Column():
145
+ gr.Markdown("# **Sickstadium AI**", elem_classes="centered-markdown", elem_id="sickstadium-title")
146
+ gr.Markdown("### Upload your videos. Find sick clips. Tell your truth.", elem_classes="centered-markdown")
147
+ 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")
148
+ video_url = gr.Textbox(label="Video URL:", elem_id="video_url")
149
+ video_file = gr.File(label="Upload Video File:", elem_id="video_file", interactive=True, file_types=["video"], type="binary")
150
+ description = gr.Textbox(label="Describe your clip:", elem_id="description")
151
  submit_button = gr.Button("Process Video", elem_id="submit_button")
152
  video_output = gr.Video(label="Processed Video", elem_id="video_output")
153
+ download_output = gr.File(label="Download Processed Video", elem_id="download_output")
154
+ submit_button.click(fn=display_results, inputs=[video_url, video_file, description], outputs=[video_output, download_output])
 
 
 
 
 
155
 
156
+ demo.launch()