Spaces:
Sleeping
Sleeping
File size: 7,070 Bytes
dcb53fc 1e456a7 939b575 f9d282c 16466ea 96c84ad 54d1b5f 939b575 1e456a7 f9d282c 54d1b5f 1e456a7 54d1b5f 15637ee f9d282c 54d1b5f 1e456a7 4393803 e5facda 54d1b5f e5facda 4393803 f9d282c 4393803 54d1b5f 4393803 54d1b5f f9d282c 54d1b5f 4393803 f9d282c a10ca18 939b575 0ddaca8 939b575 f9d282c 939b575 f9d282c 0ddaca8 f9d282c 4bd4f7f 5d5059e eca1099 e5facda 84402a9 4757b5e a561b64 5deaa7a f9d282c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
import gradio as gr
from video_processing import process_video, download_video, find_scenes, analyze_scenes, extract_best_scene, cleanup_temp_files
from gradio.themes.base import Base
from gradio.themes.utils import colors, fonts, sizes
from typing import Iterable
import uuid
import os
import plotly.graph_objects as go
class CustomTheme(Base):
def __init__(
self,
*,
primary_hue: colors.Color | str = colors.orange,
secondary_hue: colors.Color | str = colors.orange,
neutral_hue: colors.Color | str = colors.gray,
spacing_size: sizes.Size | str = sizes.spacing_md,
radius_size: sizes.Size | str = sizes.radius_md,
text_size: sizes.Size | str = sizes.text_md,
font: fonts.Font | str | Iterable[fonts.Font | str] = (
fonts.GoogleFont("Sora"),
"ui-sans-serif",
"sans-serif",
),
font_mono: fonts.Font | str | Iterable[fonts.Font | str] = (
fonts.GoogleFont("Sora"),
"ui-monospace",
"monospace",
),
):
super().__init__(
primary_hue=primary_hue,
secondary_hue=secondary_hue,
neutral_hue=neutral_hue,
spacing_size=spacing_size,
radius_size=radius_size,
text_size=text_size,
font=font,
font_mono=font_mono,
)
super().set(
body_background_fill="radial-gradient(circle at center, rgba(235, 87, 38, 1) 0%, rgba(235, 87, 38, 0) 70%), radial-gradient(#eb5726 1px, transparent 1px)",
body_text_color="#282828",
block_background_fill="#ffffff",
block_title_text_color="#eb5726",
block_label_text_color="#eb5726",
button_primary_background_fill="#eb5726",
button_primary_text_color="#ffffff",
)
custom_theme = CustomTheme()
def save_uploaded_file(uploaded_file):
upload_dir = "uploaded_videos"
os.makedirs(upload_dir, exist_ok=True)
file_path = os.path.join(upload_dir, f"{uuid.uuid4()}.mp4")
with open(file_path, "wb") as f:
f.write(uploaded_file)
return file_path
import gradio as gr
from video_processing import process_video, download_video, find_scenes, analyze_scenes, extract_best_scene, cleanup_temp_files
import plotly.graph_objects as go
import os
import uuid
# Assuming CustomTheme and other setups are defined above this snippet
def display_results(video_url, video_file, description):
if video_url:
video_path = download_video(video_url)
elif video_file:
video_path = save_uploaded_file(video_file)
else:
return "No video provided", None, None
scenes = find_scenes(video_path)
if not scenes:
return "No scenes detected", None, None
best_scene_times, sentiments = analyze_scenes(video_path, scenes, description)
if not best_scene_times:
return "No matching scene found", None, None
final_clip = extract_best_scene(video_path, best_scene_times)
if final_clip:
output_dir = "output"
os.makedirs(output_dir, exist_ok=True)
final_clip_path = os.path.join(output_dir, f"{uuid.uuid4()}_final_clip.mp4")
final_clip.write_videofile(final_clip_path, codec='libx264', audio_codec='aac')
cleanup_temp_files()
# Calculate the total sum of sentiment scores
total_score = sum(sentiments.values())
if total_score == 0:
# Ensure there's no division by zero
sentiments = {k: 0 for k in sentiments}
# Prepare data for the radial chart
labels = list(sentiments.keys())
values = [v / total_score * 100 for v in sentiments.values()] # Normalize to percentages
# Create a polar chart
fig = go.Figure(data=go.Scatterpolar(
r=values,
theta=labels,
fill='toself'
))
fig.update_layout(
polar=dict(
radialaxis=dict(
visible=True,
range=[0, max(values) if values else 1]
)),
showlegend=False
)
return final_clip_path, final_clip_path, fig
else:
return "No matching scene found", None, None
# Assuming Gradio Blocks setup is defined below this snippet
# Custom CSS for additional styling
css = """
body {
background-color: #ffffff;
background-image: radial-gradient(#eb5726 1px, transparent 1px);
background-size: 10px 10px;
background-repeat: repeat;
background-attachment: fixed;
}
#video_url {
background-color: #ffffff;
color: #282828;
border: 2px solid #eb5726;
}
#description {
background-color: #ffffff;
color: #282828;
border: 2px solid #eb5726;
}
#submit_button {
background-color: #eb5726;
color: #ffffff;
border: 2px solid #ffffff;
}
#submit_button:hover {
background-color: #f5986e;
color: #ffffff;
border: 2px solid #ffffff;
}
label[for="video_url"] {
color: #eb5726 !important;
}
label[for="description"] {
color: #eb5726 !important;
}
h3 {
color: #eb5726;
}
.centered-markdown {
text-align: center;
background-color: #ffffff;
padding: 10px;
}
#sickstadium-title {
font-size: 3em !important;
font-weight: bold;
text-transform: uppercase;
}
"""
def save_uploaded_file(uploaded_file):
upload_dir = "uploaded_videos"
os.makedirs(upload_dir, exist_ok=True)
file_path = os.path.join(upload_dir, f"{uuid.uuid4()}.mp4")
with open(file_path, "wb") as f:
f.write(uploaded_file)
return file_path
with gr.Blocks(theme=custom_theme, css=css) as demo:
with gr.Column():
gr.Markdown("# **Sickstadium AI**", elem_classes="centered-markdown", elem_id="sickstadium-title")
gr.Markdown("### Upload your videos. Find sick clips. Tell your truth.", elem_classes="centered-markdown")
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")
video_url = gr.Textbox(label="Video URL:")
video_file = gr.File(label="Upload Video File:", type="binary")
description = gr.Textbox(label="Describe your clip:")
submit_button = gr.Button("Process Video", elem_id="submit_button")
video_output = gr.Video(label="Processed Video:")
download_output = gr.File(label="Download Processed Video:")
sentiment_output = gr.Plot(label="Predicted User Feedback:") # Changed from Markdown to Plot
submit_button.click(fn=display_results, inputs=[video_url, video_file, description], outputs=[video_output, download_output, sentiment_output])
demo.launch() |