Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import textwrap
|
| 2 |
+
import subprocess
|
| 3 |
+
import shutil
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
import gradio as gr
|
| 9 |
+
from huggingface_hub import hf_hub_download
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
REPO_ID = "kbrodt/sketch2pose"
|
| 13 |
+
API_TOKEN = os.environ["sketch2pose"]
|
| 14 |
+
ASSET_DIR = Path("./assets")
|
| 15 |
+
|
| 16 |
+
filename = "models_smplx_v1_1.zip"
|
| 17 |
+
smpl_path = hf_hub_download(
|
| 18 |
+
repo_id=REPO_ID,
|
| 19 |
+
repo_type="model",
|
| 20 |
+
filename=filename,
|
| 21 |
+
use_auth_token=API_TOKEN,
|
| 22 |
+
cache_dir=ASSET_DIR,
|
| 23 |
+
)
|
| 24 |
+
if not (ASSET_DIR / filename).is_file():
|
| 25 |
+
shutil.copy(smpl_path, ASSET_DIR)
|
| 26 |
+
|
| 27 |
+
#filename = "output.zip"
|
| 28 |
+
#output_path = hf_hub_download(
|
| 29 |
+
#repo_id=REPO_ID,
|
| 30 |
+
#repo_type="dataset",
|
| 31 |
+
#filename=filename,
|
| 32 |
+
#use_auth_token=API_TOKEN,
|
| 33 |
+
#cache_dir=ASSET_DIR,
|
| 34 |
+
#)
|
| 35 |
+
#if not (ASSET_DIR / filename).is_file():
|
| 36 |
+
#shutil.copy(output_path, ASSET_DIR)
|
| 37 |
+
|
| 38 |
+
subprocess.run("bash ./scripts/download.sh".split())
|
| 39 |
+
subprocess.run("bash ./scripts/prepare.sh".split())
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
SAVE_DIR = "output"
|
| 43 |
+
CMD = textwrap.dedent("""
|
| 44 |
+
python src/pose.py
|
| 45 |
+
--save-path {}
|
| 46 |
+
--img-path {}
|
| 47 |
+
""")
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def main():
|
| 51 |
+
save_dir = Path(SAVE_DIR)
|
| 52 |
+
save_dir.mkdir(parents=True, exist_ok=True)
|
| 53 |
+
|
| 54 |
+
def pose(img_path, use_cos=True, use_angle_transf=True, use_contacts=False, use_natural=True):
|
| 55 |
+
if use_cos == False:
|
| 56 |
+
use_angle_transf = False
|
| 57 |
+
|
| 58 |
+
cmd = CMD.format(save_dir, img_path)
|
| 59 |
+
if use_cos:
|
| 60 |
+
cmd = cmd + " --use-cos"
|
| 61 |
+
if use_angle_transf:
|
| 62 |
+
cmd = cmd + " --use-angle-transf"
|
| 63 |
+
if use_contacts:
|
| 64 |
+
cmd = cmd + " --use-contacts"
|
| 65 |
+
if use_natural:
|
| 66 |
+
cmd = cmd + " --use-natural"
|
| 67 |
+
|
| 68 |
+
out_dir = (save_dir / Path(img_path).name).with_suffix("")
|
| 69 |
+
mesh_path = out_dir / "us.ply"
|
| 70 |
+
|
| 71 |
+
if not mesh_path.is_file():
|
| 72 |
+
subprocess.call(cmd.split())
|
| 73 |
+
|
| 74 |
+
return mesh_path
|
| 75 |
+
|
| 76 |
+
examples = []
|
| 77 |
+
for img_path in Path("./data/images").glob("*"):
|
| 78 |
+
examples.append([str(img_path), True, True, False, True])
|
| 79 |
+
demo = gr.Interface(
|
| 80 |
+
fn=pose,
|
| 81 |
+
inputs=[
|
| 82 |
+
gr.Image(type="filepath"),
|
| 83 |
+
gr.Checkbox(value=True),
|
| 84 |
+
gr.Checkbox(value=True),
|
| 85 |
+
gr.Checkbox(value=False, interactive=torch.cuda.is_available()),
|
| 86 |
+
gr.Checkbox(value=True),
|
| 87 |
+
],
|
| 88 |
+
outputs=gr.Model3D(),
|
| 89 |
+
examples=examples,
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
demo.launch()
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
if __name__ == "__main__":
|
| 96 |
+
main()
|