Spaces:
Paused
Paused
Update run/gradio_ootd.py
Browse files- run/gradio_ootd.py +29 -179
run/gradio_ootd.py
CHANGED
@@ -1,20 +1,17 @@
|
|
1 |
-
import
|
|
|
2 |
import os
|
3 |
-
from pathlib import Path
|
4 |
-
import sys
|
5 |
import torch
|
6 |
from PIL import Image, ImageOps
|
7 |
|
8 |
from utils_ootd import get_mask_location
|
9 |
-
|
10 |
-
PROJECT_ROOT = Path(__file__).absolute().parents[1].absolute()
|
11 |
-
sys.path.insert(0, str(PROJECT_ROOT))
|
12 |
-
|
13 |
from preprocess.openpose.run_openpose import OpenPose
|
14 |
from preprocess.humanparsing.run_parsing import Parsing
|
15 |
from ootd.inference_ootd_hd import OOTDiffusionHD
|
16 |
from ootd.inference_ootd_dc import OOTDiffusionDC
|
17 |
|
|
|
|
|
18 |
|
19 |
openpose_model_hd = OpenPose(0)
|
20 |
parsing_model_hd = Parsing(0)
|
@@ -24,22 +21,19 @@ openpose_model_dc = OpenPose(1)
|
|
24 |
parsing_model_dc = Parsing(1)
|
25 |
ootd_model_dc = OOTDiffusionDC(1)
|
26 |
|
27 |
-
|
28 |
category_dict = ['upperbody', 'lowerbody', 'dress']
|
29 |
category_dict_utils = ['upper_body', 'lower_body', 'dresses']
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
example_path = os.path.join(os.path.dirname(__file__), 'examples')
|
33 |
-
model_hd = os.path.join(example_path, 'model/model_1.png')
|
34 |
-
garment_hd = os.path.join(example_path, 'garment/03244_00.jpg')
|
35 |
-
model_dc = os.path.join(example_path, 'model/model_8.png')
|
36 |
-
garment_dc = os.path.join(example_path, 'garment/048554_1.jpg')
|
37 |
-
|
38 |
-
|
39 |
-
import spaces
|
40 |
-
|
41 |
-
@spaces.GPU
|
42 |
-
def process_hd(vton_img, garm_img, n_samples, n_steps, image_scale, seed):
|
43 |
model_type = 'hd'
|
44 |
category = 0 # 0:upperbody; 1:lowerbody; 2:dress
|
45 |
|
@@ -73,17 +67,26 @@ def process_hd(vton_img, garm_img, n_samples, n_steps, image_scale, seed):
|
|
73 |
seed=seed,
|
74 |
)
|
75 |
|
76 |
-
return images
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
-
@spaces.GPU
|
79 |
-
def process_dc(vton_img, garm_img, category, n_samples, n_steps, image_scale, seed):
|
80 |
model_type = 'dc'
|
81 |
if category == 'Upper-body':
|
82 |
category = 0
|
83 |
elif category == 'Lower-body':
|
84 |
category = 1
|
85 |
else:
|
86 |
-
category =2
|
87 |
|
88 |
with torch.no_grad():
|
89 |
openpose_model_dc.preprocessor.body_estimation.model.to('cuda')
|
@@ -115,160 +118,7 @@ def process_dc(vton_img, garm_img, category, n_samples, n_steps, image_scale, se
|
|
115 |
seed=seed,
|
116 |
)
|
117 |
|
118 |
-
return images
|
119 |
-
|
120 |
-
|
121 |
-
block = gr.Blocks().queue()
|
122 |
-
with block:
|
123 |
-
with gr.Row():
|
124 |
-
gr.Markdown("# OOTDiffusion Demo")
|
125 |
-
with gr.Row():
|
126 |
-
gr.Markdown("## Half-body")
|
127 |
-
with gr.Row():
|
128 |
-
gr.Markdown("***Support upper-body garments***")
|
129 |
-
with gr.Row():
|
130 |
-
with gr.Column():
|
131 |
-
vton_img = gr.Image(label="Model", sources='upload', type="filepath", height=384, value=model_hd)
|
132 |
-
example = gr.Examples(
|
133 |
-
inputs=vton_img,
|
134 |
-
examples_per_page=14,
|
135 |
-
examples=[
|
136 |
-
os.path.join(example_path, 'model/model_1.png'),
|
137 |
-
os.path.join(example_path, 'model/model_2.png'),
|
138 |
-
os.path.join(example_path, 'model/model_3.png'),
|
139 |
-
os.path.join(example_path, 'model/model_4.png'),
|
140 |
-
os.path.join(example_path, 'model/model_5.png'),
|
141 |
-
os.path.join(example_path, 'model/model_6.png'),
|
142 |
-
os.path.join(example_path, 'model/model_7.png'),
|
143 |
-
os.path.join(example_path, 'model/01008_00.jpg'),
|
144 |
-
os.path.join(example_path, 'model/07966_00.jpg'),
|
145 |
-
os.path.join(example_path, 'model/05997_00.jpg'),
|
146 |
-
os.path.join(example_path, 'model/02849_00.jpg'),
|
147 |
-
os.path.join(example_path, 'model/14627_00.jpg'),
|
148 |
-
os.path.join(example_path, 'model/09597_00.jpg'),
|
149 |
-
os.path.join(example_path, 'model/01861_00.jpg'),
|
150 |
-
])
|
151 |
-
with gr.Column():
|
152 |
-
garm_img = gr.Image(label="Garment", sources='upload', type="filepath", height=384, value=garment_hd)
|
153 |
-
example = gr.Examples(
|
154 |
-
inputs=garm_img,
|
155 |
-
examples_per_page=14,
|
156 |
-
examples=[
|
157 |
-
os.path.join(example_path, 'garment/03244_00.jpg'),
|
158 |
-
os.path.join(example_path, 'garment/00126_00.jpg'),
|
159 |
-
os.path.join(example_path, 'garment/03032_00.jpg'),
|
160 |
-
os.path.join(example_path, 'garment/06123_00.jpg'),
|
161 |
-
os.path.join(example_path, 'garment/02305_00.jpg'),
|
162 |
-
os.path.join(example_path, 'garment/00055_00.jpg'),
|
163 |
-
os.path.join(example_path, 'garment/00470_00.jpg'),
|
164 |
-
os.path.join(example_path, 'garment/02015_00.jpg'),
|
165 |
-
os.path.join(example_path, 'garment/10297_00.jpg'),
|
166 |
-
os.path.join(example_path, 'garment/07382_00.jpg'),
|
167 |
-
os.path.join(example_path, 'garment/07764_00.jpg'),
|
168 |
-
os.path.join(example_path, 'garment/00151_00.jpg'),
|
169 |
-
os.path.join(example_path, 'garment/12562_00.jpg'),
|
170 |
-
os.path.join(example_path, 'garment/04825_00.jpg'),
|
171 |
-
])
|
172 |
-
with gr.Column():
|
173 |
-
result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery", preview=True, scale=1)
|
174 |
-
with gr.Column():
|
175 |
-
run_button = gr.Button(value="Run")
|
176 |
-
n_samples = gr.Slider(label="Images", minimum=1, maximum=4, value=1, step=1)
|
177 |
-
n_steps = gr.Slider(label="Steps", minimum=20, maximum=40, value=20, step=1)
|
178 |
-
# scale = gr.Slider(label="Scale", minimum=1.0, maximum=12.0, value=5.0, step=0.1)
|
179 |
-
image_scale = gr.Slider(label="Guidance scale", minimum=1.0, maximum=5.0, value=2.0, step=0.1)
|
180 |
-
seed = gr.Slider(label="Seed", minimum=-1, maximum=2147483647, step=1, value=-1)
|
181 |
-
|
182 |
-
ips = [vton_img, garm_img, n_samples, n_steps, image_scale, seed]
|
183 |
-
run_button.click(fn=process_hd, inputs=ips, outputs=[result_gallery], api_name='generate_hc')
|
184 |
-
|
185 |
-
|
186 |
-
with gr.Row():
|
187 |
-
gr.Markdown("## Full-body")
|
188 |
-
with gr.Row():
|
189 |
-
gr.Markdown("***Support upper-body/lower-body/dresses; garment category must be paired!!!***")
|
190 |
-
with gr.Row():
|
191 |
-
with gr.Column():
|
192 |
-
vton_img_dc = gr.Image(label="Model", sources='upload', type="filepath", height=384, value=model_dc)
|
193 |
-
example = gr.Examples(
|
194 |
-
label="Examples (upper-body/lower-body)",
|
195 |
-
inputs=vton_img_dc,
|
196 |
-
examples_per_page=7,
|
197 |
-
examples=[
|
198 |
-
os.path.join(example_path, 'model/model_8.png'),
|
199 |
-
os.path.join(example_path, 'model/049447_0.jpg'),
|
200 |
-
os.path.join(example_path, 'model/049713_0.jpg'),
|
201 |
-
os.path.join(example_path, 'model/051482_0.jpg'),
|
202 |
-
os.path.join(example_path, 'model/051918_0.jpg'),
|
203 |
-
os.path.join(example_path, 'model/051962_0.jpg'),
|
204 |
-
os.path.join(example_path, 'model/049205_0.jpg'),
|
205 |
-
])
|
206 |
-
example = gr.Examples(
|
207 |
-
label="Examples (dress)",
|
208 |
-
inputs=vton_img_dc,
|
209 |
-
examples_per_page=7,
|
210 |
-
examples=[
|
211 |
-
os.path.join(example_path, 'model/model_9.png'),
|
212 |
-
os.path.join(example_path, 'model/052767_0.jpg'),
|
213 |
-
os.path.join(example_path, 'model/052472_0.jpg'),
|
214 |
-
os.path.join(example_path, 'model/053514_0.jpg'),
|
215 |
-
os.path.join(example_path, 'model/053228_0.jpg'),
|
216 |
-
os.path.join(example_path, 'model/052964_0.jpg'),
|
217 |
-
os.path.join(example_path, 'model/053700_0.jpg'),
|
218 |
-
])
|
219 |
-
with gr.Column():
|
220 |
-
garm_img_dc = gr.Image(label="Garment", sources='upload', type="filepath", height=384, value=garment_dc)
|
221 |
-
category_dc = gr.Dropdown(label="Garment category (important option!!!)", choices=["Upper-body", "Lower-body", "Dress"], value="Upper-body")
|
222 |
-
example = gr.Examples(
|
223 |
-
label="Examples (upper-body)",
|
224 |
-
inputs=garm_img_dc,
|
225 |
-
examples_per_page=7,
|
226 |
-
examples=[
|
227 |
-
os.path.join(example_path, 'garment/048554_1.jpg'),
|
228 |
-
os.path.join(example_path, 'garment/049920_1.jpg'),
|
229 |
-
os.path.join(example_path, 'garment/049965_1.jpg'),
|
230 |
-
os.path.join(example_path, 'garment/049949_1.jpg'),
|
231 |
-
os.path.join(example_path, 'garment/050181_1.jpg'),
|
232 |
-
os.path.join(example_path, 'garment/049805_1.jpg'),
|
233 |
-
os.path.join(example_path, 'garment/050105_1.jpg'),
|
234 |
-
])
|
235 |
-
example = gr.Examples(
|
236 |
-
label="Examples (lower-body)",
|
237 |
-
inputs=garm_img_dc,
|
238 |
-
examples_per_page=7,
|
239 |
-
examples=[
|
240 |
-
os.path.join(example_path, 'garment/051827_1.jpg'),
|
241 |
-
os.path.join(example_path, 'garment/051946_1.jpg'),
|
242 |
-
os.path.join(example_path, 'garment/051473_1.jpg'),
|
243 |
-
os.path.join(example_path, 'garment/051515_1.jpg'),
|
244 |
-
os.path.join(example_path, 'garment/051517_1.jpg'),
|
245 |
-
os.path.join(example_path, 'garment/051988_1.jpg'),
|
246 |
-
os.path.join(example_path, 'garment/051412_1.jpg'),
|
247 |
-
])
|
248 |
-
example = gr.Examples(
|
249 |
-
label="Examples (dress)",
|
250 |
-
inputs=garm_img_dc,
|
251 |
-
examples_per_page=7,
|
252 |
-
examples=[
|
253 |
-
os.path.join(example_path, 'garment/053290_1.jpg'),
|
254 |
-
os.path.join(example_path, 'garment/053744_1.jpg'),
|
255 |
-
os.path.join(example_path, 'garment/053742_1.jpg'),
|
256 |
-
os.path.join(example_path, 'garment/053786_1.jpg'),
|
257 |
-
os.path.join(example_path, 'garment/053790_1.jpg'),
|
258 |
-
os.path.join(example_path, 'garment/053319_1.jpg'),
|
259 |
-
os.path.join(example_path, 'garment/052234_1.jpg'),
|
260 |
-
])
|
261 |
-
with gr.Column():
|
262 |
-
result_gallery_dc = gr.Gallery(label='Output', show_label=False, elem_id="gallery", preview=True, scale=1)
|
263 |
-
with gr.Column():
|
264 |
-
run_button_dc = gr.Button(value="Run")
|
265 |
-
n_samples_dc = gr.Slider(label="Images", minimum=1, maximum=4, value=1, step=1)
|
266 |
-
n_steps_dc = gr.Slider(label="Steps", minimum=20, maximum=40, value=20, step=1)
|
267 |
-
# scale_dc = gr.Slider(label="Scale", minimum=1.0, maximum=12.0, value=5.0, step=0.1)
|
268 |
-
image_scale_dc = gr.Slider(label="Guidance scale", minimum=1.0, maximum=5.0, value=2.0, step=0.1)
|
269 |
-
seed_dc = gr.Slider(label="Seed", minimum=-1, maximum=2147483647, step=1, value=-1)
|
270 |
-
|
271 |
-
ips_dc = [vton_img_dc, garm_img_dc, category_dc, n_samples_dc, n_steps_dc, image_scale_dc, seed_dc]
|
272 |
-
run_button_dc.click(fn=process_dc, inputs=ips_dc, outputs=[result_gallery_dc] , api_name='generate_dc')
|
273 |
|
274 |
-
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
from flask_ngrok import run_with_ngrok
|
3 |
import os
|
|
|
|
|
4 |
import torch
|
5 |
from PIL import Image, ImageOps
|
6 |
|
7 |
from utils_ootd import get_mask_location
|
|
|
|
|
|
|
|
|
8 |
from preprocess.openpose.run_openpose import OpenPose
|
9 |
from preprocess.humanparsing.run_parsing import Parsing
|
10 |
from ootd.inference_ootd_hd import OOTDiffusionHD
|
11 |
from ootd.inference_ootd_dc import OOTDiffusionDC
|
12 |
|
13 |
+
app = Flask(__name__)
|
14 |
+
run_with_ngrok(app) # Utilisé pour exposer l'API via ngrok, retirez cette ligne si vous ne l'utilisez pas
|
15 |
|
16 |
openpose_model_hd = OpenPose(0)
|
17 |
parsing_model_hd = Parsing(0)
|
|
|
21 |
parsing_model_dc = Parsing(1)
|
22 |
ootd_model_dc = OOTDiffusionDC(1)
|
23 |
|
|
|
24 |
category_dict = ['upperbody', 'lowerbody', 'dress']
|
25 |
category_dict_utils = ['upper_body', 'lower_body', 'dresses']
|
26 |
|
27 |
+
@app.route("/process_hd", methods=["POST"])
|
28 |
+
def process_hd():
|
29 |
+
data = request.files
|
30 |
+
vton_img = data['vton_img']
|
31 |
+
garm_img = data['garm_img']
|
32 |
+
n_samples = int(request.form['n_samples'])
|
33 |
+
n_steps = int(request.form['n_steps'])
|
34 |
+
image_scale = float(request.form['image_scale'])
|
35 |
+
seed = int(request.form['seed'])
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
model_type = 'hd'
|
38 |
category = 0 # 0:upperbody; 1:lowerbody; 2:dress
|
39 |
|
|
|
67 |
seed=seed,
|
68 |
)
|
69 |
|
70 |
+
return jsonify(result=images)
|
71 |
+
|
72 |
+
@app.route("/process_dc", methods=["POST"])
|
73 |
+
def process_dc():
|
74 |
+
data = request.files
|
75 |
+
vton_img = data['vton_img']
|
76 |
+
garm_img = data['garm_img']
|
77 |
+
category = request.form['category']
|
78 |
+
n_samples = int(request.form['n_samples'])
|
79 |
+
n_steps = int(request.form['n_steps'])
|
80 |
+
image_scale = float(request.form['image_scale'])
|
81 |
+
seed = int(request.form['seed'])
|
82 |
|
|
|
|
|
83 |
model_type = 'dc'
|
84 |
if category == 'Upper-body':
|
85 |
category = 0
|
86 |
elif category == 'Lower-body':
|
87 |
category = 1
|
88 |
else:
|
89 |
+
category = 2
|
90 |
|
91 |
with torch.no_grad():
|
92 |
openpose_model_dc.preprocessor.body_estimation.model.to('cuda')
|
|
|
118 |
seed=seed,
|
119 |
)
|
120 |
|
121 |
+
return jsonify(result=images)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
+
if __name__ == "__main__":
|
124 |
+
app.run(host="0.0.0.0", port=7860)
|