fffiloni commited on
Commit
28e784b
1 Parent(s): b7880b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -5
app.py CHANGED
@@ -7,6 +7,14 @@ import cv2
7
  import huggingface_hub
8
  import subprocess
9
  import threading
 
 
 
 
 
 
 
 
10
 
11
  def stream_output(pipe):
12
  for line in iter(pipe.readline, ''):
@@ -174,16 +182,81 @@ def infer(ref_image_in, ref_video_in):
174
 
175
  return mp4_file_path
176
 
177
- output_video = gr.Video()
178
 
179
- with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  with gr.Column():
 
181
  with gr.Row():
182
  with gr.Column():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  with gr.Row():
184
- ref_image_in = gr.Image(type="filepath")
185
- ref_video_in = gr.Video()
186
- submit_btn = gr.Button("Submit")
 
 
 
 
 
187
  gr.Examples(
188
  examples = [
189
  ["./examples/demo1.jpg", "./examples/preview_1.mp4"]
 
7
  import huggingface_hub
8
  import subprocess
9
  import threading
10
+ from subprocess import getoutput
11
+
12
+ is_shared_ui = False
13
+ # is_shared_ui = True if "fffiloni/MimicMotion" in os.environ['SPACE_ID'] else False
14
+ available_property = False if is_shared_ui else True
15
+
16
+ is_gpu_associated = torch.cuda.is_available()
17
+ gpu_info = getoutput('nvidia-smi')
18
 
19
  def stream_output(pipe):
20
  for line in iter(pipe.readline, ''):
 
182
 
183
  return mp4_file_path
184
 
185
+ output_video = gr.Video(label="Output Video")
186
 
187
+ css = """
188
+ div#warning-duplicate {
189
+ background-color: #ebf5ff;
190
+ padding: 0 16px 16px;
191
+ margin: 20px 0;
192
+ color: #030303!important;
193
+ }
194
+ div#warning-duplicate > .gr-prose > h2, div#warning-duplicate > .gr-prose > p {
195
+ color: #0f4592!important;
196
+ }
197
+ div#warning-duplicate strong {
198
+ color: #0f4592;
199
+ }
200
+ p.actions {
201
+ display: flex;
202
+ align-items: center;
203
+ margin: 20px 0;
204
+ }
205
+ div#warning-duplicate .actions a {
206
+ display: inline-block;
207
+ margin-right: 10px;
208
+ }
209
+ div#warning-ready {
210
+ background-color: #ecfdf5;
211
+ padding: 0 16px 16px;
212
+ margin: 20px 0;
213
+ color: #030303!important;
214
+ }
215
+ div#warning-ready > .gr-prose > h2, div#warning-ready > .gr-prose > p {
216
+ color: #057857!important;
217
+ }
218
+ """
219
+ with gr.Blocks(css=css) as demo:
220
  with gr.Column():
221
+ gr.Markdown("# MimicMotion")
222
  with gr.Row():
223
  with gr.Column():
224
+ if is_shared_ui:
225
+ top_description = gr.HTML(f'''
226
+ <div class="gr-prose">
227
+ <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>
228
+ Attention: this Space need to be duplicated to work</h2>
229
+ <p class="main-message custom-color">
230
+ To make it work, <strong>duplicate the Space</strong> and run it on your own profile using a <strong>private</strong> GPU (A10G-large recommended).<br />
231
+ A A10G-large costs <strong>US$1.50/h</strong>.
232
+ </p>
233
+ <p class="actions custom-color">
234
+ <a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}?duplicate=true">
235
+ <img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-lg-dark.svg" alt="Duplicate this Space" />
236
+ </a>
237
+ to start experimenting with this demo
238
+ </p>
239
+ </div>
240
+ ''', elem_id="warning-duplicate")
241
+ else:
242
+ top_description = gr.HTML(f'''
243
+ <div class="gr-prose">
244
+ <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>
245
+ You have successfully associated a {gpu_info} GPU to the MimicMotion Space 🎉</h2>
246
+ <p class="custom-color">
247
+ You will be billed by the minute from when you activated the GPU until when it is turned off.
248
+ </p>
249
+ </div>
250
+ ''', elem_id="warning-ready")
251
  with gr.Row():
252
+ ref_image_in = gr.Image(label="Person Image Reference", type="filepath")
253
+ ref_video_in = gr.Video(label="Person Video Reference")
254
+ with gr.Accordion("Advanced Settings", open=False):
255
+ num_inference_steps = gr.Slider(label="num inference steps", minimum=12, maximum=50, value=25, step=1, interactive=available_property)
256
+ guidance_scale = gr.Slider(label="guidance scale", minimum=0.1, maximum=10, value=2, step=0.1, interactive=available_property)
257
+ output_frames_per_second = gr.Slider(label="fps", minimum=1, maximum=60, value=16, step=1, interactive=available_property)
258
+ seed = gr.Number(label="Seed", value=42, interactive=available_property)
259
+ submit_btn = gr.Button("Submit", interactive=available_property)
260
  gr.Examples(
261
  examples = [
262
  ["./examples/demo1.jpg", "./examples/preview_1.mp4"]