Spaces:
Running
Running
Update
Browse files- .pre-commit-config.yaml +2 -12
- README.md +1 -1
- app.py +103 -123
- model.py +3 -3
- requirements.txt +1 -1
.pre-commit-config.yaml
CHANGED
@@ -21,11 +21,11 @@ repos:
|
|
21 |
- id: docformatter
|
22 |
args: ['--in-place']
|
23 |
- repo: https://github.com/pycqa/isort
|
24 |
-
rev: 5.
|
25 |
hooks:
|
26 |
- id: isort
|
27 |
- repo: https://github.com/pre-commit/mirrors-mypy
|
28 |
-
rev: v0.
|
29 |
hooks:
|
30 |
- id: mypy
|
31 |
args: ['--ignore-missing-imports']
|
@@ -34,13 +34,3 @@ repos:
|
|
34 |
hooks:
|
35 |
- id: yapf
|
36 |
args: ['--parallel', '--in-place']
|
37 |
-
- repo: https://github.com/kynan/nbstripout
|
38 |
-
rev: 0.5.0
|
39 |
-
hooks:
|
40 |
-
- id: nbstripout
|
41 |
-
args: ['--extra-keys', 'metadata.interpreter metadata.kernelspec cell.metadata.pycharm']
|
42 |
-
- repo: https://github.com/nbQA-dev/nbQA
|
43 |
-
rev: 1.3.1
|
44 |
-
hooks:
|
45 |
-
- id: nbqa-isort
|
46 |
-
- id: nbqa-yapf
|
|
|
21 |
- id: docformatter
|
22 |
args: ['--in-place']
|
23 |
- repo: https://github.com/pycqa/isort
|
24 |
+
rev: 5.12.0
|
25 |
hooks:
|
26 |
- id: isort
|
27 |
- repo: https://github.com/pre-commit/mirrors-mypy
|
28 |
+
rev: v0.991
|
29 |
hooks:
|
30 |
- id: mypy
|
31 |
args: ['--ignore-missing-imports']
|
|
|
34 |
hooks:
|
35 |
- id: yapf
|
36 |
args: ['--parallel', '--in-place']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: π
|
|
4 |
colorFrom: purple
|
5 |
colorTo: gray
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
|
|
4 |
colorFrom: purple
|
5 |
colorTo: gray
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.19.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
app.py
CHANGED
@@ -2,9 +2,9 @@
|
|
2 |
|
3 |
from __future__ import annotations
|
4 |
|
5 |
-
import argparse
|
6 |
import os
|
7 |
import pathlib
|
|
|
8 |
import subprocess
|
9 |
|
10 |
import gradio as gr
|
@@ -16,7 +16,7 @@ if os.getenv('SYSTEM') == 'spaces':
|
|
16 |
mim.install('mmcv-full==1.5.2', is_yes=True)
|
17 |
|
18 |
with open('patch') as f:
|
19 |
-
subprocess.run('patch -p1'
|
20 |
|
21 |
from model import Model
|
22 |
|
@@ -27,132 +27,112 @@ You can modify sample steps and seeds. By varying seeds, you can sample differen
|
|
27 |
|
28 |
Label image generation step can be skipped. However, in that case, the input label image must be 512x256 in size and must contain only the specified colors.
|
29 |
'''
|
30 |
-
FOOTER = '<img id="visitor-badge" alt="visitor badge" src="https://visitor-badge.glitch.me/badge?page_id=hysts.text2human" />'
|
31 |
-
|
32 |
-
|
33 |
-
def parse_args() -> argparse.Namespace:
|
34 |
-
parser = argparse.ArgumentParser()
|
35 |
-
parser.add_argument('--device', type=str, default='cpu')
|
36 |
-
parser.add_argument('--theme', type=str)
|
37 |
-
parser.add_argument('--share', action='store_true')
|
38 |
-
parser.add_argument('--port', type=int)
|
39 |
-
parser.add_argument('--disable-queue',
|
40 |
-
dest='enable_queue',
|
41 |
-
action='store_false')
|
42 |
-
return parser.parse_args()
|
43 |
|
44 |
|
45 |
def set_example_image(example: list) -> dict:
|
46 |
-
return gr.
|
47 |
|
48 |
|
49 |
def set_example_text(example: list) -> dict:
|
50 |
-
return gr.
|
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 |
-
placeholder=
|
77 |
-
'''<gender>, <sleeve length>, <length of lower clothing>, <outer clothing type>, <other accessories1>, ...
|
78 |
Note: The outer clothing type and accessories can be omitted.''')
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
Note: Currently, only 5 types of textures are supported, i.e., pure color, stripe/spline, plaid/lattice, floral, denim.'''
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
)
|
155 |
-
|
156 |
-
|
157 |
-
if __name__ == '__main__':
|
158 |
-
main()
|
|
|
2 |
|
3 |
from __future__ import annotations
|
4 |
|
|
|
5 |
import os
|
6 |
import pathlib
|
7 |
+
import shlex
|
8 |
import subprocess
|
9 |
|
10 |
import gradio as gr
|
|
|
16 |
mim.install('mmcv-full==1.5.2', is_yes=True)
|
17 |
|
18 |
with open('patch') as f:
|
19 |
+
subprocess.run(shlex.split('patch -p1'), cwd='Text2Human', stdin=f)
|
20 |
|
21 |
from model import Model
|
22 |
|
|
|
27 |
|
28 |
Label image generation step can be skipped. However, in that case, the input label image must be 512x256 in size and must contain only the specified colors.
|
29 |
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
|
32 |
def set_example_image(example: list) -> dict:
|
33 |
+
return gr.update(value=example[0])
|
34 |
|
35 |
|
36 |
def set_example_text(example: list) -> dict:
|
37 |
+
return gr.update(value=example[0])
|
38 |
+
|
39 |
+
|
40 |
+
model = Model()
|
41 |
+
|
42 |
+
with gr.Blocks(css='style.css') as demo:
|
43 |
+
gr.Markdown(DESCRIPTION)
|
44 |
+
|
45 |
+
with gr.Row():
|
46 |
+
with gr.Column():
|
47 |
+
with gr.Row():
|
48 |
+
input_image = gr.Image(label='Input Pose Image',
|
49 |
+
type='pil',
|
50 |
+
elem_id='input-image')
|
51 |
+
pose_data = gr.State()
|
52 |
+
with gr.Row():
|
53 |
+
paths = sorted(pathlib.Path('pose_images').glob('*.png'))
|
54 |
+
example_images = gr.Dataset(components=[input_image],
|
55 |
+
samples=[[path.as_posix()]
|
56 |
+
for path in paths])
|
57 |
+
|
58 |
+
with gr.Row():
|
59 |
+
shape_text = gr.Textbox(
|
60 |
+
label='Shape Description',
|
61 |
+
placeholder=
|
62 |
+
'''<gender>, <sleeve length>, <length of lower clothing>, <outer clothing type>, <other accessories1>, ...
|
|
|
|
|
63 |
Note: The outer clothing type and accessories can be omitted.''')
|
64 |
+
with gr.Row():
|
65 |
+
shape_example_texts = gr.Dataset(
|
66 |
+
components=[shape_text],
|
67 |
+
samples=[['man, sleeveless T-shirt, long pants'],
|
68 |
+
['woman, short-sleeve T-shirt, short jeans']])
|
69 |
+
with gr.Row():
|
70 |
+
generate_label_button = gr.Button('Generate Label Image')
|
71 |
+
|
72 |
+
with gr.Column():
|
73 |
+
with gr.Row():
|
74 |
+
label_image = gr.Image(label='Label Image',
|
75 |
+
type='numpy',
|
76 |
+
elem_id='label-image')
|
77 |
+
|
78 |
+
with gr.Row():
|
79 |
+
texture_text = gr.Textbox(
|
80 |
+
label='Texture Description',
|
81 |
+
placeholder=
|
82 |
+
'''<upper clothing texture>, <lower clothing texture>, <outer clothing texture>
|
83 |
Note: Currently, only 5 types of textures are supported, i.e., pure color, stripe/spline, plaid/lattice, floral, denim.'''
|
84 |
+
)
|
85 |
+
with gr.Row():
|
86 |
+
texture_example_texts = gr.Dataset(components=[texture_text],
|
87 |
+
samples=[
|
88 |
+
['pure color, denim'],
|
89 |
+
['floral, stripe'],
|
90 |
+
])
|
91 |
+
with gr.Row():
|
92 |
+
sample_steps = gr.Slider(label='Sample Steps',
|
93 |
+
minimum=10,
|
94 |
+
maximum=300,
|
95 |
+
value=10,
|
96 |
+
step=10)
|
97 |
+
with gr.Row():
|
98 |
+
seed = gr.Slider(0, 1000000, value=0, step=1, label='Seed')
|
99 |
+
with gr.Row():
|
100 |
+
generate_human_button = gr.Button('Generate Human')
|
101 |
+
|
102 |
+
with gr.Column():
|
103 |
+
with gr.Row():
|
104 |
+
result = gr.Image(label='Result',
|
105 |
+
type='numpy',
|
106 |
+
elem_id='result-image')
|
107 |
+
|
108 |
+
input_image.change(fn=model.process_pose_image,
|
109 |
+
inputs=input_image,
|
110 |
+
outputs=pose_data)
|
111 |
+
generate_label_button.click(fn=model.generate_label_image,
|
112 |
+
inputs=[
|
113 |
+
pose_data,
|
114 |
+
shape_text,
|
115 |
+
],
|
116 |
+
outputs=label_image)
|
117 |
+
generate_human_button.click(fn=model.generate_human,
|
118 |
+
inputs=[
|
119 |
+
label_image,
|
120 |
+
texture_text,
|
121 |
+
sample_steps,
|
122 |
+
seed,
|
123 |
+
],
|
124 |
+
outputs=result)
|
125 |
+
example_images.click(fn=set_example_image,
|
126 |
+
inputs=example_images,
|
127 |
+
outputs=example_images.components,
|
128 |
+
queue=False)
|
129 |
+
shape_example_texts.click(fn=set_example_text,
|
130 |
+
inputs=shape_example_texts,
|
131 |
+
outputs=shape_example_texts.components,
|
132 |
+
queue=False)
|
133 |
+
texture_example_texts.click(fn=set_example_text,
|
134 |
+
inputs=texture_example_texts,
|
135 |
+
outputs=texture_example_texts.components,
|
136 |
+
queue=False)
|
137 |
+
|
138 |
+
demo.queue().launch(show_api=False)
|
|
|
|
|
|
|
|
|
|
model.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
from __future__ import annotations
|
2 |
|
3 |
-
import os
|
4 |
import pathlib
|
5 |
import sys
|
6 |
import zipfile
|
@@ -47,9 +46,10 @@ COLOR_LIST = [
|
|
47 |
|
48 |
|
49 |
class Model:
|
50 |
-
def __init__(self
|
|
|
51 |
self.config = self._load_config()
|
52 |
-
self.config['device'] = device
|
53 |
self._download_models()
|
54 |
self.model = SampleFromPoseModel(self.config)
|
55 |
self.model.batch_size = 1
|
|
|
1 |
from __future__ import annotations
|
2 |
|
|
|
3 |
import pathlib
|
4 |
import sys
|
5 |
import zipfile
|
|
|
46 |
|
47 |
|
48 |
class Model:
|
49 |
+
def __init__(self):
|
50 |
+
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
|
51 |
self.config = self._load_config()
|
52 |
+
self.config['device'] = device.type
|
53 |
self._download_models()
|
54 |
self.model = SampleFromPoseModel(self.config)
|
55 |
self.model.batch_size = 1
|
requirements.txt
CHANGED
@@ -5,7 +5,7 @@ mmsegmentation==0.24.1
|
|
5 |
numpy==1.22.3
|
6 |
openmim==0.1.5
|
7 |
Pillow==9.1.1
|
8 |
-
sentence-transformers==2.2.
|
9 |
tokenizers==0.12.1
|
10 |
torch==1.11.0
|
11 |
torchvision==0.12.0
|
|
|
5 |
numpy==1.22.3
|
6 |
openmim==0.1.5
|
7 |
Pillow==9.1.1
|
8 |
+
sentence-transformers==2.2.2
|
9 |
tokenizers==0.12.1
|
10 |
torch==1.11.0
|
11 |
torchvision==0.12.0
|