Spaces:
Running
Running
update pose images
#8
by
yumingj
- opened
- .pre-commit-config.yaml +12 -2
- README.md +1 -2
- app.py +125 -107
- model.py +7 -5
- pose_images/001.png +2 -2
- pose_images/002.png +2 -2
- pose_images/003.png +2 -2
- pose_images/004.png +2 -2
- pose_images/005.png +2 -2
- requirements.txt +6 -6
.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,3 +34,13 @@ repos:
|
|
34 |
hooks:
|
35 |
- id: yapf
|
36 |
args: ['--parallel', '--in-place']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
- id: docformatter
|
22 |
args: ['--in-place']
|
23 |
- repo: https://github.com/pycqa/isort
|
24 |
+
rev: 5.10.1
|
25 |
hooks:
|
26 |
- id: isort
|
27 |
- repo: https://github.com/pre-commit/mirrors-mypy
|
28 |
+
rev: v0.812
|
29 |
hooks:
|
30 |
- id: mypy
|
31 |
args: ['--ignore-missing-imports']
|
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
|
README.md
CHANGED
@@ -4,10 +4,9 @@ emoji: 🏃
|
|
4 |
colorFrom: purple
|
5 |
colorTo: gray
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
suggested_hardware: t4-small
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
|
4 |
colorFrom: purple
|
5 |
colorTo: gray
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.0.17
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
|
app.py
CHANGED
@@ -2,14 +2,12 @@
|
|
2 |
|
3 |
from __future__ import annotations
|
4 |
|
|
|
5 |
import os
|
6 |
import pathlib
|
7 |
-
import random
|
8 |
-
import shlex
|
9 |
import subprocess
|
10 |
|
11 |
import gradio as gr
|
12 |
-
import numpy as np
|
13 |
|
14 |
if os.getenv('SYSTEM') == 'spaces':
|
15 |
import mim
|
@@ -18,123 +16,143 @@ if os.getenv('SYSTEM') == 'spaces':
|
|
18 |
mim.install('mmcv-full==1.5.2', is_yes=True)
|
19 |
|
20 |
with open('patch') as f:
|
21 |
-
subprocess.run(
|
22 |
|
23 |
from model import Model
|
24 |
|
25 |
-
DESCRIPTION = '''#
|
26 |
|
|
|
27 |
You can modify sample steps and seeds. By varying seeds, you can sample different human images under the same pose, shape description, and texture description. The larger the sample steps, the better quality of the generated images. (The default value of sample steps is 256 in the original repo.)
|
28 |
|
29 |
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.
|
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 |
Note: The outer clothing type and accessories can be omitted.''')
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
Note: Currently, only 5 types of textures are supported, i.e., pure color, stripe/spline, plaid/lattice, floral, denim.'''
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
)
|
119 |
-
generate_label_button.click(
|
120 |
-
fn=model.generate_label_image,
|
121 |
-
inputs=[
|
122 |
-
pose_data,
|
123 |
-
shape_text,
|
124 |
-
],
|
125 |
-
outputs=label_image,
|
126 |
-
)
|
127 |
-
generate_human_button.click(fn=randomize_seed_fn,
|
128 |
-
inputs=[seed, randomize_seed],
|
129 |
-
outputs=seed,
|
130 |
-
queue=False).then(
|
131 |
-
fn=model.generate_human,
|
132 |
inputs=[
|
133 |
label_image,
|
134 |
texture_text,
|
135 |
sample_steps,
|
136 |
seed,
|
137 |
],
|
138 |
-
outputs=result
|
139 |
-
|
140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
11 |
|
12 |
if os.getenv('SYSTEM') == 'spaces':
|
13 |
import mim
|
16 |
mim.install('mmcv-full==1.5.2', is_yes=True)
|
17 |
|
18 |
with open('patch') as f:
|
19 |
+
subprocess.run('patch -p1'.split(), cwd='Text2Human', stdin=f)
|
20 |
|
21 |
from model import Model
|
22 |
|
23 |
+
DESCRIPTION = '''# Text2Human
|
24 |
|
25 |
+
This is an unofficial demo for <a href="https://github.com/yumingj/Text2Human">https://github.com/yumingj/Text2Human</a>.
|
26 |
You can modify sample steps and seeds. By varying seeds, you can sample different human images under the same pose, shape description, and texture description. The larger the sample steps, the better quality of the generated images. (The default value of sample steps is 256 in the original repo.)
|
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.Image.update(value=example[0])
|
47 |
+
|
48 |
+
|
49 |
+
def set_example_text(example: list) -> dict:
|
50 |
+
return gr.Textbox.update(value=example[0])
|
51 |
+
|
52 |
+
|
53 |
+
def main():
|
54 |
+
args = parse_args()
|
55 |
+
model = Model(args.device)
|
56 |
+
|
57 |
+
with gr.Blocks(theme=args.theme, css='style.css') as demo:
|
58 |
+
gr.Markdown(DESCRIPTION)
|
59 |
+
|
60 |
+
with gr.Row():
|
61 |
+
with gr.Column():
|
62 |
+
with gr.Row():
|
63 |
+
input_image = gr.Image(label='Input Pose Image',
|
64 |
+
type='pil',
|
65 |
+
elem_id='input-image')
|
66 |
+
pose_data = gr.Variable()
|
67 |
+
with gr.Row():
|
68 |
+
paths = sorted(pathlib.Path('pose_images').glob('*.png'))
|
69 |
+
example_images = gr.Dataset(components=[input_image],
|
70 |
+
samples=[[path.as_posix()]
|
71 |
+
for path in paths])
|
72 |
+
|
73 |
+
with gr.Row():
|
74 |
+
shape_text = gr.Textbox(
|
75 |
+
label='Shape Description',
|
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 |
+
with gr.Row():
|
80 |
+
shape_example_texts = gr.Dataset(
|
81 |
+
components=[shape_text],
|
82 |
+
samples=[['man, sleeveless T-shirt, long pants'],
|
83 |
+
['woman, short-sleeve T-shirt, short jeans']])
|
84 |
+
with gr.Row():
|
85 |
+
generate_label_button = gr.Button('Generate Label Image')
|
86 |
+
|
87 |
+
with gr.Column():
|
88 |
+
with gr.Row():
|
89 |
+
label_image = gr.Image(label='Label Image',
|
90 |
+
type='numpy',
|
91 |
+
elem_id='label-image')
|
92 |
+
|
93 |
+
with gr.Row():
|
94 |
+
texture_text = gr.Textbox(
|
95 |
+
label='Texture Description',
|
96 |
+
placeholder=
|
97 |
+
'''<upper clothing texture>, <lower clothing texture>, <outer clothing texture>
|
98 |
Note: Currently, only 5 types of textures are supported, i.e., pure color, stripe/spline, plaid/lattice, floral, denim.'''
|
99 |
+
)
|
100 |
+
with gr.Row():
|
101 |
+
texture_example_texts = gr.Dataset(
|
102 |
+
components=[texture_text],
|
103 |
+
samples=[['pure color, denim'], ['floral, stripe']])
|
104 |
+
with gr.Row():
|
105 |
+
sample_steps = gr.Slider(10,
|
106 |
+
300,
|
107 |
+
value=10,
|
108 |
+
step=10,
|
109 |
+
label='Sample Steps')
|
110 |
+
with gr.Row():
|
111 |
+
seed = gr.Slider(0, 1000000, value=0, step=1, label='Seed')
|
112 |
+
with gr.Row():
|
113 |
+
generate_human_button = gr.Button('Generate Human')
|
114 |
+
|
115 |
+
with gr.Column():
|
116 |
+
with gr.Row():
|
117 |
+
result = gr.Image(label='Result',
|
118 |
+
type='numpy',
|
119 |
+
elem_id='result-image')
|
120 |
+
|
121 |
+
gr.Markdown(FOOTER)
|
122 |
+
|
123 |
+
input_image.change(fn=model.process_pose_image,
|
124 |
+
inputs=input_image,
|
125 |
+
outputs=pose_data)
|
126 |
+
generate_label_button.click(fn=model.generate_label_image,
|
127 |
+
inputs=[
|
128 |
+
pose_data,
|
129 |
+
shape_text,
|
130 |
+
],
|
131 |
+
outputs=label_image)
|
132 |
+
generate_human_button.click(fn=model.generate_human,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
inputs=[
|
134 |
label_image,
|
135 |
texture_text,
|
136 |
sample_steps,
|
137 |
seed,
|
138 |
],
|
139 |
+
outputs=result)
|
140 |
+
example_images.click(fn=set_example_image,
|
141 |
+
inputs=example_images,
|
142 |
+
outputs=example_images.components)
|
143 |
+
shape_example_texts.click(fn=set_example_text,
|
144 |
+
inputs=shape_example_texts,
|
145 |
+
outputs=shape_example_texts.components)
|
146 |
+
texture_example_texts.click(fn=set_example_text,
|
147 |
+
inputs=texture_example_texts,
|
148 |
+
outputs=texture_example_texts.components)
|
149 |
+
|
150 |
+
demo.launch(
|
151 |
+
enable_queue=args.enable_queue,
|
152 |
+
server_port=args.port,
|
153 |
+
share=args.share,
|
154 |
+
)
|
155 |
+
|
156 |
+
|
157 |
+
if __name__ == '__main__':
|
158 |
+
main()
|
model.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
from __future__ import annotations
|
2 |
|
|
|
3 |
import pathlib
|
4 |
import sys
|
5 |
import zipfile
|
@@ -46,10 +47,9 @@ COLOR_LIST = [
|
|
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
|
53 |
self._download_models()
|
54 |
self.model = SampleFromPoseModel(self.config)
|
55 |
self.model.batch_size = 1
|
@@ -64,8 +64,10 @@ class Model:
|
|
64 |
model_dir = pathlib.Path('pretrained_models')
|
65 |
if model_dir.exists():
|
66 |
return
|
67 |
-
|
68 |
-
|
|
|
|
|
69 |
model_dir.mkdir()
|
70 |
with zipfile.ZipFile(path) as f:
|
71 |
f.extractall(model_dir)
|
1 |
from __future__ import annotations
|
2 |
|
3 |
+
import os
|
4 |
import pathlib
|
5 |
import sys
|
6 |
import zipfile
|
47 |
|
48 |
|
49 |
class Model:
|
50 |
+
def __init__(self, device: str):
|
|
|
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
|
64 |
model_dir = pathlib.Path('pretrained_models')
|
65 |
if model_dir.exists():
|
66 |
return
|
67 |
+
token = os.getenv('HF_TOKEN')
|
68 |
+
path = huggingface_hub.hf_hub_download('hysts/Text2Human',
|
69 |
+
'orig/pretrained_models.zip',
|
70 |
+
use_auth_token=token)
|
71 |
model_dir.mkdir()
|
72 |
with zipfile.ZipFile(path) as f:
|
73 |
f.extractall(model_dir)
|
pose_images/001.png
CHANGED
Git LFS Details
|
Git LFS Details
|
pose_images/002.png
CHANGED
Git LFS Details
|
Git LFS Details
|
pose_images/003.png
CHANGED
Git LFS Details
|
Git LFS Details
|
pose_images/004.png
CHANGED
Git LFS Details
|
Git LFS Details
|
pose_images/005.png
CHANGED
Git LFS Details
|
Git LFS Details
|
requirements.txt
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
-
einops==0.
|
2 |
lpips==0.1.4
|
3 |
mmcv-full==1.5.2
|
4 |
mmsegmentation==0.24.1
|
5 |
-
numpy==1.
|
6 |
openmim==0.1.5
|
7 |
-
Pillow==9.
|
8 |
-
sentence-transformers==2.2.
|
9 |
-
tokenizers==0.
|
10 |
torch==1.11.0
|
11 |
torchvision==0.12.0
|
12 |
-
transformers==4.
|
1 |
+
einops==0.4.1
|
2 |
lpips==0.1.4
|
3 |
mmcv-full==1.5.2
|
4 |
mmsegmentation==0.24.1
|
5 |
+
numpy==1.22.3
|
6 |
openmim==0.1.5
|
7 |
+
Pillow==9.1.1
|
8 |
+
sentence-transformers==2.2.0
|
9 |
+
tokenizers==0.12.1
|
10 |
torch==1.11.0
|
11 |
torchvision==0.12.0
|
12 |
+
transformers==4.19.2
|