aljun5 commited on
Commit
fdc9cde
·
verified ·
1 Parent(s): 6adf673

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +127 -22
app.py CHANGED
@@ -23,16 +23,16 @@ MODEL_MAP = {
23
  # Sample clothing items from your clothes folder
24
  SAMPLE_CLOTHES = {
25
  "top": [
26
- "clothes/shirt1.jpg",
27
- "clothes/shirt2.jpg",
28
- "clothes/dress1.jpg",
29
- "clothes/jacket1.jpg"
30
  ],
31
  "bottom": [
32
- "clothes/pants1.jpg",
33
- "clothes/skirt1.jpg",
34
- "clothes/jeans1.jpg",
35
- "clothes/shorts1.jpg"
36
  ]
37
  }
38
 
@@ -55,6 +55,18 @@ def load_sample_image(image_path):
55
  print(f"Error loading image {image_path}: {e}")
56
  return np.zeros((400, 400, 3), dtype=np.uint8)
57
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  def get_tryon_result(model_name, garment1, garment2, seed=1234):
59
  # model_name = "AI Model " + model_name.split("\\")[-1].split(".")[0] # windows
60
  model_name = "AI Model " + model_name.split("/")[-1].split(".")[0] # linux
@@ -133,7 +145,38 @@ with gr.Blocks(css = ".output-image, .input-image, .image-preview {height: 400px
133
  """)
134
  with gr.Row():
135
  with gr.Column():
136
- init_image = gr.Image(sources='clipboard', type="filepath", label="model", value=model)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
 
138
  with gr.Column():
139
  gr.HTML(
@@ -146,24 +189,68 @@ with gr.Blocks(css = ".output-image, .input-image, .image-preview {height: 400px
146
  </div>
147
  """)
148
 
149
- # Sample clothing buttons section
150
  gr.HTML("<h3>Quick Select Sample Clothes:</h3>")
151
 
 
152
  with gr.Row():
153
- gr.HTML("<h4>Top Garments:</h4>")
154
- with gr.Row():
155
- top_btn1 = gr.Button("Shirt 1", variant="secondary")
156
- top_btn2 = gr.Button("Shirt 2", variant="secondary")
157
- top_btn3 = gr.Button("Dress", variant="secondary")
158
- top_btn4 = gr.Button("Jacket", variant="secondary")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
 
 
160
  with gr.Row():
161
- gr.HTML("<h4>Bottom Garments:</h4>")
162
- with gr.Row():
163
- bottom_btn1 = gr.Button("Pants", variant="secondary")
164
- bottom_btn2 = gr.Button("Skirt", variant="secondary")
165
- bottom_btn3 = gr.Button("Jeans", variant="secondary")
166
- bottom_btn4 = gr.Button("Shorts", variant="secondary")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
 
168
  with gr.Row():
169
  garment_top = gr.Image(sources='upload', type="numpy", label="top garment")
@@ -174,6 +261,24 @@ with gr.Blocks(css = ".output-image, .input-image, .image-preview {height: 400px
174
  with gr.Column():
175
  gallery = gr.Image()
176
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  # Connect buttons to load sample images
178
  top_btn1.click(
179
  lambda: load_sample_image(SAMPLE_CLOTHES["top"][0]),
 
23
  # Sample clothing items from your clothes folder
24
  SAMPLE_CLOTHES = {
25
  "top": [
26
+ "clothes/shirt.jpg",
27
+ "clothes/cardigan.jpg",
28
+ "clothes/jacket.jpg",
29
+ "clothes/dress.jpg"
30
  ],
31
  "bottom": [
32
+ "clothes/pants.jpg",
33
+ "clothes/jeans.jpg",
34
+ "clothes/skirt.jpg",
35
+ "clothes/shorts.jpg"
36
  ]
37
  }
38
 
 
55
  print(f"Error loading image {image_path}: {e}")
56
  return np.zeros((400, 400, 3), dtype=np.uint8)
57
 
58
+ def load_model_image(model_path):
59
+ """Load a model image and return the file path"""
60
+ try:
61
+ if os.path.exists(model_path):
62
+ return model_path
63
+ else:
64
+ print(f"Model image not found: {model_path}")
65
+ return model # fallback to default
66
+ except Exception as e:
67
+ print(f"Error loading model {model_path}: {e}")
68
+ return model # fallback to default
69
+
70
  def get_tryon_result(model_name, garment1, garment2, seed=1234):
71
  # model_name = "AI Model " + model_name.split("\\")[-1].split(".")[0] # windows
72
  model_name = "AI Model " + model_name.split("/")[-1].split(".")[0] # linux
 
145
  """)
146
  with gr.Row():
147
  with gr.Column():
148
+ # Model selection buttons with preview images
149
+ gr.HTML("<h3>Select AI Model:</h3>")
150
+ with gr.Row():
151
+ with gr.Column():
152
+ model_preview1 = gr.Image(value=MODEL_MAP["AI Model female_model"],
153
+ label="Female Model",
154
+ height=150, width=100,
155
+ interactive=False, show_label=True)
156
+ model_btn1 = gr.Button("Select Female Model", variant="secondary")
157
+
158
+ with gr.Column():
159
+ model_preview2 = gr.Image(value=MODEL_MAP["AI Model female_model1"],
160
+ label="Female Model 1",
161
+ height=150, width=100,
162
+ interactive=False, show_label=True)
163
+ model_btn2 = gr.Button("Select Female Model 1", variant="secondary")
164
+
165
+ with gr.Column():
166
+ model_preview3 = gr.Image(value=MODEL_MAP["AI Model male_model"],
167
+ label="Male Model",
168
+ height=150, width=100,
169
+ interactive=False, show_label=True)
170
+ model_btn3 = gr.Button("Select Male Model", variant="secondary")
171
+
172
+ with gr.Column():
173
+ model_preview4 = gr.Image(value=MODEL_MAP["AI Model male_model2"],
174
+ label="Male Model 2",
175
+ height=150, width=100,
176
+ interactive=False, show_label=True)
177
+ model_btn4 = gr.Button("Select Male Model 2", variant="secondary")
178
+
179
+ init_image = gr.Image(sources='clipboard', type="filepath", label="Selected Model", value=model)
180
 
181
  with gr.Column():
182
  gr.HTML(
 
189
  </div>
190
  """)
191
 
192
+ # Sample clothing buttons section with preview images
193
  gr.HTML("<h3>Quick Select Sample Clothes:</h3>")
194
 
195
+ gr.HTML("<h4>Top Garments:</h4>")
196
  with gr.Row():
197
+ with gr.Column():
198
+ top_preview1 = gr.Image(value=SAMPLE_CLOTHES["top"][0],
199
+ label="Shirt",
200
+ height=150, width=100,
201
+ interactive=False, show_label=True)
202
+ top_btn1 = gr.Button("Select Shirt", variant="secondary")
203
+
204
+ with gr.Column():
205
+ top_preview2 = gr.Image(value=SAMPLE_CLOTHES["top"][1],
206
+ label="Cardigan",
207
+ height=150, width=100,
208
+ interactive=False, show_label=True)
209
+ top_btn2 = gr.Button("Select Cardigan", variant="secondary")
210
+
211
+ with gr.Column():
212
+ top_preview3 = gr.Image(value=SAMPLE_CLOTHES["top"][2],
213
+ label="Jacket",
214
+ height=150, width=100,
215
+ interactive=False, show_label=True)
216
+ top_btn3 = gr.Button("Select Jacket", variant="secondary")
217
+
218
+ with gr.Column():
219
+ top_preview4 = gr.Image(value=SAMPLE_CLOTHES["top"][3],
220
+ label="Dress",
221
+ height=150, width=100,
222
+ interactive=False, show_label=True)
223
+ top_btn4 = gr.Button("Select Dress", variant="secondary")
224
 
225
+ gr.HTML("<h4>Bottom Garments:</h4>")
226
  with gr.Row():
227
+ with gr.Column():
228
+ bottom_preview1 = gr.Image(value=SAMPLE_CLOTHES["bottom"][0],
229
+ label="Pants",
230
+ height=150, width=100,
231
+ interactive=False, show_label=True)
232
+ bottom_btn1 = gr.Button("Select Pants", variant="secondary")
233
+
234
+ with gr.Column():
235
+ bottom_preview2 = gr.Image(value=SAMPLE_CLOTHES["bottom"][1],
236
+ label="Jeans",
237
+ height=150, width=100,
238
+ interactive=False, show_label=True)
239
+ bottom_btn2 = gr.Button("Select Jeans", variant="secondary")
240
+
241
+ with gr.Column():
242
+ bottom_preview3 = gr.Image(value=SAMPLE_CLOTHES["bottom"][2],
243
+ label="Skirt",
244
+ height=150, width=100,
245
+ interactive=False, show_label=True)
246
+ bottom_btn3 = gr.Button("Select Skirt", variant="secondary")
247
+
248
+ with gr.Column():
249
+ bottom_preview4 = gr.Image(value=SAMPLE_CLOTHES["bottom"][3],
250
+ label="Shorts",
251
+ height=150, width=100,
252
+ interactive=False, show_label=True)
253
+ bottom_btn4 = gr.Button("Select Shorts", variant="secondary")
254
 
255
  with gr.Row():
256
  garment_top = gr.Image(sources='upload', type="numpy", label="top garment")
 
261
  with gr.Column():
262
  gallery = gr.Image()
263
 
264
+ # Connect model buttons to load model images
265
+ model_btn1.click(
266
+ lambda: load_model_image(MODEL_MAP["AI Model female_model"]),
267
+ outputs=[init_image]
268
+ )
269
+ model_btn2.click(
270
+ lambda: load_model_image(MODEL_MAP["AI Model female_model1"]),
271
+ outputs=[init_image]
272
+ )
273
+ model_btn3.click(
274
+ lambda: load_model_image(MODEL_MAP["AI Model male_model"]),
275
+ outputs=[init_image]
276
+ )
277
+ model_btn4.click(
278
+ lambda: load_model_image(MODEL_MAP["AI Model male_model2"]),
279
+ outputs=[init_image]
280
+ )
281
+
282
  # Connect buttons to load sample images
283
  top_btn1.click(
284
  lambda: load_sample_image(SAMPLE_CLOTHES["top"][0]),