Spaces:
Paused
Paused
alex
commited on
Commit
·
1adb8b2
1
Parent(s):
f0b3778
clean up
Browse files
app.py
CHANGED
|
@@ -137,7 +137,7 @@ def make_sample(
|
|
| 137 |
}
|
| 138 |
return sample
|
| 139 |
|
| 140 |
-
g_use_factor_guidance =
|
| 141 |
|
| 142 |
pipe = load_ctrlv_pipelines(
|
| 143 |
"AnthonyGosselin/Ctrl-Crash",
|
|
@@ -341,62 +341,95 @@ def ctrl_generate(
|
|
| 341 |
raise gr.Error("Video file was not created. Check model path and logs.")
|
| 342 |
return mp4_path
|
| 343 |
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
video_out = gr.Video(label="Output video")
|
| 359 |
-
|
| 360 |
-
cached_examples = gr.Examples(
|
| 361 |
-
examples=[
|
| 362 |
-
[
|
| 363 |
-
"examples/gt_video.mp4",
|
| 364 |
-
"No Crash",
|
| 365 |
-
3,
|
| 366 |
-
],
|
| 367 |
-
|
| 368 |
-
[
|
| 369 |
-
"examples/gt_video.mp4",
|
| 370 |
-
"Ego-Only crash",
|
| 371 |
-
3,
|
| 372 |
-
],
|
| 373 |
-
|
| 374 |
-
[
|
| 375 |
-
"examples/gt_video.mp4",
|
| 376 |
-
"Ego-and-Vehicle crash",
|
| 377 |
-
3,
|
| 378 |
-
],
|
| 379 |
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
|
| 386 |
-
[
|
| 387 |
-
"examples/gt_video.mp4",
|
| 388 |
-
"Vehicle-and-Vehicle crash",
|
| 389 |
-
3,
|
| 390 |
],
|
| 391 |
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
cache_examples=True
|
| 399 |
-
)
|
| 400 |
|
| 401 |
run_btn.click(
|
| 402 |
fn=ctrl_generate,
|
|
|
|
| 137 |
}
|
| 138 |
return sample
|
| 139 |
|
| 140 |
+
g_use_factor_guidance = True
|
| 141 |
|
| 142 |
pipe = load_ctrlv_pipelines(
|
| 143 |
"AnthonyGosselin/Ctrl-Crash",
|
|
|
|
| 341 |
raise gr.Error("Video file was not created. Check model path and logs.")
|
| 342 |
return mp4_path
|
| 343 |
|
| 344 |
+
css = """
|
| 345 |
+
#col-container {
|
| 346 |
+
margin: 0 auto;
|
| 347 |
+
max-width: 1560px;
|
| 348 |
+
}
|
| 349 |
+
/* editable vs locked, reusing theme variables that adapt to dark/light */
|
| 350 |
+
.stateful textarea:not(:disabled):not([readonly]) {
|
| 351 |
+
color: var(--color-text) !important; /* accent in both modes */
|
| 352 |
+
}
|
| 353 |
+
.stateful textarea:disabled,
|
| 354 |
+
.stateful textarea[readonly]{
|
| 355 |
+
color: var(--body-text-color-subdued) !important; /* subdued in both modes */
|
| 356 |
+
}
|
| 357 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
|
| 359 |
+
with gr.Blocks(title="Ctrl-Crash Demo") as demo:
|
| 360 |
+
with gr.Column(elem_id="col-container"):
|
| 361 |
+
gr.HTML(
|
| 362 |
+
"""
|
| 363 |
+
<div style="text-align: left;">
|
| 364 |
+
<p style="font-size:16px; display: inline; margin: 0;">
|
| 365 |
+
<strong>Ctrl-Crash</strong> – Controllable Diffusion for Realistic Car Crashes
|
| 366 |
+
</p>
|
| 367 |
+
<a href="https://github.com/AnthonyGosselin/Ctrl-Crash" style="display: inline-block; vertical-align: middle; margin-left: 0.5em;">
|
| 368 |
+
[Github]
|
| 369 |
+
</a>
|
| 370 |
+
</div>
|
| 371 |
+
<div style="text-align: left;">
|
| 372 |
+
<strong>HF Space by:</strong>
|
| 373 |
+
<a href="https://twitter.com/alexandernasa/" style="display: inline-block; vertical-align: middle; margin-left: 0.5em;">
|
| 374 |
+
<img src="https://img.shields.io/twitter/url/https/twitter.com/cloudposse.svg?style=social&label=Follow Me" alt="GitHub Repo">
|
| 375 |
+
</a>
|
| 376 |
+
</div>
|
| 377 |
+
"""
|
| 378 |
+
)
|
| 379 |
+
with gr.Row():
|
| 380 |
+
with gr.Column(scale=1):
|
| 381 |
+
video_in = gr.Video(label="Dashcam Footage")
|
| 382 |
+
|
| 383 |
+
action_dropdown = gr.Dropdown(
|
| 384 |
+
label="Action Type",
|
| 385 |
+
choices=list(ACTION_TYPES.keys()),
|
| 386 |
+
value="Vehicle-and-Vehicle crash", # sensible default matching your prior checkbox default
|
| 387 |
+
)
|
| 388 |
+
bbx_frames = gr.Slider(1, 25, value=3, step=1, label="Mask Frames")
|
| 389 |
+
run_btn = gr.Button("Generate Video", variant="primary")
|
| 390 |
+
with gr.Column(scale=1):
|
| 391 |
+
video_out = gr.Video(label="Output video")
|
| 392 |
+
|
| 393 |
+
cached_examples = gr.Examples(
|
| 394 |
+
examples=[
|
| 395 |
+
[
|
| 396 |
+
"examples/gt_video.mp4",
|
| 397 |
+
"No Crash",
|
| 398 |
+
3,
|
| 399 |
+
],
|
| 400 |
+
|
| 401 |
+
[
|
| 402 |
+
"examples/gt_video.mp4",
|
| 403 |
+
"Ego-Only crash",
|
| 404 |
+
3,
|
| 405 |
+
],
|
| 406 |
+
|
| 407 |
+
[
|
| 408 |
+
"examples/gt_video.mp4",
|
| 409 |
+
"Ego-and-Vehicle crash",
|
| 410 |
+
3,
|
| 411 |
+
],
|
| 412 |
+
|
| 413 |
+
[
|
| 414 |
+
"examples/gt_video.mp4",
|
| 415 |
+
"Vehicle-Only crash",
|
| 416 |
+
3,
|
| 417 |
+
],
|
| 418 |
+
|
| 419 |
+
[
|
| 420 |
+
"examples/gt_video.mp4",
|
| 421 |
+
"Vehicle-and-Vehicle crash",
|
| 422 |
+
3,
|
| 423 |
+
],
|
| 424 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
],
|
| 426 |
|
| 427 |
+
label="Cached Examples",
|
| 428 |
+
inputs=[video_in, action_dropdown, bbx_frames],
|
| 429 |
+
outputs=[video_out],
|
| 430 |
+
fn=ctrl_generate,
|
| 431 |
+
cache_examples=True
|
| 432 |
+
)
|
|
|
|
|
|
|
| 433 |
|
| 434 |
run_btn.click(
|
| 435 |
fn=ctrl_generate,
|