fffiloni commited on
Commit
e6accad
·
verified ·
1 Parent(s): 1ede279

update to only work on duplicated gpu instances

Browse files
Files changed (1) hide show
  1. simple_app.py +111 -7
simple_app.py CHANGED
@@ -1,4 +1,9 @@
1
  import gradio as gr
 
 
 
 
 
2
  import re
3
  import subprocess
4
  import time
@@ -6,11 +11,12 @@ import select
6
  from tqdm import tqdm
7
  from huggingface_hub import snapshot_download
8
 
9
- #Download model
10
- snapshot_download(
11
- repo_id = "Wan-AI/Wan2.1-T2V-1.3B",
12
- local_dir = "./Wan2.1-T2V-1.3B"
13
- )
 
14
 
15
  def infer(prompt, progress=gr.Progress(track_tqdm=True)):
16
 
@@ -147,7 +153,65 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
147
  print("Error executing command.")
148
  raise Exception("Error executing command")
149
 
150
- with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  with gr.Column():
152
  gr.Markdown("# Wan 2.1 1.3B")
153
  gr.Markdown("Enjoy this simple working UI, duplicate the space to skip the queue :)")
@@ -161,8 +225,48 @@ with gr.Blocks() as demo:
161
  </a>
162
  </div>
163
  """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  prompt = gr.Textbox(label="Prompt")
165
- submit_btn = gr.Button("Submit")
166
  video_res = gr.Video(label="Generated Video")
167
 
168
  submit_btn.click(
 
1
  import gradio as gr
2
+ import torch
3
+
4
+ is_shared_ui = True if "fffiloni/Wan2.1" in os.environ['SPACE_ID'] else False
5
+ is_gpu_associated = torch.cuda.is_available()
6
+
7
  import re
8
  import subprocess
9
  import time
 
11
  from tqdm import tqdm
12
  from huggingface_hub import snapshot_download
13
 
14
+ if not is_shared_ui and is_gpu_associated:
15
+ #Download model
16
+ snapshot_download(
17
+ repo_id = "Wan-AI/Wan2.1-T2V-1.3B",
18
+ local_dir = "./Wan2.1-T2V-1.3B"
19
+ )
20
 
21
  def infer(prompt, progress=gr.Progress(track_tqdm=True)):
22
 
 
153
  print("Error executing command.")
154
  raise Exception("Error executing command")
155
 
156
+ css = """
157
+ div#warning-duplicate {
158
+ background-color: #ebf5ff;
159
+ padding: 0 16px 16px;
160
+ margin: 20px 0;
161
+ color: #030303!important;
162
+ }
163
+ div#warning-duplicate > .gr-prose > h2, div#warning-duplicate > .gr-prose > p {
164
+ color: #0f4592!important;
165
+ }
166
+ div#warning-duplicate strong {
167
+ color: #0f4592;
168
+ }
169
+ p.actions {
170
+ display: flex;
171
+ align-items: center;
172
+ margin: 20px 0;
173
+ }
174
+ div#warning-duplicate .actions a {
175
+ display: inline-block;
176
+ margin-right: 10px;
177
+ }
178
+ div#warning-setgpu {
179
+ background-color: #fff4eb;
180
+ padding: 0 16px 16px;
181
+ margin: 20px 0;
182
+ color: #030303!important;
183
+ }
184
+ div#warning-setgpu > .gr-prose > h2, div#warning-setgpu > .gr-prose > p {
185
+ color: #92220f!important;
186
+ }
187
+ div#warning-setgpu a, div#warning-setgpu b {
188
+ color: #91230f;
189
+ }
190
+ div#warning-setgpu p.actions > a {
191
+ display: inline-block;
192
+ background: #1f1f23;
193
+ border-radius: 40px;
194
+ padding: 6px 24px;
195
+ color: antiquewhite;
196
+ text-decoration: none;
197
+ font-weight: 600;
198
+ font-size: 1.2em;
199
+ }
200
+ div#warning-ready {
201
+ background-color: #ecfdf5;
202
+ padding: 0 16px 16px;
203
+ margin: 20px 0;
204
+ color: #030303!important;
205
+ }
206
+ div#warning-ready > .gr-prose > h2, div#warning-ready > .gr-prose > p {
207
+ color: #057857!important;
208
+ }
209
+ .custom-color {
210
+ color: #030303 !important;
211
+ }
212
+ """
213
+
214
+ with gr.Blocks(css=css) as demo:
215
  with gr.Column():
216
  gr.Markdown("# Wan 2.1 1.3B")
217
  gr.Markdown("Enjoy this simple working UI, duplicate the space to skip the queue :)")
 
225
  </a>
226
  </div>
227
  """)
228
+ if is_shared_ui:
229
+ top_description = gr.HTML(f'''
230
+ <div class="gr-prose">
231
+ <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>
232
+ Attention: this Space need to be duplicated to work</h2>
233
+ <p class="main-message custom-color">
234
+ 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 />
235
+ A L40s costs <strong>US$1.80/h</strong>.
236
+ </p>
237
+ <p class="actions custom-color">
238
+ <a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}?duplicate=true">
239
+ <img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-lg-dark.svg" alt="Duplicate this Space" />
240
+ </a>
241
+ to start experimenting with this demo
242
+ </p>
243
+ </div>
244
+ ''', elem_id="warning-duplicate")
245
+ else:
246
+ if(is_gpu_associated):
247
+ top_description = gr.HTML(f'''
248
+ <div class="gr-prose">
249
+ <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>
250
+ You have successfully associated a GPU to this Space 🎉</h2>
251
+ <p class="custom-color">
252
+ You will be billed by the minute from when you activated the GPU until when it is turned off.
253
+ </p>
254
+ </div>
255
+ ''', elem_id="warning-ready")
256
+ else:
257
+ top_description = gr.HTML(f'''
258
+ <div class="gr-prose">
259
+ <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>
260
+ You have successfully duplicated the MimicMotion Space 🎉</h2>
261
+ <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.
262
+ You will be billed by the minute from when you activate the GPU until when it is turned off.</p>
263
+ <p class="actions custom-color">
264
+ <a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}/settings">🔥 &nbsp; Set recommended GPU</a>
265
+ </p>
266
+ </div>
267
+ ''', elem_id="warning-setgpu")
268
  prompt = gr.Textbox(label="Prompt")
269
+ submit_btn = gr.Button("Submit", interactive=False if is_shared_ui else True)
270
  video_res = gr.Video(label="Generated Video")
271
 
272
  submit_btn.click(