Spaces:
Running
Running
update to only work with gpu duplicated instances
Browse files- gradio_app.py +116 -14
gradio_app.py
CHANGED
|
@@ -4,6 +4,10 @@ import gradio as gr
|
|
| 4 |
import os
|
| 5 |
import shutil
|
| 6 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
import imageio
|
| 8 |
import argparse
|
| 9 |
from types import MethodType
|
|
@@ -23,21 +27,23 @@ from utils.tools import read_video, set_all_seed
|
|
| 23 |
|
| 24 |
from huggingface_hub import snapshot_download, hf_hub_download
|
| 25 |
|
| 26 |
-
|
| 27 |
-
repo_id='lllyasviel/ic-light',
|
| 28 |
-
filename='iclight_sd15_fc.safetensors',
|
| 29 |
-
local_dir='./models'
|
| 30 |
-
)
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
snapshot_download(
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
)
|
| 41 |
|
| 42 |
def main(args):
|
| 43 |
|
|
@@ -298,6 +304,62 @@ div#col-container{
|
|
| 298 |
margin: 0 auto;
|
| 299 |
max-width: 1200px;
|
| 300 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
"""
|
| 302 |
|
| 303 |
with gr.Blocks(css=css) as demo:
|
|
@@ -344,7 +406,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 344 |
text_guide_scale = gr.Number(label="Text Guide Scale", value=2)
|
| 345 |
seed = gr.Number(label="Seed", value=2060)
|
| 346 |
|
| 347 |
-
submit = gr.Button("Run")
|
| 348 |
|
| 349 |
gr.Examples(
|
| 350 |
examples=[
|
|
@@ -369,6 +431,46 @@ with gr.Blocks(css=css) as demo:
|
|
| 369 |
)
|
| 370 |
|
| 371 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
output = gr.Video(label="Results Path")
|
| 373 |
|
| 374 |
submit.click(
|
|
|
|
| 4 |
import os
|
| 5 |
import shutil
|
| 6 |
import torch
|
| 7 |
+
|
| 8 |
+
is_shared_ui = True if "fffiloni/Light-A-Video" in os.environ['SPACE_ID'] else False
|
| 9 |
+
is_gpu_associated = torch.cuda.is_available()
|
| 10 |
+
|
| 11 |
import imageio
|
| 12 |
import argparse
|
| 13 |
from types import MethodType
|
|
|
|
| 27 |
|
| 28 |
from huggingface_hub import snapshot_download, hf_hub_download
|
| 29 |
|
| 30 |
+
if not is_shared_ui and is_gpu_associated:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
hf_hub_download(
|
| 33 |
+
repo_id='lllyasviel/ic-light',
|
| 34 |
+
filename='iclight_sd15_fc.safetensors',
|
| 35 |
+
local_dir='./models'
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
snapshot_download(
|
| 39 |
+
repo_id="stablediffusionapi/realistic-vision-v51",
|
| 40 |
+
local_dir="./models/stablediffusionapi/realistic-vision-v51"
|
| 41 |
+
)
|
| 42 |
|
| 43 |
+
snapshot_download(
|
| 44 |
+
repo_id="guoyww/animatediff-motion-adapter-v1-5-3",
|
| 45 |
+
local_dir="./models/guoyww/animatediff-motion-adapter-v1-5-3"
|
| 46 |
+
)
|
| 47 |
|
| 48 |
def main(args):
|
| 49 |
|
|
|
|
| 304 |
margin: 0 auto;
|
| 305 |
max-width: 1200px;
|
| 306 |
}
|
| 307 |
+
|
| 308 |
+
div#warning-duplicate {
|
| 309 |
+
background-color: #ebf5ff;
|
| 310 |
+
padding: 0 16px 16px;
|
| 311 |
+
margin: 20px 0;
|
| 312 |
+
color: #030303!important;
|
| 313 |
+
}
|
| 314 |
+
div#warning-duplicate > .gr-prose > h2, div#warning-duplicate > .gr-prose > p {
|
| 315 |
+
color: #0f4592!important;
|
| 316 |
+
}
|
| 317 |
+
div#warning-duplicate strong {
|
| 318 |
+
color: #0f4592;
|
| 319 |
+
}
|
| 320 |
+
p.actions {
|
| 321 |
+
display: flex;
|
| 322 |
+
align-items: center;
|
| 323 |
+
margin: 20px 0;
|
| 324 |
+
}
|
| 325 |
+
div#warning-duplicate .actions a {
|
| 326 |
+
display: inline-block;
|
| 327 |
+
margin-right: 10px;
|
| 328 |
+
}
|
| 329 |
+
div#warning-setgpu {
|
| 330 |
+
background-color: #fff4eb;
|
| 331 |
+
padding: 0 16px 16px;
|
| 332 |
+
margin: 20px 0;
|
| 333 |
+
color: #030303!important;
|
| 334 |
+
}
|
| 335 |
+
div#warning-setgpu > .gr-prose > h2, div#warning-setgpu > .gr-prose > p {
|
| 336 |
+
color: #92220f!important;
|
| 337 |
+
}
|
| 338 |
+
div#warning-setgpu a, div#warning-setgpu b {
|
| 339 |
+
color: #91230f;
|
| 340 |
+
}
|
| 341 |
+
div#warning-setgpu p.actions > a {
|
| 342 |
+
display: inline-block;
|
| 343 |
+
background: #1f1f23;
|
| 344 |
+
border-radius: 40px;
|
| 345 |
+
padding: 6px 24px;
|
| 346 |
+
color: antiquewhite;
|
| 347 |
+
text-decoration: none;
|
| 348 |
+
font-weight: 600;
|
| 349 |
+
font-size: 1.2em;
|
| 350 |
+
}
|
| 351 |
+
div#warning-ready {
|
| 352 |
+
background-color: #ecfdf5;
|
| 353 |
+
padding: 0 16px 16px;
|
| 354 |
+
margin: 20px 0;
|
| 355 |
+
color: #030303!important;
|
| 356 |
+
}
|
| 357 |
+
div#warning-ready > .gr-prose > h2, div#warning-ready > .gr-prose > p {
|
| 358 |
+
color: #057857!important;
|
| 359 |
+
}
|
| 360 |
+
.custom-color {
|
| 361 |
+
color: #030303 !important;
|
| 362 |
+
}
|
| 363 |
"""
|
| 364 |
|
| 365 |
with gr.Blocks(css=css) as demo:
|
|
|
|
| 406 |
text_guide_scale = gr.Number(label="Text Guide Scale", value=2)
|
| 407 |
seed = gr.Number(label="Seed", value=2060)
|
| 408 |
|
| 409 |
+
submit = gr.Button("Run", interactive=False if is_shared_ui else True)
|
| 410 |
|
| 411 |
gr.Examples(
|
| 412 |
examples=[
|
|
|
|
| 431 |
)
|
| 432 |
|
| 433 |
with gr.Column():
|
| 434 |
+
if is_shared_ui:
|
| 435 |
+
top_description = gr.HTML(f'''
|
| 436 |
+
<div class="gr-prose">
|
| 437 |
+
<h2 class="custom-color"><svg xmlns="http://www.w3.org/2000/svg" width="18px" height="18px" style="margin-right: 0px;display: inline-block;"fill="none"><path fill="#fff" d="M7 13.2a6.3 6.3 0 0 0 4.4-10.7A6.3 6.3 0 0 0 .6 6.9 6.3 6.3 0 0 0 7 13.2Z"/><path fill="#fff" fill-rule="evenodd" d="M7 0a6.9 6.9 0 0 1 4.8 11.8A6.9 6.9 0 0 1 0 7 6.9 6.9 0 0 1 7 0Zm0 0v.7V0ZM0 7h.6H0Zm7 6.8v-.6.6ZM13.7 7h-.6.6ZM9.1 1.7c-.7-.3-1.4-.4-2.2-.4a5.6 5.6 0 0 0-4 1.6 5.6 5.6 0 0 0-1.6 4 5.6 5.6 0 0 0 1.6 4 5.6 5.6 0 0 0 4 1.7 5.6 5.6 0 0 0 4-1.7 5.6 5.6 0 0 0 1.7-4 5.6 5.6 0 0 0-1.7-4c-.5-.5-1.1-.9-1.8-1.2Z" clip-rule="evenodd"/><path fill="#000" fill-rule="evenodd" d="M7 2.9a.8.8 0 1 1 0 1.5A.8.8 0 0 1 7 3ZM5.8 5.7c0-.4.3-.6.6-.6h.7c.3 0 .6.2.6.6v3.7h.5a.6.6 0 0 1 0 1.3H6a.6.6 0 0 1 0-1.3h.4v-3a.6.6 0 0 1-.6-.7Z" clip-rule="evenodd"/></svg>
|
| 438 |
+
Attention: this Space need to be duplicated to work</h2>
|
| 439 |
+
<p class="main-message custom-color">
|
| 440 |
+
To make it work, <strong>duplicate the Space</strong> and run it on your own profile using a <strong>private</strong> GPU (L40s recommended).<br />
|
| 441 |
+
A L40s costs <strong>US$1.80/h</strong>.
|
| 442 |
+
</p>
|
| 443 |
+
<p class="actions custom-color">
|
| 444 |
+
<a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}?duplicate=true">
|
| 445 |
+
<img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-lg-dark.svg" alt="Duplicate this Space" />
|
| 446 |
+
</a>
|
| 447 |
+
to start experimenting with this demo
|
| 448 |
+
</p>
|
| 449 |
+
</div>
|
| 450 |
+
''', elem_id="warning-duplicate")
|
| 451 |
+
else:
|
| 452 |
+
if(is_gpu_associated):
|
| 453 |
+
top_description = gr.HTML(f'''
|
| 454 |
+
<div class="gr-prose">
|
| 455 |
+
<h2 class="custom-color"><svg xmlns="http://www.w3.org/2000/svg" width="18px" height="18px" style="margin-right: 0px;display: inline-block;"fill="none"><path fill="#fff" d="M7 13.2a6.3 6.3 0 0 0 4.4-10.7A6.3 6.3 0 0 0 .6 6.9 6.3 6.3 0 0 0 7 13.2Z"/><path fill="#fff" fill-rule="evenodd" d="M7 0a6.9 6.9 0 0 1 4.8 11.8A6.9 6.9 0 0 1 0 7 6.9 6.9 0 0 1 7 0Zm0 0v.7V0ZM0 7h.6H0Zm7 6.8v-.6.6ZM13.7 7h-.6.6ZM9.1 1.7c-.7-.3-1.4-.4-2.2-.4a5.6 5.6 0 0 0-4 1.6 5.6 5.6 0 0 0-1.6 4 5.6 5.6 0 0 0 1.6 4 5.6 5.6 0 0 0 4 1.7 5.6 5.6 0 0 0 4-1.7 5.6 5.6 0 0 0 1.7-4 5.6 5.6 0 0 0-1.7-4c-.5-.5-1.1-.9-1.8-1.2Z" clip-rule="evenodd"/><path fill="#000" fill-rule="evenodd" d="M7 2.9a.8.8 0 1 1 0 1.5A.8.8 0 0 1 7 3ZM5.8 5.7c0-.4.3-.6.6-.6h.7c.3 0 .6.2.6.6v3.7h.5a.6.6 0 0 1 0 1.3H6a.6.6 0 0 1 0-1.3h.4v-3a.6.6 0 0 1-.6-.7Z" clip-rule="evenodd"/></svg>
|
| 456 |
+
You have successfully associated a GPU to this Space π</h2>
|
| 457 |
+
<p class="custom-color">
|
| 458 |
+
You will be billed by the minute from when you activated the GPU until when it is turned off.
|
| 459 |
+
</p>
|
| 460 |
+
</div>
|
| 461 |
+
''', elem_id="warning-ready")
|
| 462 |
+
else:
|
| 463 |
+
top_description = gr.HTML(f'''
|
| 464 |
+
<div class="gr-prose">
|
| 465 |
+
<h2 class="custom-color"><svg xmlns="http://www.w3.org/2000/svg" width="18px" height="18px" style="margin-right: 0px;display: inline-block;"fill="none"><path fill="#fff" d="M7 13.2a6.3 6.3 0 0 0 4.4-10.7A6.3 6.3 0 0 0 .6 6.9 6.3 6.3 0 0 0 7 13.2Z"/><path fill="#fff" fill-rule="evenodd" d="M7 0a6.9 6.9 0 0 1 4.8 11.8A6.9 6.9 0 0 1 0 7 6.9 6.9 0 0 1 7 0Zm0 0v.7V0ZM0 7h.6H0Zm7 6.8v-.6.6ZM13.7 7h-.6.6ZM9.1 1.7c-.7-.3-1.4-.4-2.2-.4a5.6 5.6 0 0 0-4 1.6 5.6 5.6 0 0 0-1.6 4 5.6 5.6 0 0 0 1.6 4 5.6 5.6 0 0 0 4 1.7 5.6 5.6 0 0 0 4-1.7 5.6 5.6 0 0 0 1.7-4 5.6 5.6 0 0 0-1.7-4c-.5-.5-1.1-.9-1.8-1.2Z" clip-rule="evenodd"/><path fill="#000" fill-rule="evenodd" d="M7 2.9a.8.8 0 1 1 0 1.5A.8.8 0 0 1 7 3ZM5.8 5.7c0-.4.3-.6.6-.6h.7c.3 0 .6.2.6.6v3.7h.5a.6.6 0 0 1 0 1.3H6a.6.6 0 0 1 0-1.3h.4v-3a.6.6 0 0 1-.6-.7Z" clip-rule="evenodd"/></svg>
|
| 466 |
+
You have successfully duplicated the MimicMotion Space π</h2>
|
| 467 |
+
<p class="custom-color">There's only one step left before you can properly play with this demo: <a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}/settings" style="text-decoration: underline" target="_blank">attribute a GPU</b> to it (via the Settings tab)</a> and run the app below.
|
| 468 |
+
You will be billed by the minute from when you activate the GPU until when it is turned off.</p>
|
| 469 |
+
<p class="actions custom-color">
|
| 470 |
+
<a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}/settings">π₯ Set recommended GPU</a>
|
| 471 |
+
</p>
|
| 472 |
+
</div>
|
| 473 |
+
''', elem_id="warning-setgpu")
|
| 474 |
output = gr.Video(label="Results Path")
|
| 475 |
|
| 476 |
submit.click(
|