Spaces:
Running
Running
update to only work with duplicated gpu instances
Browse files- gradio/vace.py +111 -8
gradio/vace.py
CHANGED
@@ -10,20 +10,80 @@ import numpy as np
|
|
10 |
import torch
|
11 |
import gradio as gr
|
12 |
|
13 |
-
|
|
|
14 |
|
15 |
-
snapshot_download
|
16 |
-
repo_id = "Wan-AI/Wan2.1-VACE-1.3B",
|
17 |
-
local_dir = "./models/Wan2.1-VACE-1.3B"
|
18 |
-
)
|
19 |
|
20 |
-
|
|
|
|
|
|
|
|
|
21 |
|
22 |
sys.path.insert(0, os.path.sep.join(os.path.realpath(__file__).split(os.path.sep)[:-2]))
|
23 |
import wan
|
24 |
from wan import WanVace, WanVaceMP
|
25 |
from wan.configs import WAN_CONFIGS, SIZE_CONFIGS
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
class FixedSizeQueue:
|
29 |
def __init__(self, max_size):
|
@@ -82,6 +142,47 @@ class VACEInference:
|
|
82 |
</a>
|
83 |
</div>
|
84 |
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
with gr.Row(variant='panel', equal_height=True):
|
86 |
with gr.Column(scale=1, min_width=0):
|
87 |
self.src_video = gr.Video(
|
@@ -209,7 +310,9 @@ class VACEInference:
|
|
209 |
value='Run',
|
210 |
elem_classes='type_row',
|
211 |
elem_id='generate_button',
|
212 |
-
visible=True
|
|
|
|
|
213 |
with gr.Column(scale=1):
|
214 |
self.refresh_button = gr.Button(value='\U0001f504') # π
|
215 |
#
|
@@ -311,7 +414,7 @@ if __name__ == '__main__':
|
|
311 |
if not os.path.exists(args.save_dir):
|
312 |
os.makedirs(args.save_dir, exist_ok=True)
|
313 |
|
314 |
-
with gr.Blocks() as demo:
|
315 |
infer_gr = VACEInference(args, skip_load=False, gallery_share=True, gallery_share_limit=5)
|
316 |
infer_gr.create_ui()
|
317 |
infer_gr.set_callbacks()
|
|
|
10 |
import torch
|
11 |
import gradio as gr
|
12 |
|
13 |
+
is_shared_ui = True if "fffiloni/Wan2.1-VACE-1.3B" in os.environ['SPACE_ID'] else False
|
14 |
+
is_gpu_associated = torch.cuda.is_available()
|
15 |
|
16 |
+
from huggingface_hub import snapshot_download
|
|
|
|
|
|
|
17 |
|
18 |
+
if not is_shared_ui and is_gpu_associated:
|
19 |
+
snapshot_download(
|
20 |
+
repo_id = "Wan-AI/Wan2.1-VACE-1.3B",
|
21 |
+
local_dir = "./models/Wan2.1-VACE-1.3B"
|
22 |
+
)
|
23 |
|
24 |
sys.path.insert(0, os.path.sep.join(os.path.realpath(__file__).split(os.path.sep)[:-2]))
|
25 |
import wan
|
26 |
from wan import WanVace, WanVaceMP
|
27 |
from wan.configs import WAN_CONFIGS, SIZE_CONFIGS
|
28 |
|
29 |
+
css = """
|
30 |
+
div#warning-duplicate {
|
31 |
+
background-color: #ebf5ff;
|
32 |
+
padding: 0 16px 16px;
|
33 |
+
margin: 20px 0;
|
34 |
+
color: #030303!important;
|
35 |
+
}
|
36 |
+
div#warning-duplicate > .gr-prose > h2, div#warning-duplicate > .gr-prose > p {
|
37 |
+
color: #0f4592!important;
|
38 |
+
}
|
39 |
+
div#warning-duplicate strong {
|
40 |
+
color: #0f4592;
|
41 |
+
}
|
42 |
+
p.actions {
|
43 |
+
display: flex;
|
44 |
+
align-items: center;
|
45 |
+
margin: 20px 0;
|
46 |
+
}
|
47 |
+
div#warning-duplicate .actions a {
|
48 |
+
display: inline-block;
|
49 |
+
margin-right: 10px;
|
50 |
+
}
|
51 |
+
div#warning-setgpu {
|
52 |
+
background-color: #fff4eb;
|
53 |
+
padding: 0 16px 16px;
|
54 |
+
margin: 20px 0;
|
55 |
+
color: #030303!important;
|
56 |
+
}
|
57 |
+
div#warning-setgpu > .gr-prose > h2, div#warning-setgpu > .gr-prose > p {
|
58 |
+
color: #92220f!important;
|
59 |
+
}
|
60 |
+
div#warning-setgpu a, div#warning-setgpu b {
|
61 |
+
color: #91230f;
|
62 |
+
}
|
63 |
+
div#warning-setgpu p.actions > a {
|
64 |
+
display: inline-block;
|
65 |
+
background: #1f1f23;
|
66 |
+
border-radius: 40px;
|
67 |
+
padding: 6px 24px;
|
68 |
+
color: antiquewhite;
|
69 |
+
text-decoration: none;
|
70 |
+
font-weight: 600;
|
71 |
+
font-size: 1.2em;
|
72 |
+
}
|
73 |
+
div#warning-ready {
|
74 |
+
background-color: #ecfdf5;
|
75 |
+
padding: 0 16px 16px;
|
76 |
+
margin: 20px 0;
|
77 |
+
color: #030303!important;
|
78 |
+
}
|
79 |
+
div#warning-ready > .gr-prose > h2, div#warning-ready > .gr-prose > p {
|
80 |
+
color: #057857!important;
|
81 |
+
}
|
82 |
+
.custom-color {
|
83 |
+
color: #030303 !important;
|
84 |
+
}
|
85 |
+
"""
|
86 |
+
|
87 |
|
88 |
class FixedSizeQueue:
|
89 |
def __init__(self, max_size):
|
|
|
142 |
</a>
|
143 |
</div>
|
144 |
""")
|
145 |
+
with gr.Column():
|
146 |
+
if is_shared_ui:
|
147 |
+
top_description = gr.HTML(f'''
|
148 |
+
<div class="gr-prose">
|
149 |
+
<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>
|
150 |
+
Attention: this Space need to be duplicated to work</h2>
|
151 |
+
<p class="main-message custom-color">
|
152 |
+
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 />
|
153 |
+
A L40s costs <strong>US$1.80/h</strong>.
|
154 |
+
</p>
|
155 |
+
<p class="actions custom-color">
|
156 |
+
<a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}?duplicate=true">
|
157 |
+
<img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-lg-dark.svg" alt="Duplicate this Space" />
|
158 |
+
</a>
|
159 |
+
to start experimenting with this demo
|
160 |
+
</p>
|
161 |
+
</div>
|
162 |
+
''', elem_id="warning-duplicate")
|
163 |
+
else:
|
164 |
+
if(is_gpu_associated):
|
165 |
+
top_description = gr.HTML(f'''
|
166 |
+
<div class="gr-prose">
|
167 |
+
<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>
|
168 |
+
You have successfully associated a GPU to this Space π</h2>
|
169 |
+
<p class="custom-color">
|
170 |
+
You will be billed by the minute from when you activated the GPU until when it is turned off.
|
171 |
+
</p>
|
172 |
+
</div>
|
173 |
+
''', elem_id="warning-ready")
|
174 |
+
else:
|
175 |
+
top_description = gr.HTML(f'''
|
176 |
+
<div class="gr-prose">
|
177 |
+
<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>
|
178 |
+
You have successfully duplicated the MimicMotion Space π</h2>
|
179 |
+
<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.
|
180 |
+
You will be billed by the minute from when you activate the GPU until when it is turned off.</p>
|
181 |
+
<p class="actions custom-color">
|
182 |
+
<a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}/settings">π₯ Set recommended GPU</a>
|
183 |
+
</p>
|
184 |
+
</div>
|
185 |
+
''', elem_id="warning-setgpu")
|
186 |
with gr.Row(variant='panel', equal_height=True):
|
187 |
with gr.Column(scale=1, min_width=0):
|
188 |
self.src_video = gr.Video(
|
|
|
310 |
value='Run',
|
311 |
elem_classes='type_row',
|
312 |
elem_id='generate_button',
|
313 |
+
visible=True,
|
314 |
+
interactive = False if is_shared_ui else True
|
315 |
+
)
|
316 |
with gr.Column(scale=1):
|
317 |
self.refresh_button = gr.Button(value='\U0001f504') # π
|
318 |
#
|
|
|
414 |
if not os.path.exists(args.save_dir):
|
415 |
os.makedirs(args.save_dir, exist_ok=True)
|
416 |
|
417 |
+
with gr.Blocks(css=css) as demo:
|
418 |
infer_gr = VACEInference(args, skip_load=False, gallery_share=True, gallery_share_limit=5)
|
419 |
infer_gr.create_ui()
|
420 |
infer_gr.set_callbacks()
|