lsb commited on
Commit
34895c9
1 Parent(s): 0025e75

parameterize inpaint size

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -40,7 +40,6 @@ inpainting_pipeline = StableDiffusionInpaintPipeline.from_pretrained(
40
  #seg_model = torch.compile(seg_model, backend=preferred_backend)
41
 
42
  seg_working_size = (seg_model_img_size, seg_model_img_size)
43
- repaint_working_size = (768, 768)
44
 
45
  default_inpainting_prompt = "award-winning photo of a leafy pedestrian mall full of people, with multiracial genderqueer joggers and bicyclists and wheelchair users talking and laughing"
46
 
@@ -63,7 +62,7 @@ def get_seg_mask(img):
63
  return blurred_widened_mask
64
 
65
 
66
- def app(img, prompt, num_inference_steps, seed):
67
  start_time = datetime.now().timestamp()
68
  old_size = Image.fromarray(img).size
69
  img = np.array(Image.fromarray(img).resize(seg_working_size))
@@ -77,8 +76,8 @@ def app(img, prompt, num_inference_steps, seed):
77
  mask_image=(mask).resize(repaint_working_size),
78
  strength=1,
79
  num_inference_steps=num_inference_steps,
80
- height=repaint_working_size[0],
81
- width=repaint_working_size[1],
82
  generator=torch.manual_seed(int(seed)),
83
  ).images[0]
84
  #overlay_img.save("overlay_raw.jpg")
@@ -95,9 +94,16 @@ def app(img, prompt, num_inference_steps, seed):
95
 
96
  for i in range(2):
97
  for j in tqdm(range(3 ** i)):
98
- app(np.array(Image.fromarray(np.zeros((1024,1024,3), dtype=np.uint8))), default_inpainting_prompt, 4, 42).save("zeros_inpainting_oneshot.jpg")
99
 
100
  #ideally:
101
  #iface = gr.Interface(app, gr.Image(sources=["webcam"], streaming=True), "image", live=True)
102
- iface = gr.Interface(app, [gr.Image(), gr.Textbox(value=default_inpainting_prompt), gr.Number(minimum=1, maximum=8, value=4), gr.Number(value=42)], "image")
 
 
 
 
 
 
 
103
  iface.launch()
 
40
  #seg_model = torch.compile(seg_model, backend=preferred_backend)
41
 
42
  seg_working_size = (seg_model_img_size, seg_model_img_size)
 
43
 
44
  default_inpainting_prompt = "award-winning photo of a leafy pedestrian mall full of people, with multiracial genderqueer joggers and bicyclists and wheelchair users talking and laughing"
45
 
 
62
  return blurred_widened_mask
63
 
64
 
65
+ def app(img, prompt, num_inference_steps, seed, inpaint_size):
66
  start_time = datetime.now().timestamp()
67
  old_size = Image.fromarray(img).size
68
  img = np.array(Image.fromarray(img).resize(seg_working_size))
 
76
  mask_image=(mask).resize(repaint_working_size),
77
  strength=1,
78
  num_inference_steps=num_inference_steps,
79
+ height=inpaint_size,
80
+ width=inpaint_size,
81
  generator=torch.manual_seed(int(seed)),
82
  ).images[0]
83
  #overlay_img.save("overlay_raw.jpg")
 
94
 
95
  for i in range(2):
96
  for j in tqdm(range(3 ** i)):
97
+ app(np.array(Image.fromarray(np.zeros((1024,1024,3), dtype=np.uint8))), default_inpainting_prompt, 4, 42, 512).save("zeros_inpainting_oneshot.jpg")
98
 
99
  #ideally:
100
  #iface = gr.Interface(app, gr.Image(sources=["webcam"], streaming=True), "image", live=True)
101
+ iface = gr.Interface(app, [
102
+ gr.Image(),
103
+ gr.Textbox(value=default_inpainting_prompt),
104
+ gr.Number(minimum=1, maximum=8, value=4),
105
+ gr.Number(value=42),
106
+ gr.Number(value=512, maximum=seg_model_img_size,)
107
+ ],
108
+ "image")
109
  iface.launch()