craftgamesnetwork commited on
Commit
d65e488
·
verified ·
1 Parent(s): 4a5d0df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -80,15 +80,18 @@ def generate(
80
  pipe = AutoPipelineForImage2Image.from_pretrained(model, vae=vae, torch_dtype=torch.float16)
81
 
82
  if use_inpainting:
83
- pipe = AutoPipelineForInpainting.from_pretrained(model, torch_dtype=torch.float16)
84
-
85
- response = requests.get(url)
86
- init_image = Image.open(BytesIO(response.content)).convert("RGB")
87
- init_image = init_image.resize((width, height))
 
 
 
 
 
 
88
 
89
- image_init = load_image(img_url)
90
- mask_image = load_image(mask_url)
91
-
92
  if use_lora:
93
  pipe.load_lora_weights(lora)
94
  pipe.fuse_lora(lora_scale)
@@ -114,9 +117,8 @@ def generate(
114
  if use_inpainting:
115
  image = pipe(
116
  prompt=prompt,
117
- image=image_init,
118
- mask_image=mask_image,
119
- strength=strength_img2img,
120
  negative_prompt=negative_prompt,
121
  prompt_2=prompt_2,
122
  width=width,
 
80
  pipe = AutoPipelineForImage2Image.from_pretrained(model, vae=vae, torch_dtype=torch.float16)
81
 
82
  if use_inpainting:
83
+ controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-canny", torch_dtype=torch.float16)
84
+ pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(model, controlnet=controlnet, torch_dtype=torch.float16)
85
+
86
+ image = load_image(img_url)
87
+ np_image = np.array(image)
88
+
89
+ # get canny image
90
+ np_image = cv2.Canny(np_image, 100, 200)
91
+ np_image = np_image[:, :, None]
92
+ np_image = np.concatenate([np_image, np_image, np_image], axis=2)
93
+ canny_image = Image.fromarray(np_image)
94
 
 
 
 
95
  if use_lora:
96
  pipe.load_lora_weights(lora)
97
  pipe.fuse_lora(lora_scale)
 
117
  if use_inpainting:
118
  image = pipe(
119
  prompt=prompt,
120
+ image=image,
121
+ control_image=canny_image,
 
122
  negative_prompt=negative_prompt,
123
  prompt_2=prompt_2,
124
  width=width,