File size: 3,649 Bytes
523c2b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f78b608
523c2b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46f62ad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# install


import glob
import gradio as gr
import os
import numpy as np

import subprocess

if os.getenv('SYSTEM') == 'spaces':
    subprocess.run('pip install pyembree'.split())
    subprocess.run(
        'pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html'.split())
    subprocess.run(
        'pip install https://download.is.tue.mpg.de/icon/HF/kaolin-0.11.0-cp38-cp38-linux_x86_64.whl'.split())
    subprocess.run(
        'pip install https://download.is.tue.mpg.de/icon/HF/pytorch3d-0.7.0-cp38-cp38-linux_x86_64.whl'.split())
    subprocess.run(
        'pip install git+https://github.com/YuliangXiu/neural_voxelization_layer.git'.split())

from apps.infer import generate_model

# running

description = ''''''


def generate_image(seed, psi):
    iface = gr.Interface.load("spaces/hysts/StyleGAN-Human")
    img = iface(seed, psi)
    return img


model_types = ['ICON', 'PIFu', 'PaMIR']
examples_names = glob.glob('examples/*.png')
examples_types = np.random.choice(
    model_types, len(examples_names), p=[0.6, 0.2, 0.2])

examples = [list(item) for item in zip(examples_names, examples_types)]

with gr.Blocks() as demo:
    gr.Markdown(description)

    out_lst = []
    with gr.Row():
        with gr.Column():
            with gr.Row():
                with gr.Column():
                    seed = gr.inputs.Slider(
                        0, 1000, step=1, default=0, label='Seed (For Image Generation)')
                    psi = gr.inputs.Slider(
                        0, 2, step=0.05, default=0.7, label='Truncation psi (For Image Generation)')
                    radio_choice = gr.Radio(
                        model_types, label='Method (For Reconstruction)', value='icon-filter')
                inp = gr.Image(type="filepath", label="Input Image")
            with gr.Row():
                btn_sample = gr.Button("Generate Image")
                btn_submit = gr.Button("Submit Image")

            gr.Examples(examples=examples,
                        inputs=[inp, radio_choice],
                        cache_examples=False,
                        fn=generate_model,
                        outputs=out_lst)

            out_vid = gr.Video(
                label="Image + Normal + SMPL Body + Clothed Human")
            out_vid_download = gr.File(
                label="Download Video, welcome share on Twitter with #ICON")

        with gr.Column():
            overlap_inp = gr.Image(
                type="filepath", label="Image Normal Overlap")
            out_final = gr.Model3D(
                clear_color=[0.0, 0.0, 0.0, 0.0],  label="Clothed human")
            out_final_download = gr.File(
                label="Download clothed human mesh")
            out_smpl = gr.Model3D(
                clear_color=[0.0, 0.0, 0.0, 0.0],  label="SMPL body")
            out_smpl_download = gr.File(label="Download SMPL body mesh")
            out_smpl_npy_download = gr.File(label="Download SMPL params")

    out_lst = [out_smpl, out_smpl_download, out_smpl_npy_download,
               out_final, out_final_download, out_vid, out_vid_download, overlap_inp]

    btn_submit.click(fn=generate_model, inputs=[
                     inp, radio_choice], outputs=out_lst)
    btn_sample.click(fn=generate_image, inputs=[seed, psi], outputs=inp)

if __name__ == "__main__":

    # demo.launch(debug=False, enable_queue=False,
    #             auth=(os.environ['USER'], os.environ['PASSWORD']),
    #             auth_message="Register at icon.is.tue.mpg.de to get HuggingFace username and password.")

    demo.launch(debug=True, enable_queue=True)