Update app.py
Browse files
app.py
CHANGED
@@ -36,30 +36,36 @@ def restore_version(index, versions):
|
|
36 |
|
37 |
|
38 |
def generate(image_editor, prompt, neg_prompt, versions):
|
39 |
-
print('versions')
|
40 |
-
print(versions)
|
41 |
-
|
42 |
image = image_editor['background'].convert('RGB')
|
|
|
|
|
43 |
image.thumbnail((1024, 1024))
|
44 |
image = divisible_by_8(image)
|
45 |
original_image_size = image.size
|
46 |
-
|
|
|
47 |
layer = image_editor["layers"][0].resize(image.size)
|
48 |
-
|
|
|
49 |
image = squarify_image(image)
|
50 |
-
|
|
|
51 |
mask = Image.new("RGBA", image.size, "WHITE")
|
52 |
mask.paste(layer, (0, 0), layer)
|
53 |
mask = ImageOps.invert(mask.convert('L'))
|
54 |
|
|
|
55 |
final_image = pipeline(prompt=prompt,
|
56 |
image=image,
|
57 |
mask_image=mask).images[0]
|
58 |
-
|
|
|
59 |
final_image = final_image.crop((0, 0, original_image_size[0], original_image_size[1]))
|
60 |
|
|
|
61 |
final_dict = {'background': final_image, 'layers': None, 'composite': final_image}
|
62 |
|
|
|
63 |
if(versions==None):
|
64 |
final_gallery = [image_editor['background'] ,final_image]
|
65 |
else:
|
@@ -72,6 +78,8 @@ with gr.Blocks() as demo:
|
|
72 |
gr.Markdown("""
|
73 |
# Inpainting Sketch Pad
|
74 |
by [Tony Assi](https://www.tonyassi.com/)
|
|
|
|
|
75 |
""")
|
76 |
|
77 |
with gr.Row():
|
|
|
36 |
|
37 |
|
38 |
def generate(image_editor, prompt, neg_prompt, versions):
|
|
|
|
|
|
|
39 |
image = image_editor['background'].convert('RGB')
|
40 |
+
|
41 |
+
# Resize image
|
42 |
image.thumbnail((1024, 1024))
|
43 |
image = divisible_by_8(image)
|
44 |
original_image_size = image.size
|
45 |
+
|
46 |
+
# Mask layer
|
47 |
layer = image_editor["layers"][0].resize(image.size)
|
48 |
+
|
49 |
+
# Make image a square
|
50 |
image = squarify_image(image)
|
51 |
+
|
52 |
+
# Make sure mask is white with a black background
|
53 |
mask = Image.new("RGBA", image.size, "WHITE")
|
54 |
mask.paste(layer, (0, 0), layer)
|
55 |
mask = ImageOps.invert(mask.convert('L'))
|
56 |
|
57 |
+
# Inpaint
|
58 |
final_image = pipeline(prompt=prompt,
|
59 |
image=image,
|
60 |
mask_image=mask).images[0]
|
61 |
+
|
62 |
+
# Crop image to original aspect ratio
|
63 |
final_image = final_image.crop((0, 0, original_image_size[0], original_image_size[1]))
|
64 |
|
65 |
+
# gradio.ImageEditor requires a diction
|
66 |
final_dict = {'background': final_image, 'layers': None, 'composite': final_image}
|
67 |
|
68 |
+
# Add generated image to version gallery
|
69 |
if(versions==None):
|
70 |
final_gallery = [image_editor['background'] ,final_image]
|
71 |
else:
|
|
|
78 |
gr.Markdown("""
|
79 |
# Inpainting Sketch Pad
|
80 |
by [Tony Assi](https://www.tonyassi.com/)
|
81 |
+
|
82 |
+
Please ❤️ this Space. I build custom AI apps for companies. <a href="mailto: tony.assi.media@gmail.com">Email me</a> for business inquiries.
|
83 |
""")
|
84 |
|
85 |
with gr.Row():
|