liuyizhang commited on
Commit
1f8f331
1 Parent(s): 7957dbb

update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -291,10 +291,16 @@ def run_grounded_sam(image_path, text_prompt, task_type, inpaint_prompt, box_thr
291
  mask = masks[0][0].cpu().numpy() # simply choose the first mask, which will be refine in the future release
292
  mask_pil = Image.fromarray(mask)
293
  image_pil = Image.fromarray(image)
 
 
 
 
 
 
 
294
 
295
- image = sd_pipe(prompt=inpaint_prompt, image=image_pil, mask_image=mask_pil).images[0]
296
  image_path = os.path.join(output_dir, f"grounded_sam_inpainting_output_{file_temp}.jpg")
297
- image.save(image_path)
298
  image_result = cv2.cvtColor(cv2.imread(image_path), cv2.COLOR_BGR2RGB)
299
  os.remove(image_path)
300
  return image_result
 
291
  mask = masks[0][0].cpu().numpy() # simply choose the first mask, which will be refine in the future release
292
  mask_pil = Image.fromarray(mask)
293
  image_pil = Image.fromarray(image)
294
+ # image_inpainting = sd_pipe(prompt=inpaint_prompt, image=image_pil, mask_image=mask_pil).images[0]
295
+
296
+ # resize for inpaint
297
+ image_source_for_inpaint = image_pil.resize((512, 512))
298
+ image_mask_for_inpaint = mask_pil.resize((512, 512))
299
+ image_inpainting = sd_pipe(prompt=inpaint_prompt, image=image_source_for_inpaint, mask_image=image_mask_for_inpaint).images[0]
300
+ image_inpainting = image_inpainting.resize((image_pil.size[0], image_pil.size[1]))
301
 
 
302
  image_path = os.path.join(output_dir, f"grounded_sam_inpainting_output_{file_temp}.jpg")
303
+ image_inpainting.save(image_path)
304
  image_result = cv2.cvtColor(cv2.imread(image_path), cv2.COLOR_BGR2RGB)
305
  os.remove(image_path)
306
  return image_result