Update app.py
Browse files
app.py
CHANGED
@@ -162,7 +162,16 @@ def submit_function(
|
|
162 |
# Xử lý mặt nạ (mask)
|
163 |
person_image,
|
164 |
mask = person_image["background"], # Lấy ảnh người từ lớp nền.
|
165 |
-
person_image["layers"][0] # Lấy mặt nạ do người dùng vẽ (nếu có).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
mask = Image.open(mask).convert("L") # Chuyển mặt nạ thành ảnh thang độ xám
|
167 |
if len(np.unique(np.array(mask))) == 1: # Nếu mặt nạ chỉ chứa một giá trị (ví dụ: toàn đen hoặc toàn trắng), thì không sử dụng mặt nạ (mask = None).
|
168 |
mask = None
|
@@ -251,9 +260,10 @@ HEADER = ""
|
|
251 |
def app_gradio():
|
252 |
with gr.Blocks(title="CatVTON") as demo:
|
253 |
gr.Markdown(HEADER)
|
254 |
-
with gr.Tab("Mask-based
|
255 |
with gr.Row():
|
256 |
with gr.Column(scale=1, min_width=350):
|
|
|
257 |
with gr.Row():
|
258 |
image_path = gr.Image(
|
259 |
type="filepath",
|
@@ -264,6 +274,7 @@ def app_gradio():
|
|
264 |
interactive=True, label="Person Image", type="filepath"
|
265 |
)
|
266 |
|
|
|
267 |
with gr.Row():
|
268 |
with gr.Column(scale=1, min_width=230):
|
269 |
cloth_image = gr.Image(
|
@@ -279,12 +290,13 @@ def app_gradio():
|
|
279 |
value="upper",
|
280 |
)
|
281 |
|
282 |
-
|
283 |
submit = gr.Button("Submit")
|
284 |
gr.Markdown(
|
285 |
'<center><span style="color: #FF0000">!!! Click only Once, Wait for Delay !!!</span></center>'
|
286 |
)
|
287 |
|
|
|
288 |
gr.Markdown(
|
289 |
'<span style="color: #808080; font-size: small;">Advanced options can adjust details:<br>1. `Inference Step` may enhance details;<br>2. `CFG` is highly correlated with saturation;<br>3. `Random seed` may improve pseudo-shadow.</span>'
|
290 |
)
|
@@ -306,7 +318,9 @@ def app_gradio():
|
|
306 |
value="input & mask & result",
|
307 |
)
|
308 |
|
|
|
309 |
with gr.Column(scale=2, min_width=500):
|
|
|
310 |
result_image = gr.Image(interactive=False, label="Result")
|
311 |
with gr.Row():
|
312 |
# Photo Examples
|
@@ -369,6 +383,7 @@ def app_gradio():
|
|
369 |
person_example_fn, inputs=image_path, outputs=person_image
|
370 |
)
|
371 |
|
|
|
372 |
submit.click(
|
373 |
submit_function,
|
374 |
[
|
@@ -382,8 +397,9 @@ def app_gradio():
|
|
382 |
],
|
383 |
result_image,
|
384 |
)
|
385 |
-
|
386 |
demo.queue().launch(share=True, show_error=True)
|
|
|
387 |
|
388 |
|
389 |
if __name__ == "__main__":
|
|
|
162 |
# Xử lý mặt nạ (mask)
|
163 |
person_image,
|
164 |
mask = person_image["background"], # Lấy ảnh người từ lớp nền.
|
165 |
+
#person_image["layers"][0] # Lấy mặt nạ do người dùng vẽ (nếu có).
|
166 |
+
if len(person_image["layers"]) > 0:
|
167 |
+
# Nếu danh sách không rỗng, lấy phần tử đầu tiên
|
168 |
+
layer = person_image["layers"][0]
|
169 |
+
else:
|
170 |
+
# Nếu danh sách rỗng, thực hiện hành động thay thế hoặc thông báo lỗi
|
171 |
+
layer = None
|
172 |
+
print("Không có layers trong person_image.")
|
173 |
+
|
174 |
+
|
175 |
mask = Image.open(mask).convert("L") # Chuyển mặt nạ thành ảnh thang độ xám
|
176 |
if len(np.unique(np.array(mask))) == 1: # Nếu mặt nạ chỉ chứa một giá trị (ví dụ: toàn đen hoặc toàn trắng), thì không sử dụng mặt nạ (mask = None).
|
177 |
mask = None
|
|
|
260 |
def app_gradio():
|
261 |
with gr.Blocks(title="CatVTON") as demo:
|
262 |
gr.Markdown(HEADER)
|
263 |
+
with gr.Tab("Mask-based"):
|
264 |
with gr.Row():
|
265 |
with gr.Column(scale=1, min_width=350):
|
266 |
+
# Ảnh model (người)
|
267 |
with gr.Row():
|
268 |
image_path = gr.Image(
|
269 |
type="filepath",
|
|
|
274 |
interactive=True, label="Person Image", type="filepath"
|
275 |
)
|
276 |
|
277 |
+
# Ảnh quần áo
|
278 |
with gr.Row():
|
279 |
with gr.Column(scale=1, min_width=230):
|
280 |
cloth_image = gr.Image(
|
|
|
290 |
value="upper",
|
291 |
)
|
292 |
|
293 |
+
# Submit button - Run
|
294 |
submit = gr.Button("Submit")
|
295 |
gr.Markdown(
|
296 |
'<center><span style="color: #FF0000">!!! Click only Once, Wait for Delay !!!</span></center>'
|
297 |
)
|
298 |
|
299 |
+
# Advance setting
|
300 |
gr.Markdown(
|
301 |
'<span style="color: #808080; font-size: small;">Advanced options can adjust details:<br>1. `Inference Step` may enhance details;<br>2. `CFG` is highly correlated with saturation;<br>3. `Random seed` may improve pseudo-shadow.</span>'
|
302 |
)
|
|
|
318 |
value="input & mask & result",
|
319 |
)
|
320 |
|
321 |
+
|
322 |
with gr.Column(scale=2, min_width=500):
|
323 |
+
# Result image
|
324 |
result_image = gr.Image(interactive=False, label="Result")
|
325 |
with gr.Row():
|
326 |
# Photo Examples
|
|
|
383 |
person_example_fn, inputs=image_path, outputs=person_image
|
384 |
)
|
385 |
|
386 |
+
# Function khi ấn nút submit
|
387 |
submit.click(
|
388 |
submit_function,
|
389 |
[
|
|
|
397 |
],
|
398 |
result_image,
|
399 |
)
|
400 |
+
|
401 |
demo.queue().launch(share=True, show_error=True)
|
402 |
+
#demo.queue().launch()
|
403 |
|
404 |
|
405 |
if __name__ == "__main__":
|