JosephPai
commited on
Commit
•
544ad26
1
Parent(s):
091f2fc
update inpaint
Browse files
app.py
CHANGED
@@ -93,7 +93,16 @@ def text_to_image_generation(input_text, guidance_scale=1.75, generation_timeste
|
|
93 |
|
94 |
|
95 |
@spaces.GPU
|
96 |
-
def text_guided_inpainting(input_text, inpainting_image,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
prompt = [input_text]
|
98 |
|
99 |
config.training.batch_size = config.batch_size = 1
|
@@ -393,15 +402,23 @@ with gr.Blocks() as demo:
|
|
393 |
inpainting_input_img = gr.Image(
|
394 |
label="Input image",
|
395 |
type="pil",
|
396 |
-
height=256,
|
397 |
-
width=256,
|
398 |
)
|
399 |
-
inpainting_input_mask = gr.Image(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
400 |
label="Inpainting mask",
|
401 |
-
|
402 |
-
type="pil",
|
403 |
-
height=256,
|
404 |
-
width=256,
|
405 |
)
|
406 |
|
407 |
with gr.Column():
|
|
|
93 |
|
94 |
|
95 |
@spaces.GPU
|
96 |
+
def text_guided_inpainting(input_text, inpainting_image, inpainting_mask_input, guidance_scale=1.75, generation_timesteps=16):
|
97 |
+
# pre-process inpainting mask
|
98 |
+
alpha_channel = inpainting_mask_input["layers"][0][:, :, 3]
|
99 |
+
mask = np.where(alpha_channel == 0, 0, 255).astype(np.uint8)
|
100 |
+
|
101 |
+
if np.sum(mask) == 0:
|
102 |
+
inpainting_mask = Image.fromarray(inpainting_mask_input['background']).convert('L')
|
103 |
+
else:
|
104 |
+
inpainting_mask = Image.fromarray(mask).convert('L')
|
105 |
+
|
106 |
prompt = [input_text]
|
107 |
|
108 |
config.training.batch_size = config.batch_size = 1
|
|
|
402 |
inpainting_input_img = gr.Image(
|
403 |
label="Input image",
|
404 |
type="pil",
|
405 |
+
# height=256,
|
406 |
+
# width=256,
|
407 |
)
|
408 |
+
# inpainting_input_mask = gr.Image(
|
409 |
+
# label="Inpainting mask",
|
410 |
+
# image_mode="L",
|
411 |
+
# type="pil",
|
412 |
+
# height=256,
|
413 |
+
# width=256,
|
414 |
+
# )
|
415 |
+
inpainting_input_mask = gr.ImageMask(
|
416 |
+
sources=["upload"],
|
417 |
+
layers=False,
|
418 |
+
transforms=[],
|
419 |
+
format="png",
|
420 |
label="Inpainting mask",
|
421 |
+
show_label=True
|
|
|
|
|
|
|
422 |
)
|
423 |
|
424 |
with gr.Column():
|