yitianlian commited on
Commit
dc08f88
1 Parent(s): d69f7a8

update requirement

Browse files
.history/app_20240515160543.py ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
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
+ from model import Model
13
+
14
+ # if os.getenv("SYSTEM") == "spaces":
15
+ # import mim
16
+
17
+ # mim.uninstall("mmcv-full", confirm_yes=True)
18
+ # mim.install("mmcv-full==1.5.2", is_yes=True)
19
+
20
+ # with open("patch") as f:
21
+ # subprocess.run("patch -p1".split(), cwd="Text2Human", stdin=f)
22
+
23
+
24
+ DESCRIPTION = """# Text2Human
25
+
26
+ - Algorthm is original from <a href="https://github.com/yumingj/Text2Human">https://github.com/yumingj/Text2Human</a> made by <a href="https://huggingface.co/spaces/hysts/Text2Human">@hysts</a>. Thanks for it's awesome work.
27
+
28
+ - 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.)
29
+
30
+ - 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.
31
+ """
32
+
33
+
34
+ def parse_args() -> argparse.Namespace:
35
+ parser = argparse.ArgumentParser()
36
+ parser.add_argument("--device", type=str, default="cpu")
37
+ parser.add_argument("--theme", type=str)
38
+ parser.add_argument("--share", action="store_true")
39
+ parser.add_argument("--port", type=int)
40
+ parser.add_argument("--disable-queue", dest="enable_queue", action="store_false")
41
+ return parser.parse_args()
42
+
43
+
44
+ # def set_example_image(example: list) -> dict:
45
+ # return gr.Image.update(value=example[0])
46
+
47
+
48
+ def set_example_image(example: list) -> dict:
49
+
50
+ return gr.update(value=example[0]["path"])
51
+
52
+
53
+ # def set_example_text(example: list) -> dict:
54
+ # return gr.Textbox.change(value=example[0])
55
+
56
+
57
+ def set_example_text(example: list) -> dict:
58
+ # Update the Textbox with the example text
59
+ return gr.update(value=example[0])
60
+
61
+
62
+ def main():
63
+ args = parse_args()
64
+ print(args.device)
65
+ model = Model(args.device)
66
+
67
+ with gr.Blocks(theme=args.theme, css="style.css") as demo:
68
+ gr.Markdown(DESCRIPTION)
69
+
70
+ with gr.Row():
71
+ with gr.Column():
72
+ with gr.Row():
73
+ input_image = gr.Image(
74
+ label="Input Pose Image", type="pil", elem_id="input-image"
75
+ )
76
+ pose_data = gr.State()
77
+ with gr.Row():
78
+ paths = sorted(pathlib.Path("pose_images").glob("*.png"))
79
+ example_images = gr.Dataset(
80
+ components=[input_image],
81
+ samples=[[path.as_posix()] for path in paths],
82
+ )
83
+
84
+ with gr.Row():
85
+ shape_text = gr.Textbox(
86
+ label="Shape Description",
87
+ placeholder="""<gender>, <sleeve length>, <length of lower clothing>, <outer clothing type>, <other accessories1>, ...
88
+ Note: The outer clothing type and accessories can be omitted.""",
89
+ )
90
+ with gr.Row():
91
+ shape_example_texts = gr.Dataset(
92
+ components=[shape_text],
93
+ samples=[
94
+ ["man, sleeveless T-shirt, long pants"],
95
+ ["woman, short-sleeve T-shirt, short jeans"],
96
+ ],
97
+ )
98
+ with gr.Row():
99
+ generate_label_button = gr.Button("Generate Label Image")
100
+
101
+ with gr.Column():
102
+ with gr.Row():
103
+ label_image = gr.Image(
104
+ label="Label Image", type="numpy", elem_id="label-image"
105
+ )
106
+
107
+ with gr.Row():
108
+ texture_text = gr.Textbox(
109
+ label="Texture Description",
110
+ placeholder="""<upper clothing texture>, <lower clothing texture>, <outer clothing texture>
111
+ Note: Currently, only 5 types of textures are supported, i.e., pure color, stripe/spline, plaid/lattice, floral, denim.""",
112
+ )
113
+ with gr.Row():
114
+ texture_example_texts = gr.Dataset(
115
+ components=[texture_text],
116
+ samples=[["pure color, denim"], ["floral, stripe"]],
117
+ )
118
+ with gr.Row():
119
+ sample_steps = gr.Slider(
120
+ 10, 300, value=10, step=10, label="Sample Steps"
121
+ )
122
+ with gr.Row():
123
+ seed = gr.Slider(0, 1000000, value=0, step=1, label="Seed")
124
+ with gr.Row():
125
+ generate_human_button = gr.Button("Generate Human")
126
+
127
+ with gr.Column():
128
+ with gr.Row():
129
+ result = gr.Image(
130
+ label="Result", type="numpy", elem_id="result-image"
131
+ )
132
+
133
+ input_image.change(
134
+ fn=model.process_pose_image, inputs=input_image, outputs=pose_data
135
+ )
136
+ generate_label_button.click(
137
+ fn=model.generate_label_image,
138
+ inputs=[
139
+ pose_data,
140
+ shape_text,
141
+ ],
142
+ outputs=label_image,
143
+ )
144
+ # generate_human_button.click(
145
+ # fn=model.generate_human,
146
+ # inputs=[
147
+ # label_image,
148
+ # texture_text,
149
+ # sample_steps,
150
+ # seed,
151
+ # ],
152
+ # outputs=result,
153
+ # )
154
+ generate_human_button.click(
155
+ fn=model.generate_human,
156
+ inputs=[
157
+ pose_data,
158
+ shape_text,
159
+ texture_text,
160
+ sample_steps,
161
+ seed,
162
+ ],
163
+ outputs=result,
164
+ )
165
+ example_images.click(
166
+ fn=set_example_image,
167
+ inputs=example_images,
168
+ outputs=example_images._components,
169
+ )
170
+ shape_example_texts.click(
171
+ fn=set_example_text,
172
+ inputs=shape_example_texts,
173
+ outputs=shape_example_texts._components,
174
+ )
175
+ texture_example_texts.click(
176
+ fn=set_example_text,
177
+ inputs=texture_example_texts,
178
+ outputs=texture_example_texts._components,
179
+ )
180
+
181
+ demo.launch(
182
+ # enable_queue=args.enable_queue,
183
+ server_port=args.port,
184
+ share=args.share,
185
+ )
186
+
187
+
188
+ if __name__ == "__main__":
189
+ main()
.history/app_20240515160548.py ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
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
+ from model import Model
13
+
14
+ # if os.getenv("SYSTEM") == "spaces":
15
+ # import mim
16
+
17
+ # mim.uninstall("mmcv-full", confirm_yes=True)
18
+ # mim.install("mmcv-full==1.5.2", is_yes=True)
19
+
20
+ # with open("patch") as f:
21
+ # subprocess.run("patch -p1".split(), cwd="Text2Human", stdin=f)
22
+
23
+
24
+ DESCRIPTION = """# Text2Human
25
+
26
+ - Algorthm is original from <a href="https://github.com/yumingj/Text2Human">https://github.com/yumingj/Text2Human</a> made by <a href="https://huggingface.co/spaces/hysts/Text2Human">@hysts</a>. Thanks for it's awesome work.
27
+
28
+ - 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.)
29
+
30
+ - 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.
31
+ """
32
+
33
+
34
+ def parse_args() -> argparse.Namespace:
35
+ parser = argparse.ArgumentParser()
36
+ parser.add_argument("--device", type=str, default="cpu")
37
+ parser.add_argument("--theme", type=str)
38
+ parser.add_argument("--share", action="store_true")
39
+ parser.add_argument("--port", type=int)
40
+ parser.add_argument("--disable-queue", dest="enable_queue", action="store_false")
41
+ return parser.parse_args()
42
+
43
+
44
+ # def set_example_image(example: list) -> dict:
45
+ # return gr.Image.update(value=example[0])
46
+
47
+
48
+ def set_example_image(example: list) -> dict:
49
+ print(example)
50
+ return gr.update(value=example[0]["path"])
51
+
52
+
53
+ # def set_example_text(example: list) -> dict:
54
+ # return gr.Textbox.change(value=example[0])
55
+
56
+
57
+ def set_example_text(example: list) -> dict:
58
+ # Update the Textbox with the example text
59
+ return gr.update(value=example[0])
60
+
61
+
62
+ def main():
63
+ args = parse_args()
64
+ print(args.device)
65
+ model = Model(args.device)
66
+
67
+ with gr.Blocks(theme=args.theme, css="style.css") as demo:
68
+ gr.Markdown(DESCRIPTION)
69
+
70
+ with gr.Row():
71
+ with gr.Column():
72
+ with gr.Row():
73
+ input_image = gr.Image(
74
+ label="Input Pose Image", type="pil", elem_id="input-image"
75
+ )
76
+ pose_data = gr.State()
77
+ with gr.Row():
78
+ paths = sorted(pathlib.Path("pose_images").glob("*.png"))
79
+ example_images = gr.Dataset(
80
+ components=[input_image],
81
+ samples=[[path.as_posix()] for path in paths],
82
+ )
83
+
84
+ with gr.Row():
85
+ shape_text = gr.Textbox(
86
+ label="Shape Description",
87
+ placeholder="""<gender>, <sleeve length>, <length of lower clothing>, <outer clothing type>, <other accessories1>, ...
88
+ Note: The outer clothing type and accessories can be omitted.""",
89
+ )
90
+ with gr.Row():
91
+ shape_example_texts = gr.Dataset(
92
+ components=[shape_text],
93
+ samples=[
94
+ ["man, sleeveless T-shirt, long pants"],
95
+ ["woman, short-sleeve T-shirt, short jeans"],
96
+ ],
97
+ )
98
+ with gr.Row():
99
+ generate_label_button = gr.Button("Generate Label Image")
100
+
101
+ with gr.Column():
102
+ with gr.Row():
103
+ label_image = gr.Image(
104
+ label="Label Image", type="numpy", elem_id="label-image"
105
+ )
106
+
107
+ with gr.Row():
108
+ texture_text = gr.Textbox(
109
+ label="Texture Description",
110
+ placeholder="""<upper clothing texture>, <lower clothing texture>, <outer clothing texture>
111
+ Note: Currently, only 5 types of textures are supported, i.e., pure color, stripe/spline, plaid/lattice, floral, denim.""",
112
+ )
113
+ with gr.Row():
114
+ texture_example_texts = gr.Dataset(
115
+ components=[texture_text],
116
+ samples=[["pure color, denim"], ["floral, stripe"]],
117
+ )
118
+ with gr.Row():
119
+ sample_steps = gr.Slider(
120
+ 10, 300, value=10, step=10, label="Sample Steps"
121
+ )
122
+ with gr.Row():
123
+ seed = gr.Slider(0, 1000000, value=0, step=1, label="Seed")
124
+ with gr.Row():
125
+ generate_human_button = gr.Button("Generate Human")
126
+
127
+ with gr.Column():
128
+ with gr.Row():
129
+ result = gr.Image(
130
+ label="Result", type="numpy", elem_id="result-image"
131
+ )
132
+
133
+ input_image.change(
134
+ fn=model.process_pose_image, inputs=input_image, outputs=pose_data
135
+ )
136
+ generate_label_button.click(
137
+ fn=model.generate_label_image,
138
+ inputs=[
139
+ pose_data,
140
+ shape_text,
141
+ ],
142
+ outputs=label_image,
143
+ )
144
+ # generate_human_button.click(
145
+ # fn=model.generate_human,
146
+ # inputs=[
147
+ # label_image,
148
+ # texture_text,
149
+ # sample_steps,
150
+ # seed,
151
+ # ],
152
+ # outputs=result,
153
+ # )
154
+ generate_human_button.click(
155
+ fn=model.generate_human,
156
+ inputs=[
157
+ pose_data,
158
+ shape_text,
159
+ texture_text,
160
+ sample_steps,
161
+ seed,
162
+ ],
163
+ outputs=result,
164
+ )
165
+ example_images.click(
166
+ fn=set_example_image,
167
+ inputs=example_images,
168
+ outputs=example_images._components,
169
+ )
170
+ shape_example_texts.click(
171
+ fn=set_example_text,
172
+ inputs=shape_example_texts,
173
+ outputs=shape_example_texts._components,
174
+ )
175
+ texture_example_texts.click(
176
+ fn=set_example_text,
177
+ inputs=texture_example_texts,
178
+ outputs=texture_example_texts._components,
179
+ )
180
+
181
+ demo.launch(
182
+ # enable_queue=args.enable_queue,
183
+ server_port=args.port,
184
+ share=args.share,
185
+ )
186
+
187
+
188
+ if __name__ == "__main__":
189
+ main()
.history/app_20240515160550.py ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
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
+ from model import Model
13
+
14
+ # if os.getenv("SYSTEM") == "spaces":
15
+ # import mim
16
+
17
+ # mim.uninstall("mmcv-full", confirm_yes=True)
18
+ # mim.install("mmcv-full==1.5.2", is_yes=True)
19
+
20
+ # with open("patch") as f:
21
+ # subprocess.run("patch -p1".split(), cwd="Text2Human", stdin=f)
22
+
23
+
24
+ DESCRIPTION = """# Text2Human
25
+
26
+ - Algorthm is original from <a href="https://github.com/yumingj/Text2Human">https://github.com/yumingj/Text2Human</a> made by <a href="https://huggingface.co/spaces/hysts/Text2Human">@hysts</a>. Thanks for it's awesome work.
27
+
28
+ - 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.)
29
+
30
+ - 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.
31
+ """
32
+
33
+
34
+ def parse_args() -> argparse.Namespace:
35
+ parser = argparse.ArgumentParser()
36
+ parser.add_argument("--device", type=str, default="cpu")
37
+ parser.add_argument("--theme", type=str)
38
+ parser.add_argument("--share", action="store_true")
39
+ parser.add_argument("--port", type=int)
40
+ parser.add_argument("--disable-queue", dest="enable_queue", action="store_false")
41
+ return parser.parse_args()
42
+
43
+
44
+ # def set_example_image(example: list) -> dict:
45
+ # return gr.Image.update(value=example[0])
46
+
47
+
48
+ def set_example_image(example: list) -> dict:
49
+ print(example)
50
+ return gr.update(value=example[0]["path"])
51
+
52
+
53
+ # def set_example_text(example: list) -> dict:
54
+ # return gr.Textbox.change(value=example[0])
55
+
56
+
57
+ def set_example_text(example: list) -> dict:
58
+ # Update the Textbox with the example text
59
+ return gr.update(value=example[0])
60
+
61
+
62
+ def main():
63
+ args = parse_args()
64
+ print(args.device)
65
+ model = Model(args.device)
66
+
67
+ with gr.Blocks(theme=args.theme, css="style.css") as demo:
68
+ gr.Markdown(DESCRIPTION)
69
+
70
+ with gr.Row():
71
+ with gr.Column():
72
+ with gr.Row():
73
+ input_image = gr.Image(
74
+ label="Input Pose Image", type="pil", elem_id="input-image"
75
+ )
76
+ pose_data = gr.State()
77
+ with gr.Row():
78
+ paths = sorted(pathlib.Path("pose_images").glob("*.png"))
79
+ example_images = gr.Dataset(
80
+ components=[input_image],
81
+ samples=[[path.as_posix()] for path in paths],
82
+ )
83
+
84
+ with gr.Row():
85
+ shape_text = gr.Textbox(
86
+ label="Shape Description",
87
+ placeholder="""<gender>, <sleeve length>, <length of lower clothing>, <outer clothing type>, <other accessories1>, ...
88
+ Note: The outer clothing type and accessories can be omitted.""",
89
+ )
90
+ with gr.Row():
91
+ shape_example_texts = gr.Dataset(
92
+ components=[shape_text],
93
+ samples=[
94
+ ["man, sleeveless T-shirt, long pants"],
95
+ ["woman, short-sleeve T-shirt, short jeans"],
96
+ ],
97
+ )
98
+ with gr.Row():
99
+ generate_label_button = gr.Button("Generate Label Image")
100
+
101
+ with gr.Column():
102
+ with gr.Row():
103
+ label_image = gr.Image(
104
+ label="Label Image", type="numpy", elem_id="label-image"
105
+ )
106
+
107
+ with gr.Row():
108
+ texture_text = gr.Textbox(
109
+ label="Texture Description",
110
+ placeholder="""<upper clothing texture>, <lower clothing texture>, <outer clothing texture>
111
+ Note: Currently, only 5 types of textures are supported, i.e., pure color, stripe/spline, plaid/lattice, floral, denim.""",
112
+ )
113
+ with gr.Row():
114
+ texture_example_texts = gr.Dataset(
115
+ components=[texture_text],
116
+ samples=[["pure color, denim"], ["floral, stripe"]],
117
+ )
118
+ with gr.Row():
119
+ sample_steps = gr.Slider(
120
+ 10, 300, value=10, step=10, label="Sample Steps"
121
+ )
122
+ with gr.Row():
123
+ seed = gr.Slider(0, 1000000, value=0, step=1, label="Seed")
124
+ with gr.Row():
125
+ generate_human_button = gr.Button("Generate Human")
126
+
127
+ with gr.Column():
128
+ with gr.Row():
129
+ result = gr.Image(
130
+ label="Result", type="numpy", elem_id="result-image"
131
+ )
132
+
133
+ input_image.change(
134
+ fn=model.process_pose_image, inputs=input_image, outputs=pose_data
135
+ )
136
+ generate_label_button.click(
137
+ fn=model.generate_label_image,
138
+ inputs=[
139
+ pose_data,
140
+ shape_text,
141
+ ],
142
+ outputs=label_image,
143
+ )
144
+ # generate_human_button.click(
145
+ # fn=model.generate_human,
146
+ # inputs=[
147
+ # label_image,
148
+ # texture_text,
149
+ # sample_steps,
150
+ # seed,
151
+ # ],
152
+ # outputs=result,
153
+ # )
154
+ generate_human_button.click(
155
+ fn=model.generate_human,
156
+ inputs=[
157
+ pose_data,
158
+ shape_text,
159
+ texture_text,
160
+ sample_steps,
161
+ seed,
162
+ ],
163
+ outputs=result,
164
+ )
165
+ example_images.click(
166
+ fn=set_example_image,
167
+ inputs=example_images,
168
+ outputs=example_images._components,
169
+ )
170
+ shape_example_texts.click(
171
+ fn=set_example_text,
172
+ inputs=shape_example_texts,
173
+ outputs=shape_example_texts._components,
174
+ )
175
+ texture_example_texts.click(
176
+ fn=set_example_text,
177
+ inputs=texture_example_texts,
178
+ outputs=texture_example_texts._components,
179
+ )
180
+
181
+ demo.launch(
182
+ # enable_queue=args.enable_queue,
183
+ server_port=args.port,
184
+ share=args.share,
185
+ )
186
+
187
+
188
+ if __name__ == "__main__":
189
+ main()
.history/app_20240515160553.py ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
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
+ from model import Model
13
+
14
+ # if os.getenv("SYSTEM") == "spaces":
15
+ # import mim
16
+
17
+ # mim.uninstall("mmcv-full", confirm_yes=True)
18
+ # mim.install("mmcv-full==1.5.2", is_yes=True)
19
+
20
+ # with open("patch") as f:
21
+ # subprocess.run("patch -p1".split(), cwd="Text2Human", stdin=f)
22
+
23
+
24
+ DESCRIPTION = """# Text2Human
25
+
26
+ - Algorthm is original from <a href="https://github.com/yumingj/Text2Human">https://github.com/yumingj/Text2Human</a> made by <a href="https://huggingface.co/spaces/hysts/Text2Human">@hysts</a>. Thanks for it's awesome work.
27
+
28
+ - 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.)
29
+
30
+ - 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.
31
+ """
32
+
33
+
34
+ def parse_args() -> argparse.Namespace:
35
+ parser = argparse.ArgumentParser()
36
+ parser.add_argument("--device", type=str, default="cpu")
37
+ parser.add_argument("--theme", type=str)
38
+ parser.add_argument("--share", action="store_true")
39
+ parser.add_argument("--port", type=int)
40
+ parser.add_argument("--disable-queue", dest="enable_queue", action="store_false")
41
+ return parser.parse_args()
42
+
43
+
44
+ # def set_example_image(example: list) -> dict:
45
+ # return gr.Image.update(value=example[0])
46
+
47
+
48
+ def set_example_image(example: list) -> dict:
49
+ print(example)
50
+ return gr.update(value=example[0])
51
+
52
+
53
+ # def set_example_text(example: list) -> dict:
54
+ # return gr.Textbox.change(value=example[0])
55
+
56
+
57
+ def set_example_text(example: list) -> dict:
58
+ # Update the Textbox with the example text
59
+ return gr.update(value=example[0])
60
+
61
+
62
+ def main():
63
+ args = parse_args()
64
+ print(args.device)
65
+ model = Model(args.device)
66
+
67
+ with gr.Blocks(theme=args.theme, css="style.css") as demo:
68
+ gr.Markdown(DESCRIPTION)
69
+
70
+ with gr.Row():
71
+ with gr.Column():
72
+ with gr.Row():
73
+ input_image = gr.Image(
74
+ label="Input Pose Image", type="pil", elem_id="input-image"
75
+ )
76
+ pose_data = gr.State()
77
+ with gr.Row():
78
+ paths = sorted(pathlib.Path("pose_images").glob("*.png"))
79
+ example_images = gr.Dataset(
80
+ components=[input_image],
81
+ samples=[[path.as_posix()] for path in paths],
82
+ )
83
+
84
+ with gr.Row():
85
+ shape_text = gr.Textbox(
86
+ label="Shape Description",
87
+ placeholder="""<gender>, <sleeve length>, <length of lower clothing>, <outer clothing type>, <other accessories1>, ...
88
+ Note: The outer clothing type and accessories can be omitted.""",
89
+ )
90
+ with gr.Row():
91
+ shape_example_texts = gr.Dataset(
92
+ components=[shape_text],
93
+ samples=[
94
+ ["man, sleeveless T-shirt, long pants"],
95
+ ["woman, short-sleeve T-shirt, short jeans"],
96
+ ],
97
+ )
98
+ with gr.Row():
99
+ generate_label_button = gr.Button("Generate Label Image")
100
+
101
+ with gr.Column():
102
+ with gr.Row():
103
+ label_image = gr.Image(
104
+ label="Label Image", type="numpy", elem_id="label-image"
105
+ )
106
+
107
+ with gr.Row():
108
+ texture_text = gr.Textbox(
109
+ label="Texture Description",
110
+ placeholder="""<upper clothing texture>, <lower clothing texture>, <outer clothing texture>
111
+ Note: Currently, only 5 types of textures are supported, i.e., pure color, stripe/spline, plaid/lattice, floral, denim.""",
112
+ )
113
+ with gr.Row():
114
+ texture_example_texts = gr.Dataset(
115
+ components=[texture_text],
116
+ samples=[["pure color, denim"], ["floral, stripe"]],
117
+ )
118
+ with gr.Row():
119
+ sample_steps = gr.Slider(
120
+ 10, 300, value=10, step=10, label="Sample Steps"
121
+ )
122
+ with gr.Row():
123
+ seed = gr.Slider(0, 1000000, value=0, step=1, label="Seed")
124
+ with gr.Row():
125
+ generate_human_button = gr.Button("Generate Human")
126
+
127
+ with gr.Column():
128
+ with gr.Row():
129
+ result = gr.Image(
130
+ label="Result", type="numpy", elem_id="result-image"
131
+ )
132
+
133
+ input_image.change(
134
+ fn=model.process_pose_image, inputs=input_image, outputs=pose_data
135
+ )
136
+ generate_label_button.click(
137
+ fn=model.generate_label_image,
138
+ inputs=[
139
+ pose_data,
140
+ shape_text,
141
+ ],
142
+ outputs=label_image,
143
+ )
144
+ # generate_human_button.click(
145
+ # fn=model.generate_human,
146
+ # inputs=[
147
+ # label_image,
148
+ # texture_text,
149
+ # sample_steps,
150
+ # seed,
151
+ # ],
152
+ # outputs=result,
153
+ # )
154
+ generate_human_button.click(
155
+ fn=model.generate_human,
156
+ inputs=[
157
+ pose_data,
158
+ shape_text,
159
+ texture_text,
160
+ sample_steps,
161
+ seed,
162
+ ],
163
+ outputs=result,
164
+ )
165
+ example_images.click(
166
+ fn=set_example_image,
167
+ inputs=example_images,
168
+ outputs=example_images._components,
169
+ )
170
+ shape_example_texts.click(
171
+ fn=set_example_text,
172
+ inputs=shape_example_texts,
173
+ outputs=shape_example_texts._components,
174
+ )
175
+ texture_example_texts.click(
176
+ fn=set_example_text,
177
+ inputs=texture_example_texts,
178
+ outputs=texture_example_texts._components,
179
+ )
180
+
181
+ demo.launch(
182
+ # enable_queue=args.enable_queue,
183
+ server_port=args.port,
184
+ share=args.share,
185
+ )
186
+
187
+
188
+ if __name__ == "__main__":
189
+ main()
app.py CHANGED
@@ -46,7 +46,8 @@ def parse_args() -> argparse.Namespace:
46
 
47
 
48
  def set_example_image(example: list) -> dict:
49
- return gr.update(value=example[0]["path"])
 
50
 
51
 
52
  # def set_example_text(example: list) -> dict:
 
46
 
47
 
48
  def set_example_image(example: list) -> dict:
49
+ print(example)
50
+ return gr.update(value=example[0])
51
 
52
 
53
  # def set_example_text(example: list) -> dict: