legoandmars commited on
Commit
54e4efb
1 Parent(s): 6f03ed8
Files changed (2) hide show
  1. app.py +9 -11
  2. desert.png +0 -0
app.py CHANGED
@@ -128,7 +128,8 @@ def inpaint(input_img, input_img_with_mask, prompt):
128
  input_img_with_mask_converted = input_img.convert('RGBA').getchannel( 'A' ) # Mode 'L'
129
 
130
  input_img_with_mask_64 = input_img_with_mask_converted.resize((64, 64), resample=Image.BICUBIC)
131
- input_img_with_mask_256 = input_img_with_mask_converted.resize((256, 256), resample=Image.BICUBIC)
 
132
  # return input_img, input_img_with_mask_64
133
  # Source image we are inpainting
134
  source_image_256 = pil_to_numpy(input_img_256)
@@ -138,18 +139,18 @@ def inpaint(input_img, input_img_with_mask, prompt):
138
  # Assuming that all black pixels are meant for inpainting.
139
  # input_img_with_mask_64 = input_img_with_mask.convert('L').resize((64, 64), resample=Image.BICUBIC)
140
  gray_scale_source_image_64 = image_to_tensor(input_img_with_mask_64)
141
- gray_scale_source_image_256 = image_to_tensor(input_img_with_mask_256)
142
 
143
  source_mask_64 = (gray_scale_source_image_64!=0).float()
144
- source_mask_256 = (gray_scale_source_image_256!=0).float()
145
 
146
  source_mask_64_img = tensor_to_image(source_mask_64)
147
 
148
  # The mask should always be a boolean 64x64 mask, and then we
149
  # can upsample it for the second stage.
150
  source_mask_64 = source_mask_64.unsqueeze(0)
151
- source_mask_256 = source_mask_256.unsqueeze(0)
152
- # source_mask_256 = F.interpolate(source_mask_64, (256, 256), mode='nearest')
153
 
154
 
155
  ##############################
@@ -249,19 +250,16 @@ def inpaint(input_img, input_img_with_mask, prompt):
249
  gradio_inputs = [gr.inputs.Image(type='pil',
250
  label="Input Image",
251
  image_mode="RGBA"),
252
- gr.inputs.Image(type='pil',
253
- label="Input Image With Mask"),
254
  gr.inputs.Textbox(label='Conditional Text to Inpaint')]
255
 
256
  # gradio_outputs = [gr.outputs.Image(label='Auto-Detected Mask (From drawn black pixels)')]
257
 
258
- gradio_outputs = [gr.outputs.Image(label='Auto-Detected Mask (From drawn black pixels)'),
259
- gr.outputs.Image(label='Inpainted Image')]
260
- examples = [['grass.png', 'grass_with_mask.png', 'a corgi in a field']]
261
 
262
  title = "GLIDE Inpaint"
263
  description = "[WARNING: Queue times may take 4-6 minutes per person if there's no GPU! If there is a GPU, it'll take around 60 seconds] Using GLIDE to inpaint black regions of an input image! Instructions: 1) For the 'Input Image', upload an image. 2) For the 'Input Image with Mask', draw a black-colored mask (either manually with something like Paint, or by using gradio's built-in image editor & add a black-colored shape) IT MUST BE BLACK COLOR, but doesn't have to be rectangular! This is because it auto-detects the mask based on 0 (black) pixel values! 3) For the Conditional Text, type something you'd like to see the black region get filled in with :)"
264
- article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2112.10741' target='_blank'>GLIDE: Towards Photorealistic Image Generation and Editing with Text-Guided Diffusion Models</a> | <a href='https://github.com/openai/glide-text2im' target='_blank'>Github Repo</a> | <img src='https://visitor-badge.glitch.me/badge?page_id=epoching_glide_inpaint' alt='visitor badge'></p>"
265
  iface = gr.Interface(fn=inpaint, inputs=gradio_inputs,
266
  outputs=gradio_outputs,
267
  examples=examples, title=title,
 
128
  input_img_with_mask_converted = input_img.convert('RGBA').getchannel( 'A' ) # Mode 'L'
129
 
130
  input_img_with_mask_64 = input_img_with_mask_converted.resize((64, 64), resample=Image.BICUBIC)
131
+ # TODO: make 256x256 mask more accurate when upscaling?
132
+ # input_img_with_mask_256 = input_img_with_mask_converted.resize((256, 256), resample=Image.BICUBIC)
133
  # return input_img, input_img_with_mask_64
134
  # Source image we are inpainting
135
  source_image_256 = pil_to_numpy(input_img_256)
 
139
  # Assuming that all black pixels are meant for inpainting.
140
  # input_img_with_mask_64 = input_img_with_mask.convert('L').resize((64, 64), resample=Image.BICUBIC)
141
  gray_scale_source_image_64 = image_to_tensor(input_img_with_mask_64)
142
+ # gray_scale_source_image_256 = image_to_tensor(input_img_with_mask_256)
143
 
144
  source_mask_64 = (gray_scale_source_image_64!=0).float()
145
+ # source_mask_256 = (gray_scale_source_image_256!=0).float()
146
 
147
  source_mask_64_img = tensor_to_image(source_mask_64)
148
 
149
  # The mask should always be a boolean 64x64 mask, and then we
150
  # can upsample it for the second stage.
151
  source_mask_64 = source_mask_64.unsqueeze(0)
152
+ # source_mask_256 = source_mask_256.unsqueeze(0)
153
+ source_mask_256 = F.interpolate(source_mask_64, (256, 256), mode='nearest')
154
 
155
 
156
  ##############################
 
250
  gradio_inputs = [gr.inputs.Image(type='pil',
251
  label="Input Image",
252
  image_mode="RGBA"),
 
 
253
  gr.inputs.Textbox(label='Conditional Text to Inpaint')]
254
 
255
  # gradio_outputs = [gr.outputs.Image(label='Auto-Detected Mask (From drawn black pixels)')]
256
 
257
+ gradio_outputs = [gr.outputs.Image(label='Inpainted Image')]
258
+ examples = [['desert.png', 'a car in the desert']]
 
259
 
260
  title = "GLIDE Inpaint"
261
  description = "[WARNING: Queue times may take 4-6 minutes per person if there's no GPU! If there is a GPU, it'll take around 60 seconds] Using GLIDE to inpaint black regions of an input image! Instructions: 1) For the 'Input Image', upload an image. 2) For the 'Input Image with Mask', draw a black-colored mask (either manually with something like Paint, or by using gradio's built-in image editor & add a black-colored shape) IT MUST BE BLACK COLOR, but doesn't have to be rectangular! This is because it auto-detects the mask based on 0 (black) pixel values! 3) For the Conditional Text, type something you'd like to see the black region get filled in with :)"
262
+ article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2112.10741' target='_blank'>GLIDE: Towards Photorealistic Image Generation and Editing with Text-Guided Diffusion Models</a> | <a href='https://github.com/openai/glide-text2im' target='_blank'>Github Repo</a></p>"
263
  iface = gr.Interface(fn=inpaint, inputs=gradio_inputs,
264
  outputs=gradio_outputs,
265
  examples=examples, title=title,
desert.png ADDED