Burman-AI commited on
Commit
7577969
·
verified ·
1 Parent(s): aaeda48

Update main_code_script.py

Browse files
Files changed (1) hide show
  1. main_code_script.py +4 -5
main_code_script.py CHANGED
@@ -54,21 +54,20 @@ def segment_clothing(image, results): #Added result
54
  mask_img = Image.fromarray(binary_mask).convert("L")
55
  return mask_img
56
  # --- 3. Image Inpainting (Replacing Clothing - using Stable Diffusion Inpainting) ---
57
- def inpaint_clothing(image, mask_img, clothing_prompt, device="cuda" if torch.cuda.is_available() else "cpu"):
58
  """
59
  Replaces the clothing region in the image with new clothing based on a text prompt,
60
  using Stable Diffusion Inpainting.
61
  """
62
  pipe = StableDiffusionInpaintPipeline.from_pretrained(
63
- # "stabilityai/stable-diffusion-2-inpainting",
64
- "stabilityai/stable-diffusion-2-base"
65
- # "SimianLuo/LCM_Dreamshaper_v7"
66
  torch_dtype=torch.float16
67
  )
68
  pipe = pipe.to(device)
69
  # Resize the image and mask to a smaller size for faster inpainting
70
  width, height = image.size
71
- inpainted_size = (256, 256) # Smaller size for faster inpainting
72
  image = image.resize(inpainted_size)
73
  mask_img = mask_img.resize(inpainted_size)
74
  prompt = f"A photo of a person wearing {clothing_prompt}" #Add style or detail
 
54
  mask_img = Image.fromarray(binary_mask).convert("L")
55
  return mask_img
56
  # --- 3. Image Inpainting (Replacing Clothing - using Stable Diffusion Inpainting) ---
57
+ def inpaint_clothing(image, mask_img, clothing_prompt, device="cpu" if torch.cuda.is_available() else "cpu"):
58
  """
59
  Replaces the clothing region in the image with new clothing based on a text prompt,
60
  using Stable Diffusion Inpainting.
61
  """
62
  pipe = StableDiffusionInpaintPipeline.from_pretrained(
63
+ "stabilityai/stable-diffusion-2-inpainting",
64
+ "SimianLuo/LCM_Dreamshaper_v7"
 
65
  torch_dtype=torch.float16
66
  )
67
  pipe = pipe.to(device)
68
  # Resize the image and mask to a smaller size for faster inpainting
69
  width, height = image.size
70
+ inpainted_size = (128, 128) # Smaller size for faster inpainting
71
  image = image.resize(inpainted_size)
72
  mask_img = mask_img.resize(inpainted_size)
73
  prompt = f"A photo of a person wearing {clothing_prompt}" #Add style or detail