soonyau commited on
Commit
58710a6
·
1 Parent(s): 180336c

update GUI

Browse files
.gitignore CHANGED
@@ -1,5 +1,5 @@
1
  # pictures
2
- *.jpg
3
 
4
  # application specific
5
  lightning_logs/
 
1
  # pictures
2
+ #*.jpg
3
 
4
  # application specific
5
  lightning_logs/
app.py CHANGED
@@ -283,12 +283,12 @@ def create_app():
283
  gr.Markdown("## ViscoNet: Visual ControlNet with Human Pose and Fashion <br> [Video tutorial](https://youtu.be/85NyIuLeV00)")
284
  with gr.Row():
285
  with gr.Column():
286
- with gr.Accordion("Get pose and mask", open=False):
287
  with gr.Row():
288
  input_image = gr.Image(source='upload', type="numpy", label='input image', value=np.array(get_image_numpy('ref')))
289
  pose_image = gr.Image(source='upload', type="numpy", label='pose', value=np.array(get_image_numpy('pose')))
290
  mask_image = gr.Image(source='upload', type="numpy", label='mask', value=np.array(get_image_numpy('mask')))
291
- with gr.Accordion("Samples", open=False):
292
  with gr.Tab('Female'):
293
  samples = get_image_files(str(SAMPLE_IMAGE_PATH/'pose/WOMEN/'))
294
  female_pose_gallery = gr.Gallery(label='pose', show_label=False, value=samples).style(grid=3, height='auto')
@@ -297,7 +297,7 @@ def create_app():
297
  male_pose_gallery = gr.Gallery(label='pose', show_label=False, value=samples).style(grid=3, height='auto')
298
  with gr.Row():
299
  #pad_checkbox = gr.Checkbox(label='Pad pose to square', value=True)
300
- ignorehead_checkbox = gr.Checkbox(label='Ignore face in masking (for DeepFake)', value=True)
301
  ignorehair_checkbox = gr.Checkbox(label='Ignore hair in masking', value=False, visible=True)
302
  with gr.Row():
303
  #ignore_head_checkbox = gr.Checkbox(label='Ignore head', value=False)
@@ -305,7 +305,7 @@ def create_app():
305
  get_fashion_button = gr.Button(label="Get visual", value='Get visual prompt')
306
 
307
 
308
- with gr.Accordion("Visual Conditions", open=False):
309
  gr.Markdown('Drag-and-drop, or click from samples below.')
310
  with gr.Column():
311
  viscon_images = []
@@ -325,79 +325,78 @@ def create_app():
325
 
326
  viscon_galleries = []
327
 
328
- with gr.Column():
329
- with gr.Accordion("Female", open=False):
330
- for garment, number in zip(['hair', 'top', 'bottom', 'outer'], [150, 500, 500, 250]):
331
- with gr.Tab(garment):
332
- samples = []
333
- if WOMEN_GALLERY_PATH and os.path.exists(WOMEN_GALLERY_PATH):
334
- samples = glob(os.path.join(WOMEN_GALLERY_PATH, f'**/{garment}.jpg'), recursive=True)
335
- #samples = glob(f'/home/soon/datasets/deepfashion_inshop/styles_default/WOMEN/**/{garment}.jpg', recursive=True)
336
- samples = random.choices(samples, k=number)
337
- viscon_gallery = gr.Gallery(label='hair', allow_preview=False, show_label=False, value=samples).style(grid=4, height='auto')
338
- viscon_galleries.append({'component':viscon_gallery, 'inputs':[garment]})
339
- with gr.Accordion("Male", open=False):
340
- for garment, number in zip(['hair', 'top', 'bottom', 'outer'], [150, 500, 500, 250]):
341
- with gr.Tab(garment):
342
- samples = []
343
- if MEN_GALLERY_PATH and os.path.exists(MEN_GALLERY_PATH):
344
- samples = glob(os.path.join(MEN_GALLERY_PATH, f'**/{garment}.jpg'), recursive=True)
345
- samples = random.choices(samples, k=number)
346
- viscon_gallery = gr.Gallery(label='hair', allow_preview=False, show_label=False, value=samples).style(grid=4, height='auto')
347
- viscon_galleries.append({'component':viscon_gallery, 'inputs':[garment]})
348
-
349
- with gr.Accordion("Control Strength Scaling", open=False):
350
- gr.Markdown("smaller value for stronger textual influence. c12 is highest spatial resolution controlling textures")
351
- with gr.Row():
352
- strength_select = gr.Dropdown(list(SCALE_CONFIG.keys()), label='strength settings', value=DEFAULT_SCALE_CONFIG)
353
- scale_all = gr.Slider(label=f'set all scales', minimum=0, maximum=1, value=DEFAULT_CONTROL_SCALE, step=0.05)
354
- scale_values = SCALE_CONFIG[DEFAULT_SCALE_CONFIG]
355
- control_scales = []
356
- c_idx = 12
357
- with gr.Accordion("Advanced settings", open=False):
358
- with gr.Row():
359
- for _ in range(3):
360
- control_scales.append(gr.Slider(label=f'c{c_idx}', minimum=0, maximum=1, value=scale_values[12-c_idx], step=0.05))
361
- c_idx -= 1
362
- with gr.Row():
363
- for _ in range(3):
364
- control_scales.append(gr.Slider(label=f'c{c_idx}', minimum=0, maximum=1, value=scale_values[12-c_idx], step=0.05))
365
- c_idx -= 1
366
- with gr.Row():
367
- for _ in range(3):
368
- control_scales.append(gr.Slider(label=f'c{c_idx}', minimum=0, maximum=1, value=scale_values[12-c_idx], step=0.05))
369
- c_idx -= 1
370
- with gr.Row():
371
- for _ in range(4):
372
- control_scales.append(gr.Slider(label=f'c{c_idx}', minimum=0, maximum=1, value=scale_values[12-c_idx], step=0.05))
373
- c_idx -= 1
374
 
375
- with gr.Accordion("Advanced options", open=False):
376
- with gr.Row():
377
- detect_resolution = gr.Slider(label="OpenPose Resolution", minimum=128, maximum=512, value=512, step=1)
378
- ddim_steps = gr.Slider(label="Steps", minimum=1, maximum=50, value=20, step=1)
379
- scale = gr.Slider(label="Guidance Scale", minimum=0.1, maximum=30.0, value=12.0, step=0.1)
380
-
381
- eta = gr.Number(label="eta (DDIM)", value=0.0, visible=False)
382
- a_prompt = gr.Textbox(label="Added Prompt", value='best quality, extremely detailed')
383
- n_prompt = gr.Textbox(label="Negative Prompt",
384
- value='longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, sunglasses, hat')
385
  with gr.Column():
386
  result_gallery = gr.Gallery(label='Output', show_label=False, show_download_button=True, elem_id="gallery").style(grid=1, height='auto')
387
  with gr.Row():
388
  max_samples = 8 if not DEMO else 4
389
  num_samples = gr.Slider(label="Images", minimum=1, maximum=max_samples, value=1, step=1)
 
390
  seed = gr.Slider(label="Seed (-1 for random)", minimum=-1, maximum=2147483647, step=1, value=1561194236)#randomize=True) #value=1561194234)
391
  if not DEMO:
392
  DF_DEMO = 'fashionWOMENTees_Tanksid0000762403_1front___fashionWOMENTees_Tanksid0000762403_1front'
393
  DF_EVAL = 'fashionWOMENBlouses_Shirtsid0000035501_1front___fashionWOMENBlouses_Shirtsid0000035501_1front'
394
  DF_RESULT ="fashionWOMENTees_Tanksid0000796209_1front___fashionWOMENTees_Tanksid0000796209_2side"
395
- deepfashion_names = gr.Textbox(label='Deepfashion name', value=DF_EVAL)
396
  gr.Markdown("Default config reconstruct image faithful to pose, mask and visual condition. Reduce control strength to tip balance towards text prompt for more creativity.")
397
  prompt = gr.Textbox(label="Text Prompt", value="")
398
 
399
  run_button = gr.Button(label="Run")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
400
 
 
 
 
 
401
 
402
  female_pose_gallery.select(fn=select_gallery_image, inputs=None, outputs=input_image)
403
  male_pose_gallery.select(fn=select_gallery_image, inputs=None, outputs=input_image)
@@ -421,7 +420,7 @@ def create_app():
421
  return block
422
 
423
  if __name__ == "__main__":
424
- parser = argparse.ArgumentParser(description='Calculate image-text similarity score.')
425
 
426
  parser.add_argument('--gpu', type=int, default=0, help='GPU id')
427
  parser.add_argument('--config', type=str, default='./configs/visconet_v1.yaml')
@@ -451,8 +450,9 @@ if __name__ == "__main__":
451
  segmentor = SegmentCropper()
452
  apply_openpose = OpenposeDetector()
453
 
454
- snapshot_download(repo_id=HF_REPO, local_dir='./models',
455
- allow_patterns=os.path.basename(model_ckpt))
 
456
 
457
  style_encoder = instantiate_from_config(proj_config.model.style_embedding_config).to(device)
458
  model = create_model(config_file).cpu()
@@ -472,4 +472,4 @@ if __name__ == "__main__":
472
 
473
  # Calling the main function with parsed arguments
474
  block = create_app()
475
- block.launch()
 
283
  gr.Markdown("## ViscoNet: Visual ControlNet with Human Pose and Fashion <br> [Video tutorial](https://youtu.be/85NyIuLeV00)")
284
  with gr.Row():
285
  with gr.Column():
286
+ with gr.Accordion("Get pose and mask", open=True):
287
  with gr.Row():
288
  input_image = gr.Image(source='upload', type="numpy", label='input image', value=np.array(get_image_numpy('ref')))
289
  pose_image = gr.Image(source='upload', type="numpy", label='pose', value=np.array(get_image_numpy('pose')))
290
  mask_image = gr.Image(source='upload', type="numpy", label='mask', value=np.array(get_image_numpy('mask')))
291
+ with gr.Accordion("Human Pose Samples", open=False):
292
  with gr.Tab('Female'):
293
  samples = get_image_files(str(SAMPLE_IMAGE_PATH/'pose/WOMEN/'))
294
  female_pose_gallery = gr.Gallery(label='pose', show_label=False, value=samples).style(grid=3, height='auto')
 
297
  male_pose_gallery = gr.Gallery(label='pose', show_label=False, value=samples).style(grid=3, height='auto')
298
  with gr.Row():
299
  #pad_checkbox = gr.Checkbox(label='Pad pose to square', value=True)
300
+ ignorehead_checkbox = gr.Checkbox(label='Ignore face in masking (for faceswap with text)', value=False)
301
  ignorehair_checkbox = gr.Checkbox(label='Ignore hair in masking', value=False, visible=True)
302
  with gr.Row():
303
  #ignore_head_checkbox = gr.Checkbox(label='Ignore head', value=False)
 
305
  get_fashion_button = gr.Button(label="Get visual", value='Get visual prompt')
306
 
307
 
308
+ with gr.Accordion("Visual Conditions", open=True):
309
  gr.Markdown('Drag-and-drop, or click from samples below.')
310
  with gr.Column():
311
  viscon_images = []
 
325
 
326
  viscon_galleries = []
327
 
328
+ with gr.Accordion("Virtual Try-on", open=False):
329
+ with gr.Column():
330
+ #with gr.Accordion("Female", open=False):
331
+ with gr.Tab('Female'):
332
+ for garment, number in zip(['face', 'hair', 'top', 'bottom', 'outer'], [50, 150, 500, 500, 250]):
333
+ with gr.Tab(garment):
334
+ samples = []
335
+ if WOMEN_GALLERY_PATH and os.path.exists(WOMEN_GALLERY_PATH):
336
+ samples = glob(os.path.join(WOMEN_GALLERY_PATH, f'**/{garment}.jpg'), recursive=True)
337
+ samples = random.choices(samples, k=number)
338
+ viscon_gallery = gr.Gallery(label='hair', allow_preview=False, show_label=False, value=samples).style(grid=4, height='auto')
339
+ viscon_galleries.append({'component':viscon_gallery, 'inputs':[garment]})
340
+ #with gr.Accordion("Male", open=False):
341
+ with gr.Tab('Male'):
342
+ for garment, number in zip(['face','hair', 'top', 'bottom', 'outer'], [50, 150, 500, 500, 250]):
343
+ with gr.Tab(garment):
344
+ samples = []
345
+ if MEN_GALLERY_PATH and os.path.exists(MEN_GALLERY_PATH):
346
+ samples = glob(os.path.join(MEN_GALLERY_PATH, f'**/{garment}.jpg'), recursive=True)
347
+ samples = random.choices(samples, k=number)
348
+ viscon_gallery = gr.Gallery(label='hair', allow_preview=False, show_label=False, value=samples).style(grid=4, height='auto')
349
+ viscon_galleries.append({'component':viscon_gallery, 'inputs':[garment]})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
 
 
 
 
 
 
 
 
 
 
 
351
  with gr.Column():
352
  result_gallery = gr.Gallery(label='Output', show_label=False, show_download_button=True, elem_id="gallery").style(grid=1, height='auto')
353
  with gr.Row():
354
  max_samples = 8 if not DEMO else 4
355
  num_samples = gr.Slider(label="Images", minimum=1, maximum=max_samples, value=1, step=1)
356
+ scale_all = gr.Slider(label=f'Control Strength', minimum=0, maximum=1, value=DEFAULT_CONTROL_SCALE, step=0.05)
357
  seed = gr.Slider(label="Seed (-1 for random)", minimum=-1, maximum=2147483647, step=1, value=1561194236)#randomize=True) #value=1561194234)
358
  if not DEMO:
359
  DF_DEMO = 'fashionWOMENTees_Tanksid0000762403_1front___fashionWOMENTees_Tanksid0000762403_1front'
360
  DF_EVAL = 'fashionWOMENBlouses_Shirtsid0000035501_1front___fashionWOMENBlouses_Shirtsid0000035501_1front'
361
  DF_RESULT ="fashionWOMENTees_Tanksid0000796209_1front___fashionWOMENTees_Tanksid0000796209_2side"
362
+ deepfashion_names = gr.Textbox(label='Deepfashion name', value=DF_EVAL)
363
  gr.Markdown("Default config reconstruct image faithful to pose, mask and visual condition. Reduce control strength to tip balance towards text prompt for more creativity.")
364
  prompt = gr.Textbox(label="Text Prompt", value="")
365
 
366
  run_button = gr.Button(label="Run")
367
+ with gr.Accordion("Advanced options", open=False):
368
+ with gr.Accordion("Control Strength Scaling", open=False):
369
+ gr.Markdown("smaller value for stronger textual influence. c12 is highest spatial resolution controlling textures")
370
+ strength_select = gr.Dropdown(list(SCALE_CONFIG.keys()), label='strength settings', value=DEFAULT_SCALE_CONFIG)
371
+ scale_values = SCALE_CONFIG[DEFAULT_SCALE_CONFIG]
372
+ control_scales = []
373
+ c_idx = 12
374
+ with gr.Accordion("Advanced settings", open=False):
375
+ with gr.Row():
376
+ for _ in range(3):
377
+ control_scales.append(gr.Slider(label=f'c{c_idx}', minimum=0, maximum=1, value=scale_values[12-c_idx], step=0.05))
378
+ c_idx -= 1
379
+ with gr.Row():
380
+ for _ in range(3):
381
+ control_scales.append(gr.Slider(label=f'c{c_idx}', minimum=0, maximum=1, value=scale_values[12-c_idx], step=0.05))
382
+ c_idx -= 1
383
+ with gr.Row():
384
+ for _ in range(3):
385
+ control_scales.append(gr.Slider(label=f'c{c_idx}', minimum=0, maximum=1, value=scale_values[12-c_idx], step=0.05))
386
+ c_idx -= 1
387
+ with gr.Row():
388
+ for _ in range(4):
389
+ control_scales.append(gr.Slider(label=f'c{c_idx}', minimum=0, maximum=1, value=scale_values[12-c_idx], step=0.05))
390
+ c_idx -= 1
391
+ with gr.Row():
392
+ detect_resolution = gr.Slider(label="OpenPose Resolution", minimum=128, maximum=512, value=512, step=1)
393
+ ddim_steps = gr.Slider(label="Steps", minimum=1, maximum=50, value=20, step=1)
394
+ scale = gr.Slider(label="Guidance Scale", minimum=0.1, maximum=30.0, value=12.0, step=0.1)
395
 
396
+ eta = gr.Number(label="eta (DDIM)", value=0.0, visible=False)
397
+ a_prompt = gr.Textbox(label="Added Prompt", value='best quality, extremely detailed')
398
+ n_prompt = gr.Textbox(label="Negative Prompt",
399
+ value='longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, sunglasses, hat')
400
 
401
  female_pose_gallery.select(fn=select_gallery_image, inputs=None, outputs=input_image)
402
  male_pose_gallery.select(fn=select_gallery_image, inputs=None, outputs=input_image)
 
420
  return block
421
 
422
  if __name__ == "__main__":
423
+ parser = argparse.ArgumentParser()
424
 
425
  parser.add_argument('--gpu', type=int, default=0, help='GPU id')
426
  parser.add_argument('--config', type=str, default='./configs/visconet_v1.yaml')
 
450
  segmentor = SegmentCropper()
451
  apply_openpose = OpenposeDetector()
452
 
453
+ if not os.path.exists(model_ckpt):
454
+ snapshot_download(repo_id=HF_REPO, local_dir='./models',
455
+ allow_patterns=os.path.basename(model_ckpt))
456
 
457
  style_encoder = instantiate_from_config(proj_config.model.style_embedding_config).to(device)
458
  model = create_model(config_file).cpu()
 
472
 
473
  # Calling the main function with parsed arguments
474
  block = create_app()
475
+ block.launch(share=args.public_link)
app_files/default_images/bottom.jpg ADDED
app_files/default_images/mask.png CHANGED
app_files/default_images/top.jpg ADDED