Spaces:
Build error
Build error
Miquel Farre
commited on
Commit
·
4bc123c
1
Parent(s):
ae0847c
app.py
CHANGED
|
@@ -104,10 +104,8 @@ def create_ui(examples_path: str):
|
|
| 104 |
gr.Markdown(f"#Summary: {example['analysis']['video_description']}")
|
| 105 |
gr.Markdown(f"#Highlights to search for: {example['analysis']['highlight_types']}")
|
| 106 |
|
| 107 |
-
# Main interface section
|
| 108 |
gr.Markdown("## Try It Yourself!")
|
| 109 |
with gr.Row():
|
| 110 |
-
# Left column: Upload and Process
|
| 111 |
with gr.Column(scale=1):
|
| 112 |
input_video = gr.Video(
|
| 113 |
label="Upload your video (max 20 minutes)",
|
|
@@ -115,10 +113,7 @@ def create_ui(examples_path: str):
|
|
| 115 |
)
|
| 116 |
process_btn = gr.Button("Process Video", variant="primary")
|
| 117 |
|
| 118 |
-
# Right column: Progress and Analysis
|
| 119 |
with gr.Column(scale=1):
|
| 120 |
-
|
| 121 |
-
# Output video (initially hidden)
|
| 122 |
output_video = gr.Video(
|
| 123 |
label="Highlight Video",
|
| 124 |
visible=False,
|
|
@@ -127,19 +122,52 @@ def create_ui(examples_path: str):
|
|
| 127 |
|
| 128 |
status = gr.Markdown()
|
| 129 |
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
video_description = gr.Markdown("", elem_id="video_desc")
|
| 132 |
highlight_types = gr.Markdown("", elem_id="highlight_types")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
|
| 135 |
@spaces.GPU
|
| 136 |
-
def on_process(video
|
| 137 |
if not video:
|
| 138 |
return {
|
| 139 |
status: "Please upload a video",
|
| 140 |
video_description: "",
|
| 141 |
highlight_types: "",
|
| 142 |
-
output_video: gr.update(visible=False)
|
|
|
|
| 143 |
}
|
| 144 |
|
| 145 |
try:
|
|
@@ -149,45 +177,64 @@ def create_ui(examples_path: str):
|
|
| 149 |
status: "Video must be shorter than 20 minutes",
|
| 150 |
video_description: "",
|
| 151 |
highlight_types: "",
|
| 152 |
-
output_video: gr.update(visible=False)
|
|
|
|
| 153 |
}
|
| 154 |
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
model, processor = load_model()
|
| 158 |
detector = BatchedVideoHighlightDetector(model, processor, batch_size=8)
|
| 159 |
|
| 160 |
-
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
video_desc = detector.analyze_video_content(video)
|
| 163 |
-
#
|
| 164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
-
progress(0.3, desc="Determining highlight types...")
|
| 167 |
-
status.value = "Determining highlight types..."
|
| 168 |
highlights = detector.determine_highlights(video_desc)
|
| 169 |
-
#
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
-
progress(0.4, desc="Detecting and extracting highlights...")
|
| 173 |
-
status.value = "Detecting and extracting highlights..."
|
| 174 |
with tempfile.NamedTemporaryFile(suffix='.mp4', delete=False) as tmp_file:
|
| 175 |
temp_output = tmp_file.name
|
| 176 |
detector.create_highlight_video(video, temp_output)
|
| 177 |
|
| 178 |
-
# progress(0.9, desc="Adding watermark...")
|
| 179 |
-
# status.value = "Adding watermark..."
|
| 180 |
-
# output_path = temp_output.replace('.mp4', '_watermark.mp4')
|
| 181 |
-
# add_watermark(temp_output, output_path)
|
| 182 |
-
|
| 183 |
-
# os.unlink(temp_output)
|
| 184 |
-
progress(1.0, desc="Complete!")
|
| 185 |
-
|
| 186 |
return {
|
| 187 |
status: "Processing complete!",
|
| 188 |
-
video_description:
|
| 189 |
-
highlight_types:
|
| 190 |
-
output_video: gr.update(value=temp_output, visible=True)
|
|
|
|
| 191 |
}
|
| 192 |
|
| 193 |
except Exception as e:
|
|
@@ -195,78 +242,88 @@ def create_ui(examples_path: str):
|
|
| 195 |
status: f"Error processing video: {str(e)}",
|
| 196 |
video_description: "",
|
| 197 |
highlight_types: "",
|
| 198 |
-
output_video: gr.update(visible=False)
|
|
|
|
| 199 |
}
|
| 200 |
|
| 201 |
process_btn.click(
|
| 202 |
on_process,
|
| 203 |
inputs=[input_video],
|
| 204 |
-
outputs=[status, video_description, highlight_types, output_video]
|
| 205 |
)
|
| 206 |
|
| 207 |
return app
|
| 208 |
-
# gr.Markdown("## Try It Yourself!")
|
| 209 |
-
# with gr.Row():
|
| 210 |
-
# input_video = gr.Video(
|
| 211 |
-
# label="Upload your video (max 20 minutes)",
|
| 212 |
-
# interactive=True
|
| 213 |
-
# )
|
| 214 |
-
|
| 215 |
-
# gr.Progress()
|
| 216 |
-
# process_btn = gr.Button("Process Video", variant="primary")
|
| 217 |
-
|
| 218 |
-
# status = gr.Markdown(visible=True)
|
| 219 |
-
|
| 220 |
-
# with gr.Row() as results_row:
|
| 221 |
-
# with gr.Column():
|
| 222 |
-
# video_description = gr.Markdown(visible=False)
|
| 223 |
-
# with gr.Column():
|
| 224 |
-
# highlight_types = gr.Markdown(visible=False)
|
| 225 |
-
|
| 226 |
-
# with gr.Row() as output_row:
|
| 227 |
-
# output_video = gr.Video(label="Highlight Video", visible=False)
|
| 228 |
-
# download_btn = gr.Button("Download Highlights", visible=False)
|
| 229 |
|
|
|
|
| 230 |
# def on_process(video, progress=gr.Progress()):
|
| 231 |
# if not video:
|
| 232 |
# return {
|
| 233 |
# status: "Please upload a video",
|
| 234 |
-
# video_description:
|
| 235 |
-
# highlight_types:
|
| 236 |
-
# output_video: gr.update(visible=False)
|
| 237 |
-
# download_btn: gr.update(visible=False)
|
| 238 |
# }
|
| 239 |
|
| 240 |
-
#
|
| 241 |
-
#
|
| 242 |
-
|
| 243 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
# return {
|
| 245 |
-
# status:
|
| 246 |
-
# video_description:
|
| 247 |
-
# highlight_types:
|
| 248 |
-
# output_video: gr.update(visible=
|
| 249 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
# }
|
| 251 |
-
|
| 252 |
-
# return {
|
| 253 |
-
# status: "Processing complete!",
|
| 254 |
-
# video_description: gr.update(value=desc, visible=True),
|
| 255 |
-
# highlight_types: gr.update(value=highlights, visible=True),
|
| 256 |
-
# output_video: gr.update(value=output_path, visible=True),
|
| 257 |
-
# download_btn: gr.update(visible=True)
|
| 258 |
-
# }
|
| 259 |
|
| 260 |
# process_btn.click(
|
| 261 |
# on_process,
|
| 262 |
# inputs=[input_video],
|
| 263 |
-
# outputs=[status, video_description, highlight_types, output_video
|
| 264 |
-
# )
|
| 265 |
-
|
| 266 |
-
# download_btn.click(
|
| 267 |
-
# lambda x: x,
|
| 268 |
-
# inputs=[output_video],
|
| 269 |
-
# outputs=[output_video]
|
| 270 |
# )
|
| 271 |
|
| 272 |
# return app
|
|
|
|
| 104 |
gr.Markdown(f"#Summary: {example['analysis']['video_description']}")
|
| 105 |
gr.Markdown(f"#Highlights to search for: {example['analysis']['highlight_types']}")
|
| 106 |
|
|
|
|
| 107 |
gr.Markdown("## Try It Yourself!")
|
| 108 |
with gr.Row():
|
|
|
|
| 109 |
with gr.Column(scale=1):
|
| 110 |
input_video = gr.Video(
|
| 111 |
label="Upload your video (max 20 minutes)",
|
|
|
|
| 113 |
)
|
| 114 |
process_btn = gr.Button("Process Video", variant="primary")
|
| 115 |
|
|
|
|
| 116 |
with gr.Column(scale=1):
|
|
|
|
|
|
|
| 117 |
output_video = gr.Video(
|
| 118 |
label="Highlight Video",
|
| 119 |
visible=False,
|
|
|
|
| 122 |
|
| 123 |
status = gr.Markdown()
|
| 124 |
|
| 125 |
+
analysis_accordion = gr.Accordion(
|
| 126 |
+
"Model chain of thought details",
|
| 127 |
+
open=True,
|
| 128 |
+
visible=False
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
with analysis_accordion:
|
| 132 |
video_description = gr.Markdown("", elem_id="video_desc")
|
| 133 |
highlight_types = gr.Markdown("", elem_id="highlight_types")
|
| 134 |
+
# # Main interface section
|
| 135 |
+
# gr.Markdown("## Try It Yourself!")
|
| 136 |
+
# with gr.Row():
|
| 137 |
+
# # Left column: Upload and Process
|
| 138 |
+
# with gr.Column(scale=1):
|
| 139 |
+
# input_video = gr.Video(
|
| 140 |
+
# label="Upload your video (max 20 minutes)",
|
| 141 |
+
# interactive=True
|
| 142 |
+
# )
|
| 143 |
+
# process_btn = gr.Button("Process Video", variant="primary")
|
| 144 |
+
|
| 145 |
+
# # Right column: Progress and Analysis
|
| 146 |
+
# with gr.Column(scale=1):
|
| 147 |
+
|
| 148 |
+
# # Output video (initially hidden)
|
| 149 |
+
# output_video = gr.Video(
|
| 150 |
+
# label="Highlight Video",
|
| 151 |
+
# visible=False,
|
| 152 |
+
# interactive=False,
|
| 153 |
+
# )
|
| 154 |
+
|
| 155 |
+
# status = gr.Markdown()
|
| 156 |
+
|
| 157 |
+
# with gr.Accordion("Model chain of thought details", open=True, visible=True) as analysis_accordion:
|
| 158 |
+
# video_description = gr.Markdown("", elem_id="video_desc")
|
| 159 |
+
# highlight_types = gr.Markdown("", elem_id="highlight_types")
|
| 160 |
|
| 161 |
|
| 162 |
@spaces.GPU
|
| 163 |
+
def on_process(video):
|
| 164 |
if not video:
|
| 165 |
return {
|
| 166 |
status: "Please upload a video",
|
| 167 |
video_description: "",
|
| 168 |
highlight_types: "",
|
| 169 |
+
output_video: gr.update(visible=False),
|
| 170 |
+
analysis_accordion: gr.update(visible=False)
|
| 171 |
}
|
| 172 |
|
| 173 |
try:
|
|
|
|
| 177 |
status: "Video must be shorter than 20 minutes",
|
| 178 |
video_description: "",
|
| 179 |
highlight_types: "",
|
| 180 |
+
output_video: gr.update(visible=False),
|
| 181 |
+
analysis_accordion: gr.update(visible=False)
|
| 182 |
}
|
| 183 |
|
| 184 |
+
# Make accordion visible as soon as processing starts
|
| 185 |
+
yield {
|
| 186 |
+
status: "Loading model...",
|
| 187 |
+
video_description: "",
|
| 188 |
+
highlight_types: "",
|
| 189 |
+
output_video: gr.update(visible=False),
|
| 190 |
+
analysis_accordion: gr.update(visible=True)
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
model, processor = load_model()
|
| 194 |
detector = BatchedVideoHighlightDetector(model, processor, batch_size=8)
|
| 195 |
|
| 196 |
+
yield {
|
| 197 |
+
status: "Analyzing video content...",
|
| 198 |
+
video_description: "",
|
| 199 |
+
highlight_types: "",
|
| 200 |
+
output_video: gr.update(visible=False),
|
| 201 |
+
analysis_accordion: gr.update(visible=True)
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
video_desc = detector.analyze_video_content(video)
|
| 205 |
+
formatted_desc = f"#Summary: {video_desc[:500] + '...' if len(video_desc) > 500 else video_desc}"
|
| 206 |
+
|
| 207 |
+
# Update description as soon as it's available
|
| 208 |
+
yield {
|
| 209 |
+
status: "Determining highlight types...",
|
| 210 |
+
video_description: formatted_desc,
|
| 211 |
+
highlight_types: "",
|
| 212 |
+
output_video: gr.update(visible=False),
|
| 213 |
+
analysis_accordion: gr.update(visible=True)
|
| 214 |
+
}
|
| 215 |
|
|
|
|
|
|
|
| 216 |
highlights = detector.determine_highlights(video_desc)
|
| 217 |
+
formatted_highlights = f"#Highlights to search for: {highlights[:500] + '...' if len(highlights) > 500 else highlights}"
|
| 218 |
+
|
| 219 |
+
# Update highlights as soon as they're available
|
| 220 |
+
yield {
|
| 221 |
+
status: "Detecting and extracting highlights...",
|
| 222 |
+
video_description: formatted_desc,
|
| 223 |
+
highlight_types: formatted_highlights,
|
| 224 |
+
output_video: gr.update(visible=False),
|
| 225 |
+
analysis_accordion: gr.update(visible=True)
|
| 226 |
+
}
|
| 227 |
|
|
|
|
|
|
|
| 228 |
with tempfile.NamedTemporaryFile(suffix='.mp4', delete=False) as tmp_file:
|
| 229 |
temp_output = tmp_file.name
|
| 230 |
detector.create_highlight_video(video, temp_output)
|
| 231 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
return {
|
| 233 |
status: "Processing complete!",
|
| 234 |
+
video_description: formatted_desc,
|
| 235 |
+
highlight_types: formatted_highlights,
|
| 236 |
+
output_video: gr.update(value=temp_output, visible=True),
|
| 237 |
+
analysis_accordion: gr.update(visible=True)
|
| 238 |
}
|
| 239 |
|
| 240 |
except Exception as e:
|
|
|
|
| 242 |
status: f"Error processing video: {str(e)}",
|
| 243 |
video_description: "",
|
| 244 |
highlight_types: "",
|
| 245 |
+
output_video: gr.update(visible=False),
|
| 246 |
+
analysis_accordion: gr.update(visible=False)
|
| 247 |
}
|
| 248 |
|
| 249 |
process_btn.click(
|
| 250 |
on_process,
|
| 251 |
inputs=[input_video],
|
| 252 |
+
outputs=[status, video_description, highlight_types, output_video, analysis_accordion]
|
| 253 |
)
|
| 254 |
|
| 255 |
return app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
|
| 257 |
+
# @spaces.GPU
|
| 258 |
# def on_process(video, progress=gr.Progress()):
|
| 259 |
# if not video:
|
| 260 |
# return {
|
| 261 |
# status: "Please upload a video",
|
| 262 |
+
# video_description: "",
|
| 263 |
+
# highlight_types: "",
|
| 264 |
+
# output_video: gr.update(visible=False)
|
|
|
|
| 265 |
# }
|
| 266 |
|
| 267 |
+
# try:
|
| 268 |
+
# duration = get_video_duration_seconds(video)
|
| 269 |
+
# if duration > 1200: # 20 minutes
|
| 270 |
+
# return {
|
| 271 |
+
# status: "Video must be shorter than 20 minutes",
|
| 272 |
+
# video_description: "",
|
| 273 |
+
# highlight_types: "",
|
| 274 |
+
# output_video: gr.update(visible=False)
|
| 275 |
+
# }
|
| 276 |
+
|
| 277 |
+
# progress(0.1, desc="Loading model...")
|
| 278 |
+
# status.value = "Loading model..."
|
| 279 |
+
# model, processor = load_model()
|
| 280 |
+
# detector = BatchedVideoHighlightDetector(model, processor, batch_size=8)
|
| 281 |
+
|
| 282 |
+
# progress(0.2, desc="Analyzing video content...")
|
| 283 |
+
# status.value = "Analyzing video content..."
|
| 284 |
+
# video_desc = detector.analyze_video_content(video)
|
| 285 |
+
# # Update description in real-time
|
| 286 |
+
# video_description.value = f"#Summary: {video_desc[:500] + '...' if len(video_desc) > 500 else video_desc}"
|
| 287 |
+
|
| 288 |
+
# progress(0.3, desc="Determining highlight types...")
|
| 289 |
+
# status.value = "Determining highlight types..."
|
| 290 |
+
# highlights = detector.determine_highlights(video_desc)
|
| 291 |
+
# # Update highlights in real-time
|
| 292 |
+
# highlight_types.value = f"#Highlights to search for: {highlights[:500] + '...' if len(highlights) > 500 else highlights}"
|
| 293 |
+
|
| 294 |
+
# progress(0.4, desc="Detecting and extracting highlights...")
|
| 295 |
+
# status.value = "Detecting and extracting highlights..."
|
| 296 |
+
# with tempfile.NamedTemporaryFile(suffix='.mp4', delete=False) as tmp_file:
|
| 297 |
+
# temp_output = tmp_file.name
|
| 298 |
+
# detector.create_highlight_video(video, temp_output)
|
| 299 |
+
|
| 300 |
+
# # progress(0.9, desc="Adding watermark...")
|
| 301 |
+
# # status.value = "Adding watermark..."
|
| 302 |
+
# # output_path = temp_output.replace('.mp4', '_watermark.mp4')
|
| 303 |
+
# # add_watermark(temp_output, output_path)
|
| 304 |
+
|
| 305 |
+
# # os.unlink(temp_output)
|
| 306 |
+
# progress(1.0, desc="Complete!")
|
| 307 |
+
|
| 308 |
# return {
|
| 309 |
+
# status: "Processing complete!",
|
| 310 |
+
# video_description: video_description.value,
|
| 311 |
+
# highlight_types: highlight_types.value,
|
| 312 |
+
# output_video: gr.update(value=temp_output, visible=True)
|
| 313 |
+
# }
|
| 314 |
+
|
| 315 |
+
# except Exception as e:
|
| 316 |
+
# return {
|
| 317 |
+
# status: f"Error processing video: {str(e)}",
|
| 318 |
+
# video_description: "",
|
| 319 |
+
# highlight_types: "",
|
| 320 |
+
# output_video: gr.update(visible=False)
|
| 321 |
# }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
|
| 323 |
# process_btn.click(
|
| 324 |
# on_process,
|
| 325 |
# inputs=[input_video],
|
| 326 |
+
# outputs=[status, video_description, highlight_types, output_video]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
# )
|
| 328 |
|
| 329 |
# return app
|