feylur commited on
Commit
a128a81
·
verified ·
1 Parent(s): 1693385

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -56,9 +56,9 @@ def load_models():
56
  traceback.print_exc()
57
  raise
58
 
59
- def generate_tryon(person_img, cloth_img):
60
  print("="*50, file=sys.stderr)
61
- print(f"Received - Person: {type(person_img)}, Cloth: {type(cloth_img)}", file=sys.stderr)
62
 
63
  if person_img is None or cloth_img is None:
64
  raise gr.Error("Both images required!")
@@ -68,7 +68,6 @@ def generate_tryon(person_img, cloth_img):
68
 
69
  load_models()
70
 
71
- # CRITICAL: Clear cache and create fresh copies
72
  gc.collect()
73
  if torch.cuda.is_available():
74
  torch.cuda.empty_cache()
@@ -81,7 +80,8 @@ def generate_tryon(person_img, cloth_img):
81
  person_img = resize_and_crop(person_img, (target_width, target_height))
82
  cloth_img = resize_and_padding(cloth_img, (target_width, target_height))
83
 
84
- mask = automasker(person_img, "upper")['mask']
 
85
  gc.collect()
86
  if torch.cuda.is_available():
87
  torch.cuda.empty_cache()
@@ -92,7 +92,7 @@ def generate_tryon(person_img, cloth_img):
92
  mask=mask,
93
  num_inference_steps=50,
94
  guidance_scale=2.5,
95
- seed=None, # CHANGED: Random seed for different results
96
  height=target_height,
97
  width=target_width
98
  )[0]
@@ -105,16 +105,22 @@ def generate_tryon(person_img, cloth_img):
105
  traceback.print_exc()
106
  raise gr.Error(str(e))
107
 
108
- # CRITICAL: Use gr.Interface instead of gr.Blocks for better API support
109
  demo = gr.Interface(
110
  fn=generate_tryon,
111
  inputs=[
112
- gr.Image(label="Person Image", type="pil"), # Changed from "filepath" to "pil"
113
- gr.Image(label="Garment Image", type="pil") # Changed from "filepath" to "pil"
 
 
 
 
 
 
114
  ],
115
- outputs=gr.Image(label="Result", type="pil"), # Changed from "filepath" to "pil"
116
  title="Try-Space Virtual Try-On",
117
- description="Upload person and garment images. Processing takes 2-3 minutes on GPU T4.",
118
  api_name="generate_tryon",
119
  allow_flagging="never"
120
  )
 
56
  traceback.print_exc()
57
  raise
58
 
59
+ def generate_tryon(person_img, cloth_img, garment_category): # Added parameter
60
  print("="*50, file=sys.stderr)
61
+ print(f"Received - Person: {type(person_img)}, Cloth: {type(cloth_img)}, Category: {garment_category}", file=sys.stderr)
62
 
63
  if person_img is None or cloth_img is None:
64
  raise gr.Error("Both images required!")
 
68
 
69
  load_models()
70
 
 
71
  gc.collect()
72
  if torch.cuda.is_available():
73
  torch.cuda.empty_cache()
 
80
  person_img = resize_and_crop(person_img, (target_width, target_height))
81
  cloth_img = resize_and_padding(cloth_img, (target_width, target_height))
82
 
83
+ # CHANGED: Use selected category instead of hardcoded "upper"
84
+ mask = automasker(person_img, garment_category)['mask']
85
  gc.collect()
86
  if torch.cuda.is_available():
87
  torch.cuda.empty_cache()
 
92
  mask=mask,
93
  num_inference_steps=50,
94
  guidance_scale=2.5,
95
+ seed=None,
96
  height=target_height,
97
  width=target_width
98
  )[0]
 
105
  traceback.print_exc()
106
  raise gr.Error(str(e))
107
 
108
+ # Updated Interface with category dropdown
109
  demo = gr.Interface(
110
  fn=generate_tryon,
111
  inputs=[
112
+ gr.Image(label="Person Image", type="pil"),
113
+ gr.Image(label="Garment Image", type="pil"),
114
+ gr.Dropdown(
115
+ choices=["upper", "lower", "overall"],
116
+ value="upper",
117
+ label="Garment Category",
118
+ info="Select: upper (tops), lower (pants/skirts), overall (dresses/full outfits)"
119
+ )
120
  ],
121
+ outputs=gr.Image(label="Result", type="pil"),
122
  title="Try-Space Virtual Try-On",
123
+ description="Upload person and garment images. Select category. Processing takes 2-3 minutes on GPU T4.",
124
  api_name="generate_tryon",
125
  allow_flagging="never"
126
  )