Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
3ceda9e
1
Parent(s):
9b35681
final touch/test, tutorials
Browse files- .gitignore +2 -1
- app.py +110 -96
.gitignore
CHANGED
@@ -6,4 +6,5 @@ diffusion/__pycache__/
|
|
6 |
*.pyc
|
7 |
DINO_EMA_11M_b50_lr1e-5_epoch6_step320k.ckpt
|
8 |
sam_vit_h_4b8939.pth
|
9 |
-
vae-ft-mse-840000-ema-pruned.ckpt
|
|
|
|
6 |
*.pyc
|
7 |
DINO_EMA_11M_b50_lr1e-5_epoch6_step320k.ckpt
|
8 |
sam_vit_h_4b8939.pth
|
9 |
+
vae-ft-mse-840000-ema-pruned.ckpt
|
10 |
+
how_to_videos/
|
app.py
CHANGED
@@ -17,8 +17,6 @@ from io import BytesIO
|
|
17 |
from PIL import Image
|
18 |
import random
|
19 |
from copy import deepcopy
|
20 |
-
from typing import Optional
|
21 |
-
import requests
|
22 |
from huggingface_hub import hf_hub_download
|
23 |
try:
|
24 |
import spaces
|
@@ -47,10 +45,7 @@ def set_seed(seed):
|
|
47 |
torch.cuda.manual_seed_all(seed)
|
48 |
random.seed(seed)
|
49 |
|
50 |
-
# if torch.cuda.is_available():
|
51 |
device = "cuda"
|
52 |
-
# else:
|
53 |
-
# device = "cpu"
|
54 |
|
55 |
def remove_prefix(text, prefix):
|
56 |
if text.startswith(prefix):
|
@@ -487,16 +482,6 @@ def visualize_ref(ref):
|
|
487 |
img = mask_image(img, mask)
|
488 |
return img, inpaint_mask
|
489 |
|
490 |
-
# def inpaint_from_example(ex_mask):
|
491 |
-
# inpaint_mask = (ex_mask[:,:, -1] == 0).astype(np.uint8)
|
492 |
-
# inpaint_mask = np.tile(inpaint_mask[..., None], (1, 1, 4))
|
493 |
-
# ret = {
|
494 |
-
# "background": cv2.cvtColor(ex_mask, cv2.COLOR_RGB2RGBA),
|
495 |
-
# "layers": [inpaint_mask],
|
496 |
-
# "composite": cv2.cvtColor(ex_mask, cv2.COLOR_RGB2RGBA)
|
497 |
-
# }
|
498 |
-
# return ret
|
499 |
-
|
500 |
def get_kps(img, keypoints, side: Literal["right", "left"], evt: gr.SelectData):
|
501 |
if keypoints is None:
|
502 |
keypoints = [[], []]
|
@@ -630,7 +615,8 @@ def sample_diff(ref_cond, target_cond, target_keypts, num_gen, seed, cfg):
|
|
630 |
nvs=torch.cat([nvs, 2 * torch.ones_like(nvs)]),
|
631 |
cfg_scale=cfg,
|
632 |
)
|
633 |
-
|
|
|
634 |
samples, _ = diffusion.p_sample_loop(
|
635 |
model.forward_with_cfg,
|
636 |
z.shape,
|
@@ -835,7 +821,7 @@ def sample_inpaint(
|
|
835 |
cfg_scale=cfg_scale,
|
836 |
)
|
837 |
|
838 |
-
gr.Info("The process successfully started to run. Please wait for around 3.5 minutes.", duration=
|
839 |
samples, _ = diffusion.inpaint_p_sample_loop(
|
840 |
model.forward_with_cfg,
|
841 |
z.shape,
|
@@ -1224,17 +1210,15 @@ fix_example_brush = [
|
|
1224 |
# ["bad_hands/15_mask.jpg"],
|
1225 |
]
|
1226 |
fix_example_kpts = [
|
1227 |
-
["bad_hands/1_kpts.png"],
|
1228 |
-
["bad_hands/3_kpts.png"],
|
1229 |
-
["bad_hands/4_kpts.png"],
|
1230 |
-
["bad_hands/5_kpts.png"],
|
1231 |
-
["bad_hands/6_kpts.png"],
|
1232 |
-
["bad_hands/7_kpts.png"],
|
1233 |
]
|
1234 |
for i in range(len(fix_example_kpts)):
|
1235 |
npy_path = fix_example_kpts[i][0].replace("_kpts.png", ".npy")
|
1236 |
-
# kpts = np.load(npy_path)
|
1237 |
-
# kpts = gr.State(kpts)
|
1238 |
fix_example_kpts[i].append(npy_path)
|
1239 |
|
1240 |
custom_css = """
|
@@ -1256,8 +1240,21 @@ custom_css = """
|
|
1256 |
#kpts_examples table tr td:nth-child(2) {
|
1257 |
display: none !important;
|
1258 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1259 |
"""
|
1260 |
-
# color: black !important;
|
1261 |
|
1262 |
_HEADER_ = '''
|
1263 |
<div style="text-align: center;">
|
@@ -1309,7 +1306,6 @@ Part of this work was done during Kefan (Arthur) Chen’s internship at Meta Rea
|
|
1309 |
with gr.Blocks(css=custom_css, theme="soft") as demo:
|
1310 |
gr.Markdown(_HEADER_)
|
1311 |
with gr.Tab("Demo 1. Malformed Hand Correction", elem_id="fix-tab"):
|
1312 |
-
# gr.Markdown("""<p style="background-color: #FFDAB9; text-align: center; font-size: 20px; font-weight: bold;">Demo 1. Malformed Hand Correction</p>""")
|
1313 |
fix_inpaint_mask = gr.State(value=None)
|
1314 |
fix_original = gr.State(value=None)
|
1315 |
fix_crop_coord = gr.State(value=None)
|
@@ -1321,6 +1317,72 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
1321 |
fix_target_cond = gr.State(value=None)
|
1322 |
fix_latent = gr.State(value=None)
|
1323 |
fix_inpaint_latent = gr.State(value=None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1324 |
with gr.Row():
|
1325 |
# crop & brush
|
1326 |
with gr.Column():
|
@@ -1418,6 +1480,9 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
1418 |
gr.Markdown(
|
1419 |
"""<p style="text-align: center; font-size: 18px; font-weight: bold;">3. Target hand pose</p>"""
|
1420 |
)
|
|
|
|
|
|
|
1421 |
fix_kp_all = gr.Image(
|
1422 |
type="numpy",
|
1423 |
# label="Keypoints",
|
@@ -1432,7 +1497,7 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
1432 |
with gr.Accordion(open=True):
|
1433 |
fix_ex_kpts = gr.Examples(
|
1434 |
fix_example_kpts,
|
1435 |
-
inputs=[fix_kp_all, fix_kpts_path],
|
1436 |
examples_per_page=20,
|
1437 |
postprocess=False,
|
1438 |
elem_id="kpts_examples"
|
@@ -1580,58 +1645,12 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
1580 |
)
|
1581 |
fix_clear = gr.ClearButton()
|
1582 |
|
1583 |
-
with gr.Accordion(label="More options", open=False):
|
1584 |
-
gr.Markdown(
|
1585 |
-
"⚠️ Currently, Number of generation > 1 could lead to out-of-memory"
|
1586 |
-
)
|
1587 |
-
with gr.Row():
|
1588 |
-
fix_n_generation = gr.Slider(
|
1589 |
-
label="Number of generations",
|
1590 |
-
value=1,
|
1591 |
-
minimum=1,
|
1592 |
-
maximum=FIX_MAX_N,
|
1593 |
-
step=1,
|
1594 |
-
randomize=False,
|
1595 |
-
interactive=True,
|
1596 |
-
)
|
1597 |
-
fix_seed = gr.Slider(
|
1598 |
-
label="Seed",
|
1599 |
-
value=42,
|
1600 |
-
minimum=0,
|
1601 |
-
maximum=10000,
|
1602 |
-
step=1,
|
1603 |
-
randomize=False,
|
1604 |
-
interactive=True,
|
1605 |
-
)
|
1606 |
-
fix_cfg = gr.Slider(
|
1607 |
-
label="Classifier free guidance scale",
|
1608 |
-
value=3.0,
|
1609 |
-
minimum=0.0,
|
1610 |
-
maximum=10.0,
|
1611 |
-
step=0.1,
|
1612 |
-
randomize=False,
|
1613 |
-
interactive=True,
|
1614 |
-
)
|
1615 |
-
fix_quality = gr.Slider(
|
1616 |
-
label="Quality",
|
1617 |
-
value=10,
|
1618 |
-
minimum=1,
|
1619 |
-
maximum=10,
|
1620 |
-
step=1,
|
1621 |
-
randomize=False,
|
1622 |
-
interactive=True,
|
1623 |
-
)
|
1624 |
|
1625 |
# listeners
|
1626 |
-
# fix_crop.change(resize_to_full, fix_crop, fix_ref)
|
1627 |
fix_crop.change(stash_original, fix_crop, fix_original) # fix_original: (real_H, real_W, 3)
|
1628 |
fix_crop.change(stay_crop, [fix_crop, fix_crop_coord], [fix_crop_coord, fix_ref])
|
1629 |
fix_crop.select(process_crop, [fix_crop, fix_crop_coord], [fix_crop_coord, fix_ref, fix_crop])
|
1630 |
-
# fix_ref.change(disable_crop, fix_crop_coord, fix_crop)
|
1631 |
-
# fix_ref.change(enable_component, [fix_crop, fix_crop], fix_ref)
|
1632 |
-
# fix_ref.change(enable_component, [fix_crop, fix_crop], fix_finish_crop)
|
1633 |
fix_ref.change(visualize_ref, [fix_ref], [fix_img, fix_inpaint_mask])
|
1634 |
-
# fix_finish_crop.click(get_mask_inpaint, [fix_ref], []) # fix_ref: (real_cropped_H, real_cropped_W, 3)
|
1635 |
fix_img.change(lambda x: x, [fix_img], [fix_kp_right])
|
1636 |
fix_img.change(lambda x: x, [fix_img], [fix_kp_left])
|
1637 |
fix_ref.change(
|
@@ -1693,9 +1712,6 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
1693 |
fix_reset_left.click(
|
1694 |
reset_kps, [fix_img, fix_kpts, gr.State("left")], [fix_kp_left, fix_kpts]
|
1695 |
)
|
1696 |
-
# fix_vis_mask32.change(
|
1697 |
-
# enable_component, [fix_vis_mask32, fix_vis_mask256], fix_run
|
1698 |
-
# )
|
1699 |
fix_kpts_path.change(read_kpts, fix_kpts_path, fix_kpts_np)
|
1700 |
fix_run.click(
|
1701 |
ready_sample,
|
@@ -1775,10 +1791,8 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
1775 |
)
|
1776 |
|
1777 |
with gr.Tab("Demo 2. Repose Hands", elem_id="repose-tab"):
|
1778 |
-
# gr.Markdown("""<p style="background-color: #90EE90; text-align: center; font-size: 20px; font-weight: bold;">Demo 2. Repose Hands</p>""")
|
1779 |
-
dump = gr.State(value=None)
|
1780 |
-
|
1781 |
# ref states
|
|
|
1782 |
ref_img = gr.State(value=None)
|
1783 |
ref_im_raw = gr.State(value=None)
|
1784 |
ref_kp_raw = gr.State(value=0)
|
@@ -1801,7 +1815,20 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
1801 |
target_auto_cond = gr.State(value=None)
|
1802 |
target_cond = gr.State(value=None)
|
1803 |
|
1804 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1805 |
with gr.Row():
|
1806 |
# ref column
|
1807 |
with gr.Column():
|
@@ -1822,10 +1849,6 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
1822 |
crop_size="1:1",
|
1823 |
)
|
1824 |
gr.Examples(example_ref_imgs, [ref], examples_per_page=20)
|
1825 |
-
# gr.Markdown(
|
1826 |
-
# """<p style="text-align: center;">② Hit the "Finish Cropping" button to get hand pose</p>"""
|
1827 |
-
# )
|
1828 |
-
# ref_finish_crop = gr.Button(value="Finish Cropping", interactive=False)
|
1829 |
with gr.Accordion(label="See hand pose and more options", open=False):
|
1830 |
with gr.Tab("Automatic hand keypoints"):
|
1831 |
ref_pose = gr.Image(
|
@@ -1944,12 +1967,6 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
1944 |
crop_size="1:1",
|
1945 |
)
|
1946 |
gr.Examples(example_target_imgs, [target], examples_per_page=20)
|
1947 |
-
# gr.Markdown(
|
1948 |
-
# """<p style="text-align: center;">② Hit the "Finish Cropping" button to get hand pose</p>"""
|
1949 |
-
# )
|
1950 |
-
# target_finish_crop = gr.Button(
|
1951 |
-
# value="Finish Cropping", interactive=False
|
1952 |
-
# )
|
1953 |
with gr.Accordion(label="See hand pose and more options", open=False):
|
1954 |
with gr.Tab("Automatic hand keypoints"):
|
1955 |
target_pose = gr.Image(
|
@@ -2084,6 +2101,7 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
2084 |
)
|
2085 |
clear = gr.ClearButton()
|
2086 |
|
|
|
2087 |
with gr.Accordion(label="More options", open=False):
|
2088 |
with gr.Row():
|
2089 |
n_generation = gr.Slider(
|
@@ -2115,7 +2133,6 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
2115 |
)
|
2116 |
|
2117 |
# reference listeners
|
2118 |
-
# ref.change(enable_component, [ref, ref], ref_finish_crop)
|
2119 |
ref.change(prepare_anno, [ref, ref_is_user], [ref_im_raw, ref_kp_raw])
|
2120 |
ref_kp_raw.change(lambda x: x, ref_im_raw, ref_manual_kp_right)
|
2121 |
ref_kp_raw.change(lambda x: x, ref_im_raw, ref_manual_kp_left)
|
@@ -2179,7 +2196,6 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
2179 |
)
|
2180 |
|
2181 |
# target listeners
|
2182 |
-
# target.change(enable_component, [target, target], target_finish_crop)
|
2183 |
target.change(prepare_anno, [target, target_is_user], [target_im_raw, target_kp_raw])
|
2184 |
target_kp_raw.change(lambda x:x, target_im_raw, target_manual_kp_right)
|
2185 |
target_kp_raw.change(lambda x:x, target_im_raw, target_manual_kp_left)
|
@@ -2249,8 +2265,6 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
2249 |
# run listerners
|
2250 |
ref_cond.change(enable_component, [ref_cond, target_cond], run)
|
2251 |
target_cond.change(enable_component, [ref_cond, target_cond], run)
|
2252 |
-
# ref_manual_pose.change(enable_component, [ref_manual_pose, target_manual_pose], run)
|
2253 |
-
# target_manual_pose.change(enable_component, [ref_manual_pose, target_manual_pose], run)
|
2254 |
run.click(
|
2255 |
sample_diff,
|
2256 |
[ref_cond, target_cond, target_keypts, n_generation, seed, cfg],
|
@@ -2322,7 +2336,7 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
2322 |
gr.Markdown(_ACK_)
|
2323 |
gr.Markdown("<h1>Trouble Shooting</h1>")
|
2324 |
gr.Markdown("If error persists, please try the following steps:<br>1. Refresh the page and try again.<br>2. The issue might be due to compatibility with HuggingFace or GPU memory limitations. We recommend cloning this repository and trying it with your own GPU if possible.<br>3. Kindly leave a message on our HuggingFace Spaces Community tab (located at the top right), on our GitHub repository's Issues page, or send us an email. We are happy to help you as soon as possible.")
|
2325 |
-
gr.Markdown("If the result is not satisfactory:<br>1. Try changing
|
2326 |
gr.Markdown("<h1>Citation</h1>")
|
2327 |
gr.Markdown(
|
2328 |
"""<p style="text-align: left;">If this was useful, please cite us! ❤️</p>"""
|
|
|
17 |
from PIL import Image
|
18 |
import random
|
19 |
from copy import deepcopy
|
|
|
|
|
20 |
from huggingface_hub import hf_hub_download
|
21 |
try:
|
22 |
import spaces
|
|
|
45 |
torch.cuda.manual_seed_all(seed)
|
46 |
random.seed(seed)
|
47 |
|
|
|
48 |
device = "cuda"
|
|
|
|
|
49 |
|
50 |
def remove_prefix(text, prefix):
|
51 |
if text.startswith(prefix):
|
|
|
482 |
img = mask_image(img, mask)
|
483 |
return img, inpaint_mask
|
484 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
485 |
def get_kps(img, keypoints, side: Literal["right", "left"], evt: gr.SelectData):
|
486 |
if keypoints is None:
|
487 |
keypoints = [[], []]
|
|
|
615 |
nvs=torch.cat([nvs, 2 * torch.ones_like(nvs)]),
|
616 |
cfg_scale=cfg,
|
617 |
)
|
618 |
+
|
619 |
+
gr.Info("The process successfully started to run. Please wait for 50s x Number of Generation.", duration=20)
|
620 |
samples, _ = diffusion.p_sample_loop(
|
621 |
model.forward_with_cfg,
|
622 |
z.shape,
|
|
|
821 |
cfg_scale=cfg_scale,
|
822 |
)
|
823 |
|
824 |
+
gr.Info("The process successfully started to run. Please wait for around 3.5 minutes.", duration=220)
|
825 |
samples, _ = diffusion.inpaint_p_sample_loop(
|
826 |
model.forward_with_cfg,
|
827 |
z.shape,
|
|
|
1210 |
# ["bad_hands/15_mask.jpg"],
|
1211 |
]
|
1212 |
fix_example_kpts = [
|
1213 |
+
["bad_hands/1_kpts.png", 3.0, 1224],
|
1214 |
+
["bad_hands/3_kpts.png", 1.0, 42],
|
1215 |
+
["bad_hands/4_kpts.png", 2.0, 42],
|
1216 |
+
["bad_hands/5_kpts.png", 3.0, 42],
|
1217 |
+
["bad_hands/6_kpts.png", 3.0, 1348],
|
1218 |
+
["bad_hands/7_kpts.png", 3.0, 42],
|
1219 |
]
|
1220 |
for i in range(len(fix_example_kpts)):
|
1221 |
npy_path = fix_example_kpts[i][0].replace("_kpts.png", ".npy")
|
|
|
|
|
1222 |
fix_example_kpts[i].append(npy_path)
|
1223 |
|
1224 |
custom_css = """
|
|
|
1240 |
#kpts_examples table tr td:nth-child(2) {
|
1241 |
display: none !important;
|
1242 |
}
|
1243 |
+
#kpts_examples table tr th:nth-child(3),
|
1244 |
+
#kpts_examples table tr td:nth-child(3) {
|
1245 |
+
display: none !important;
|
1246 |
+
}
|
1247 |
+
#kpts_examples table tr th:nth-child(4),
|
1248 |
+
#kpts_examples table tr td:nth-child(4) {
|
1249 |
+
display: none !important;
|
1250 |
+
}
|
1251 |
+
#repose_tutorial video {
|
1252 |
+
width: 70% !important;
|
1253 |
+
display: block;
|
1254 |
+
margin: 0 auto;
|
1255 |
+
padding: 0;
|
1256 |
+
}
|
1257 |
"""
|
|
|
1258 |
|
1259 |
_HEADER_ = '''
|
1260 |
<div style="text-align: center;">
|
|
|
1306 |
with gr.Blocks(css=custom_css, theme="soft") as demo:
|
1307 |
gr.Markdown(_HEADER_)
|
1308 |
with gr.Tab("Demo 1. Malformed Hand Correction", elem_id="fix-tab"):
|
|
|
1309 |
fix_inpaint_mask = gr.State(value=None)
|
1310 |
fix_original = gr.State(value=None)
|
1311 |
fix_crop_coord = gr.State(value=None)
|
|
|
1317 |
fix_target_cond = gr.State(value=None)
|
1318 |
fix_latent = gr.State(value=None)
|
1319 |
fix_inpaint_latent = gr.State(value=None)
|
1320 |
+
|
1321 |
+
# tutorial video
|
1322 |
+
with gr.Accordion():
|
1323 |
+
gr.Markdown("""<p style="text-align: center; font-size: 20px; font-weight: bold;">Tutorial Videos of Demo 1</p>""")
|
1324 |
+
with gr.Row(variant="panel"):
|
1325 |
+
with gr.Column():
|
1326 |
+
gr.Video(
|
1327 |
+
"how_to_videos/subtitled_fix_hands_custom.mp4",
|
1328 |
+
label="Using your own image",
|
1329 |
+
autoplay=True,
|
1330 |
+
loop=True,
|
1331 |
+
show_label=True,
|
1332 |
+
)
|
1333 |
+
with gr.Column():
|
1334 |
+
gr.Video(
|
1335 |
+
"how_to_videos/subtitled_fix_hands_example.mp4",
|
1336 |
+
label="Using our example image",
|
1337 |
+
autoplay=True,
|
1338 |
+
loop=True,
|
1339 |
+
show_label=True,
|
1340 |
+
)
|
1341 |
+
|
1342 |
+
# more options
|
1343 |
+
with gr.Accordion(label="More options", open=False):
|
1344 |
+
gr.Markdown(
|
1345 |
+
"⚠️ Currently, Number of generation > 1 could lead to out-of-memory"
|
1346 |
+
)
|
1347 |
+
with gr.Row():
|
1348 |
+
fix_n_generation = gr.Slider(
|
1349 |
+
label="Number of generations",
|
1350 |
+
value=1,
|
1351 |
+
minimum=1,
|
1352 |
+
maximum=FIX_MAX_N,
|
1353 |
+
step=1,
|
1354 |
+
randomize=False,
|
1355 |
+
interactive=True,
|
1356 |
+
)
|
1357 |
+
fix_seed = gr.Slider(
|
1358 |
+
label="Seed",
|
1359 |
+
value=42,
|
1360 |
+
minimum=0,
|
1361 |
+
maximum=10000,
|
1362 |
+
step=1,
|
1363 |
+
randomize=False,
|
1364 |
+
interactive=True,
|
1365 |
+
)
|
1366 |
+
fix_cfg = gr.Slider(
|
1367 |
+
label="Classifier free guidance scale",
|
1368 |
+
value=3.0,
|
1369 |
+
minimum=0.0,
|
1370 |
+
maximum=10.0,
|
1371 |
+
step=0.1,
|
1372 |
+
randomize=False,
|
1373 |
+
interactive=True,
|
1374 |
+
)
|
1375 |
+
fix_quality = gr.Slider(
|
1376 |
+
label="Quality",
|
1377 |
+
value=10,
|
1378 |
+
minimum=1,
|
1379 |
+
maximum=10,
|
1380 |
+
step=1,
|
1381 |
+
randomize=False,
|
1382 |
+
interactive=True,
|
1383 |
+
)
|
1384 |
+
|
1385 |
+
# main tabs
|
1386 |
with gr.Row():
|
1387 |
# crop & brush
|
1388 |
with gr.Column():
|
|
|
1480 |
gr.Markdown(
|
1481 |
"""<p style="text-align: center; font-size: 18px; font-weight: bold;">3. Target hand pose</p>"""
|
1482 |
)
|
1483 |
+
gr.Markdown(
|
1484 |
+
"""<p style="text-align: center;">Either get hand pose from Examples, or manually give hand pose (located at the bottom)</p>"""
|
1485 |
+
)
|
1486 |
fix_kp_all = gr.Image(
|
1487 |
type="numpy",
|
1488 |
# label="Keypoints",
|
|
|
1497 |
with gr.Accordion(open=True):
|
1498 |
fix_ex_kpts = gr.Examples(
|
1499 |
fix_example_kpts,
|
1500 |
+
inputs=[fix_kp_all, fix_cfg, fix_seed, fix_kpts_path],
|
1501 |
examples_per_page=20,
|
1502 |
postprocess=False,
|
1503 |
elem_id="kpts_examples"
|
|
|
1645 |
)
|
1646 |
fix_clear = gr.ClearButton()
|
1647 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1648 |
|
1649 |
# listeners
|
|
|
1650 |
fix_crop.change(stash_original, fix_crop, fix_original) # fix_original: (real_H, real_W, 3)
|
1651 |
fix_crop.change(stay_crop, [fix_crop, fix_crop_coord], [fix_crop_coord, fix_ref])
|
1652 |
fix_crop.select(process_crop, [fix_crop, fix_crop_coord], [fix_crop_coord, fix_ref, fix_crop])
|
|
|
|
|
|
|
1653 |
fix_ref.change(visualize_ref, [fix_ref], [fix_img, fix_inpaint_mask])
|
|
|
1654 |
fix_img.change(lambda x: x, [fix_img], [fix_kp_right])
|
1655 |
fix_img.change(lambda x: x, [fix_img], [fix_kp_left])
|
1656 |
fix_ref.change(
|
|
|
1712 |
fix_reset_left.click(
|
1713 |
reset_kps, [fix_img, fix_kpts, gr.State("left")], [fix_kp_left, fix_kpts]
|
1714 |
)
|
|
|
|
|
|
|
1715 |
fix_kpts_path.change(read_kpts, fix_kpts_path, fix_kpts_np)
|
1716 |
fix_run.click(
|
1717 |
ready_sample,
|
|
|
1791 |
)
|
1792 |
|
1793 |
with gr.Tab("Demo 2. Repose Hands", elem_id="repose-tab"):
|
|
|
|
|
|
|
1794 |
# ref states
|
1795 |
+
dump = gr.State(value=None)
|
1796 |
ref_img = gr.State(value=None)
|
1797 |
ref_im_raw = gr.State(value=None)
|
1798 |
ref_kp_raw = gr.State(value=0)
|
|
|
1815 |
target_auto_cond = gr.State(value=None)
|
1816 |
target_cond = gr.State(value=None)
|
1817 |
|
1818 |
+
# tutorial video
|
1819 |
+
with gr.Accordion(""):
|
1820 |
+
gr.Markdown("""<p style="text-align: center; font-size: 20px; font-weight: bold;">Tutorial Videos of Demo 2</p>""")
|
1821 |
+
with gr.Row(variant="panel", elem_id="repose_tutorial"):
|
1822 |
+
with gr.Column():
|
1823 |
+
gr.Video(
|
1824 |
+
"how_to_videos/subtitled_repose_hands.mp4",
|
1825 |
+
label="Tutorial",
|
1826 |
+
autoplay=True,
|
1827 |
+
loop=True,
|
1828 |
+
show_label=True,
|
1829 |
+
)
|
1830 |
+
|
1831 |
+
# main tabs
|
1832 |
with gr.Row():
|
1833 |
# ref column
|
1834 |
with gr.Column():
|
|
|
1849 |
crop_size="1:1",
|
1850 |
)
|
1851 |
gr.Examples(example_ref_imgs, [ref], examples_per_page=20)
|
|
|
|
|
|
|
|
|
1852 |
with gr.Accordion(label="See hand pose and more options", open=False):
|
1853 |
with gr.Tab("Automatic hand keypoints"):
|
1854 |
ref_pose = gr.Image(
|
|
|
1967 |
crop_size="1:1",
|
1968 |
)
|
1969 |
gr.Examples(example_target_imgs, [target], examples_per_page=20)
|
|
|
|
|
|
|
|
|
|
|
|
|
1970 |
with gr.Accordion(label="See hand pose and more options", open=False):
|
1971 |
with gr.Tab("Automatic hand keypoints"):
|
1972 |
target_pose = gr.Image(
|
|
|
2101 |
)
|
2102 |
clear = gr.ClearButton()
|
2103 |
|
2104 |
+
# more options
|
2105 |
with gr.Accordion(label="More options", open=False):
|
2106 |
with gr.Row():
|
2107 |
n_generation = gr.Slider(
|
|
|
2133 |
)
|
2134 |
|
2135 |
# reference listeners
|
|
|
2136 |
ref.change(prepare_anno, [ref, ref_is_user], [ref_im_raw, ref_kp_raw])
|
2137 |
ref_kp_raw.change(lambda x: x, ref_im_raw, ref_manual_kp_right)
|
2138 |
ref_kp_raw.change(lambda x: x, ref_im_raw, ref_manual_kp_left)
|
|
|
2196 |
)
|
2197 |
|
2198 |
# target listeners
|
|
|
2199 |
target.change(prepare_anno, [target, target_is_user], [target_im_raw, target_kp_raw])
|
2200 |
target_kp_raw.change(lambda x:x, target_im_raw, target_manual_kp_right)
|
2201 |
target_kp_raw.change(lambda x:x, target_im_raw, target_manual_kp_left)
|
|
|
2265 |
# run listerners
|
2266 |
ref_cond.change(enable_component, [ref_cond, target_cond], run)
|
2267 |
target_cond.change(enable_component, [ref_cond, target_cond], run)
|
|
|
|
|
2268 |
run.click(
|
2269 |
sample_diff,
|
2270 |
[ref_cond, target_cond, target_keypts, n_generation, seed, cfg],
|
|
|
2336 |
gr.Markdown(_ACK_)
|
2337 |
gr.Markdown("<h1>Trouble Shooting</h1>")
|
2338 |
gr.Markdown("If error persists, please try the following steps:<br>1. Refresh the page and try again.<br>2. The issue might be due to compatibility with HuggingFace or GPU memory limitations. We recommend cloning this repository and trying it with your own GPU if possible.<br>3. Kindly leave a message on our HuggingFace Spaces Community tab (located at the top right), on our GitHub repository's Issues page, or send us an email. We are happy to help you as soon as possible.")
|
2339 |
+
gr.Markdown("If the result is not satisfactory:<br>1. Try changing either <b>Classifier Free Guidance Scale</b> or <b>Seed</b>, that can be found at \"More Options\".")
|
2340 |
gr.Markdown("<h1>Citation</h1>")
|
2341 |
gr.Markdown(
|
2342 |
"""<p style="text-align: left;">If this was useful, please cite us! ❤️</p>"""
|