Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,9 @@
|
|
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,6 +48,41 @@ class CustomTheme(Base):
|
|
50 |
|
51 |
custom_theme = CustomTheme()
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
# Custom CSS for additional styling
|
54 |
css = """
|
55 |
body {
|
@@ -79,7 +112,7 @@ body {
|
|
79 |
color: #ffffff;
|
80 |
border: 2px solid #ffffff;
|
81 |
}
|
82 |
-
label[for="video_url"], label[for="description"]
|
83 |
color: #eb5726 !important;
|
84 |
}
|
85 |
h3 {
|
@@ -97,24 +130,20 @@ 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:",
|
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],
|
117 |
-
outputs=[video_output,
|
118 |
)
|
119 |
|
120 |
demo.launch()
|
|
|
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 |
import uuid
|
6 |
import os
|
|
|
|
|
7 |
|
8 |
class CustomTheme(Base):
|
9 |
def __init__(
|
|
|
48 |
|
49 |
custom_theme = CustomTheme()
|
50 |
|
51 |
+
def save_uploaded_file(uploaded_file):
|
52 |
+
upload_dir = "uploaded_videos"
|
53 |
+
os.makedirs(upload_dir, exist_ok=True)
|
54 |
+
file_path = os.path.join(upload_dir, f"{uuid.uuid4()}.mp4")
|
55 |
+
with open(file_path, "wb") as f:
|
56 |
+
f.write(uploaded_file)
|
57 |
+
return file_path
|
58 |
+
|
59 |
+
def display_results(video_url, video_file, description):
|
60 |
+
if video_url:
|
61 |
+
video_path = download_video(video_url)
|
62 |
+
elif video_file:
|
63 |
+
video_path = save_uploaded_file(video_file)
|
64 |
+
else:
|
65 |
+
return "No video provided", None, None
|
66 |
+
|
67 |
+
scenes = find_scenes(video_path)
|
68 |
+
if not scenes:
|
69 |
+
return "No scenes detected", None, None
|
70 |
+
|
71 |
+
best_scene, sentiment_distribution = analyze_scenes(video_path, scenes, description)
|
72 |
+
if best_scene:
|
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, sentiment_distribution
|
81 |
+
else:
|
82 |
+
return "No matching scene found", None
|
83 |
+
else:
|
84 |
+
return "No suitable scenes found", None
|
85 |
+
|
86 |
# Custom CSS for additional styling
|
87 |
css = """
|
88 |
body {
|
|
|
112 |
color: #ffffff;
|
113 |
border: 2px solid #ffffff;
|
114 |
}
|
115 |
+
label[for="video_url"], label[for="description"] {
|
116 |
color: #eb5726 !important;
|
117 |
}
|
118 |
h3 {
|
|
|
130 |
}
|
131 |
"""
|
132 |
|
|
|
|
|
|
|
|
|
133 |
with gr.Blocks(theme=custom_theme, css=css) as demo:
|
134 |
with gr.Column():
|
135 |
gr.Markdown("# **Sickstadium AI**", elem_classes="centered-markdown", elem_id="sickstadium-title")
|
136 |
+
gr.Markdown("### Upload your videos. Find sick clips. Tell your truth.", elem_classes="centered-markdown")
|
137 |
video_url = gr.Textbox(label="Video URL:", elem_id="video_url")
|
138 |
+
video_file = gr.File(label="Upload Video File:", interactive=True, file_types=["video"], type="binary")
|
139 |
description = gr.Textbox(label="Describe your clip:", elem_id="description")
|
140 |
submit_button = gr.Button("Process Video", elem_id="submit_button")
|
141 |
video_output = gr.Video(label="Processed Video", elem_id="video_output")
|
|
|
142 |
sentiment_plot = gr.Plot(label="Sentiment Distribution", elem_id="sentiment_plot")
|
143 |
submit_button.click(
|
144 |
fn=display_results,
|
145 |
inputs=[video_url, video_file, description],
|
146 |
+
outputs=[video_output, sentiment_plot]
|
147 |
)
|
148 |
|
149 |
demo.launch()
|