Update app.py
Browse files
app.py
CHANGED
@@ -217,48 +217,55 @@ def start_tryon(
|
|
217 |
# 最初にマスク画像を一度だけ出力
|
218 |
yield output_images.value, mask_gray
|
219 |
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
|
|
225 |
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
|
263 |
# 最終的な結果を返す
|
264 |
return output_images.value, mask_gray
|
@@ -316,7 +323,9 @@ with image_blocks as demo:
|
|
316 |
label="Masked image output", elem_id="masked-img", show_share_button=False
|
317 |
)
|
318 |
with gr.Column():
|
319 |
-
image_gallery = gr.Gallery(
|
|
|
|
|
320 |
|
321 |
with gr.Column():
|
322 |
try_button = gr.Button(value="Try-on")
|
@@ -327,7 +336,7 @@ with image_blocks as demo:
|
|
327 |
)
|
328 |
seed = gr.Number(label="Seed", minimum=-1, maximum=2147483647, step=1, value=42)
|
329 |
num_images = gr.Slider(
|
330 |
-
label="Number of Images", minimum=1, maximum=10, step=1, value=1
|
331 |
)
|
332 |
|
333 |
try_button.click(
|
@@ -346,4 +355,4 @@ with image_blocks as demo:
|
|
346 |
api_name='tryon',
|
347 |
)
|
348 |
|
349 |
-
image_blocks.launch(show_error=True)
|
|
|
217 |
# 最初にマスク画像を一度だけ出力
|
218 |
yield output_images.value, mask_gray
|
219 |
|
220 |
+
try:
|
221 |
+
for i in range(int(num_images)):
|
222 |
+
current_seed = seed + i if seed is not None and seed != -1 else None
|
223 |
+
generator = (
|
224 |
+
torch.Generator(device).manual_seed(int(current_seed)) if current_seed is not None else None
|
225 |
+
)
|
226 |
|
227 |
+
with torch.no_grad():
|
228 |
+
with torch.cuda.amp.autocast():
|
229 |
+
images = pipe(
|
230 |
+
prompt_embeds=prompt_embeds.to(device, torch.float16),
|
231 |
+
negative_prompt_embeds=negative_prompt_embeds.to(device, torch.float16),
|
232 |
+
pooled_prompt_embeds=pooled_prompt_embeds.to(device, torch.float16),
|
233 |
+
negative_pooled_prompt_embeds=negative_pooled_prompt_embeds.to(
|
234 |
+
device, torch.float16
|
235 |
+
),
|
236 |
+
num_inference_steps=denoise_steps,
|
237 |
+
generator=generator,
|
238 |
+
strength=1.0,
|
239 |
+
pose_img=pose_img_tensor.to(device, torch.float16),
|
240 |
+
text_embeds_cloth=prompt_embeds_c.to(device, torch.float16),
|
241 |
+
cloth=garm_tensor.to(device, torch.float16),
|
242 |
+
mask_image=mask,
|
243 |
+
image=human_img,
|
244 |
+
height=1024,
|
245 |
+
width=768,
|
246 |
+
ip_adapter_image=garm_img.resize((768, 1024)),
|
247 |
+
guidance_scale=2.0,
|
248 |
+
)[0]
|
249 |
+
|
250 |
+
if is_checked_crop:
|
251 |
+
out_img = images[0].resize(crop_size)
|
252 |
+
human_img_copy = human_img_orig.copy()
|
253 |
+
human_img_copy.paste(out_img, (int(left), int(top)))
|
254 |
+
new_image = human_img_copy
|
255 |
+
else:
|
256 |
+
new_image = images[0]
|
257 |
+
|
258 |
+
# 画像を追加
|
259 |
+
output_images.value.append(new_image)
|
260 |
+
|
261 |
+
# ギャラリーを更新しつつmasked_imgを保持
|
262 |
+
yield output_images.value, mask_gray # mask_grayを再度渡す
|
263 |
+
|
264 |
+
except Exception as e:
|
265 |
+
# タイムアウトなどの例外が発生した場合でも、生成済みの画像を返却
|
266 |
+
yield output_images.value, mask_gray
|
267 |
+
# エラーを再度発生させてエラーメッセージを表示
|
268 |
+
raise e
|
269 |
|
270 |
# 最終的な結果を返す
|
271 |
return output_images.value, mask_gray
|
|
|
323 |
label="Masked image output", elem_id="masked-img", show_share_button=False
|
324 |
)
|
325 |
with gr.Column():
|
326 |
+
image_gallery = gr.Gallery(
|
327 |
+
label="Generated Images", elem_id="output-gallery", show_label=True
|
328 |
+
)
|
329 |
|
330 |
with gr.Column():
|
331 |
try_button = gr.Button(value="Try-on")
|
|
|
336 |
)
|
337 |
seed = gr.Number(label="Seed", minimum=-1, maximum=2147483647, step=1, value=42)
|
338 |
num_images = gr.Slider(
|
339 |
+
label="Number of Images", minimum=1, maximum=10, step=1, value=1 # 最大値を10に変更
|
340 |
)
|
341 |
|
342 |
try_button.click(
|
|
|
355 |
api_name='tryon',
|
356 |
)
|
357 |
|
358 |
+
image_blocks.launch(show_error=True)
|