txarst commited on
Commit
1b72bb6
·
1 Parent(s): 364c96c

concurrency

Browse files
Files changed (1) hide show
  1. app.py +26 -4
app.py CHANGED
@@ -260,21 +260,39 @@ def start_tryon(dict, garm_img, garment_des, is_checked, is_checked_crop, denois
260
  # 7. 后处理 - 处理裁剪情况并返回结果
261
  if is_checked_crop:
262
  # 将生成的图片和mask调整到裁剪后的尺寸
263
- return images[0].resize(crop_size), mask_gray.resize(crop_size)
264
  else:
265
  # 直接将生成的图片和mask调整到原始尺寸
266
- return images[0].resize(orig_size), mask_gray.resize(orig_size)
 
 
 
 
 
 
 
 
 
 
 
267
 
268
  ##default human
269
 
270
 
271
- image_blocks = gr.Blocks().queue()
 
 
 
 
 
272
  with image_blocks as demo:
273
 
274
  ##文字標題所在
275
 
276
  gr.Markdown("## Change Clothes AI - AI Clothes Changer Online")
277
  gr.Markdown("Go to [Change Clothes AI](https://changeclothesai.online/) for Free Try-On! 🤗 .")
 
 
278
  ##係數區塊
279
  with gr.Column():
280
  try_button = gr.Button(value="Run Change Clothes AI")
@@ -329,4 +347,8 @@ with image_blocks as demo:
329
 
330
 
331
 
332
- image_blocks.launch()
 
 
 
 
 
260
  # 7. 后处理 - 处理裁剪情况并返回结果
261
  if is_checked_crop:
262
  # 将生成的图片和mask调整到裁剪后的尺寸
263
+ result = images[0].resize(crop_size), mask_gray.resize(crop_size)
264
  else:
265
  # 直接将生成的图片和mask调整到原始尺寸
266
+ result = images[0].resize(orig_size), mask_gray.resize(orig_size)
267
+
268
+ return result
269
+ finally:
270
+ # Clear GPU memory after each run
271
+ torch.cuda.empty_cache()
272
+ if 'images' in locals():
273
+ del images
274
+ if 'pose_img' in locals():
275
+ del pose_img
276
+ if 'garm_tensor' in locals():
277
+ del garm_tensor
278
 
279
  ##default human
280
 
281
 
282
+ image_blocks = gr.Blocks().queue(
283
+ concurrency_count=5, # Process one at a time
284
+ max_size=10, # Queue up to 10 requests
285
+ api_open=True
286
+ )
287
+
288
  with image_blocks as demo:
289
 
290
  ##文字標題所在
291
 
292
  gr.Markdown("## Change Clothes AI - AI Clothes Changer Online")
293
  gr.Markdown("Go to [Change Clothes AI](https://changeclothesai.online/) for Free Try-On! 🤗 .")
294
+ # Add queue status
295
+ queue_status = gr.HTML()
296
  ##係數區塊
297
  with gr.Column():
298
  try_button = gr.Button(value="Run Change Clothes AI")
 
347
 
348
 
349
 
350
+ image_blocks.launch(
351
+ enable_queue=True,
352
+ show_api=False,
353
+ share=False
354
+ )