cmahima commited on
Commit
8e3bcb4
1 Parent(s): dfd6ed1
Files changed (1) hide show
  1. app.py +9 -14
app.py CHANGED
@@ -253,10 +253,9 @@ def start_tryon(dict,garm_img,garment_des,is_checked,is_checked_crop,denoise_ste
253
  return images[0], mask_gray
254
  # return images[0], mask_gray
255
  # Function to handle image selection from the gallery
256
- def select_image(image_url):
257
- response = requests.get(image_url)
258
- image = Image.open(BytesIO(response.content))
259
- return image
260
 
261
  garm_list = os.listdir(os.path.join(example_path,"cloth"))
262
  garm_list_path = [os.path.join(example_path,"cloth",garm) for garm in garm_list]
@@ -295,15 +294,10 @@ with image_blocks as demo:
295
  )
296
 
297
  with gr.Column():
298
- garm_img = gr.Image(label="Garment", elem_id="amazon-img",show_share_button=False)
299
- with gr.Row(elem_id="prompt-container"):
300
- with gr.Row():
301
- prompt = gr.Textbox(placeholder="Description of garment ex) Yellow Top", show_label=False, elem_id="prompt")
302
- fetch_button = gr.Button("Fetch Products")
303
- example = gr.Examples(
304
- inputs=garm_img,
305
- examples_per_page=8,
306
- examples=garm_list_path)
307
  price_display = gr.Textbox(label="Price of Selected Image", interactive=False)
308
  url_display = gr.Textbox(label="URL of Selected Image", interactive=False)
309
  with gr.Column():
@@ -321,7 +315,8 @@ with image_blocks as demo:
321
  seed = gr.Number(label="Seed", minimum=-1, maximum=2147483647, step=1, value=42)
322
 
323
 
324
- fetch_button.click(fn=fetch_products, inputs=prompt, outputs=[example, price_display, url_display])
 
325
 
326
  try_button.click(fn=start_tryon, inputs=[imgs, garm_img, prompt, is_checked,is_checked_crop, denoise_steps, seed], outputs=[image_out,masked_img], api_name='tryon')
327
 
 
253
  return images[0], mask_gray
254
  # return images[0], mask_gray
255
  # Function to handle image selection from the gallery
256
+ def select_image(images, evt: gr.SelectData):
257
+ print(images)
258
+ return images[evt.index]['name']
 
259
 
260
  garm_list = os.listdir(os.path.join(example_path,"cloth"))
261
  garm_list_path = [os.path.join(example_path,"cloth",garm) for garm in garm_list]
 
294
  )
295
 
296
  with gr.Column():
297
+ garm_img = gr.Image(label="Garment", elem_id="upload",show_share_button=False)
298
+ prompt = gr.Textbox(placeholder="Description of garment ex) Yellow Top", show_label=False, elem_id="prompt")
299
+ fetch_button = gr.Button("Fetch Products")
300
+ image_gallery = gr.Gallery(label="Fetched Images", columns=4)
 
 
 
 
 
301
  price_display = gr.Textbox(label="Price of Selected Image", interactive=False)
302
  url_display = gr.Textbox(label="URL of Selected Image", interactive=False)
303
  with gr.Column():
 
315
  seed = gr.Number(label="Seed", minimum=-1, maximum=2147483647, step=1, value=42)
316
 
317
 
318
+ fetch_button.click(fn=fetch_products, inputs=prompt, outputs=[image_gallery, price_display, url_display])
319
+ image_gallery.select(select_image, image_gallery, garm_img)
320
 
321
  try_button.click(fn=start_tryon, inputs=[imgs, garm_img, prompt, is_checked,is_checked_crop, denoise_steps, seed], outputs=[image_out,masked_img], api_name='tryon')
322