MCPcopy Create free account
hub / github.com/chenfei-wu/TaskMatrix / dowhile

Method dowhile

visual_chatgpt.py:1240–1262  ·  view source on GitHub ↗
(self, original_img, tosize, expand_ratio, imagine, usr_prompt)

Source from the content-addressed store, hash-verified

1238 return image.resize((new_width, new_height))
1239
1240 def dowhile(self, original_img, tosize, expand_ratio, imagine, usr_prompt):
1241 old_img = original_img
1242 while (old_img.size != tosize):
1243 prompt = self.check_prompt(usr_prompt) if usr_prompt else self.get_imagine_caption(old_img, imagine)
1244 crop_w = 15 if old_img.size[0] != tosize[0] else 0
1245 crop_h = 15 if old_img.size[1] != tosize[1] else 0
1246 old_img = ImageOps.crop(old_img, (crop_w, crop_h, crop_w, crop_h))
1247 temp_canvas_size = (expand_ratio * old_img.width if expand_ratio * old_img.width < tosize[0] else tosize[0],
1248 expand_ratio * old_img.height if expand_ratio * old_img.height < tosize[1] else tosize[
1249 1])
1250 temp_canvas, temp_mask = Image.new("RGB", temp_canvas_size, color="white"), Image.new("L", temp_canvas_size,
1251 color="white")
1252 x, y = (temp_canvas.width - old_img.width) // 2, (temp_canvas.height - old_img.height) // 2
1253 temp_canvas.paste(old_img, (x, y))
1254 temp_mask.paste(0, (x, y, x + old_img.width, y + old_img.height))
1255 resized_temp_canvas, resized_temp_mask = self.resize_image(temp_canvas), self.resize_image(temp_mask)
1256 image = self.inpaint(prompt=prompt, image=resized_temp_canvas, mask_image=resized_temp_mask,
1257 height=resized_temp_canvas.height, width=resized_temp_canvas.width,
1258 num_inference_steps=50).resize(
1259 (temp_canvas.width, temp_canvas.height), Image.ANTIALIAS)
1260 image = blend_gt2pt(old_img, image)
1261 old_img = image
1262 return old_img
1263
1264 @prompts(name="Extend An Image",
1265 description="useful when you need to extend an image into a larger image."

Callers 1

inferenceMethod · 0.95

Calls 4

check_promptMethod · 0.95
get_imagine_captionMethod · 0.95
resize_imageMethod · 0.95
blend_gt2ptFunction · 0.85

Tested by

no test coverage detected