Spaces:
Runtime error
Runtime error
praeclarumjj3
commited on
Commit
•
9e43b47
1
Parent(s):
4530503
Add mask drawing
Browse files- app.py +28 -16
- test_512/a_overlay.png +0 -0
- test_512/b_overlay.png +0 -0
- test_512/c_overlay.png +0 -0
- test_512/d_overlay.png +0 -0
- test_512/e_overlay.png +0 -0
- test_512/f_overlay.png +0 -0
- test_512/g_overlay.png +0 -0
- test_512/h_overlay.png +0 -0
- test_512/i_overlay.png +0 -0
app.py
CHANGED
@@ -76,12 +76,20 @@ def inpaint(input_img, mask, option):
|
|
76 |
mask = Image.fromarray(result[0]['mask'])
|
77 |
else:
|
78 |
mask = mask.resize((width,height))
|
79 |
-
|
80 |
-
|
|
|
81 |
input_img = input_img.resize((512, 512))
|
82 |
mask = mask.resize((512, 512))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
-
mask = mask.convert('L')
|
85 |
mask = np.array(mask) / 255.
|
86 |
mask_tensor = torch.from_numpy(mask).to(torch.float32)
|
87 |
mask_tensor = mask_tensor.unsqueeze(0)
|
@@ -106,30 +114,34 @@ def inpaint(input_img, mask, option):
|
|
106 |
gradio_inputs = [gr.inputs.Image(type='pil',
|
107 |
tool=None,
|
108 |
label="Input Image"),
|
109 |
-
gr.inputs.Image(type='pil',source="canvas", label="Mask", invert_colors=True),
|
|
|
|
|
|
|
110 |
gr.inputs.Radio(choices=["Automatic", "Manual"], type="value", default="Manual", label="Masking Choice")
|
111 |
]
|
112 |
|
113 |
gradio_outputs = [gr.outputs.Image(label='Image with Hole'),
|
114 |
gr.outputs.Image(label='Inpainted Image')]
|
115 |
|
116 |
-
examples = [['test_512/person512.png', 'test_512/
|
117 |
-
['test_512/a_org.png', 'test_512/
|
118 |
-
['test_512/
|
119 |
-
['test_512/
|
120 |
-
['test_512/d_org.png', 'test_512/
|
121 |
-
['test_512/e_org.png', 'test_512/
|
122 |
-
['test_512/f_org.png', 'test_512/
|
123 |
-
['test_512/g_org.png', 'test_512/
|
124 |
-
['test_512/h_org.png', 'test_512/
|
125 |
-
['test_512/i_org.png', 'test_512/
|
126 |
|
127 |
title = "FcF-Inpainting"
|
128 |
description = "[Note: Queue time may take upto 20 seconds! The image and mask are resized to 512x512 before inpainting.] To use FcF-Inpainting: \n \
|
129 |
(1) Upload an Image; \n \
|
130 |
-
(
|
|
|
131 |
(3) Click on Submit and witness the MAGIC! 🪄 ✨ ✨"
|
132 |
-
article = "<p style='text-align: center'><a href='https://
|
133 |
|
134 |
css = ".image-preview {height: 32rem; width: auto;} .output-image {height: 32rem; width: auto;} .panel-buttons { display: flex; flex-direction: row;}"
|
135 |
|
|
|
76 |
mask = Image.fromarray(result[0]['mask'])
|
77 |
else:
|
78 |
mask = mask.resize((width,height))
|
79 |
+
mask = mask.convert('L')
|
80 |
+
|
81 |
+
if width != 512 or height != 512:
|
82 |
input_img = input_img.resize((512, 512))
|
83 |
mask = mask.resize((512, 512))
|
84 |
+
|
85 |
+
|
86 |
+
if option == 'Manual':
|
87 |
+
mask = (np.array(mask) - np.array(input_img.convert('L'))) > 0.
|
88 |
+
mask = mask * 1.
|
89 |
+
kernel = np.ones((5, 5), np.uint8)
|
90 |
+
mask = cv2.dilate(mask, kernel)
|
91 |
+
mask = mask * 255.
|
92 |
|
|
|
93 |
mask = np.array(mask) / 255.
|
94 |
mask_tensor = torch.from_numpy(mask).to(torch.float32)
|
95 |
mask_tensor = mask_tensor.unsqueeze(0)
|
|
|
114 |
gradio_inputs = [gr.inputs.Image(type='pil',
|
115 |
tool=None,
|
116 |
label="Input Image"),
|
117 |
+
# gr.inputs.Image(type='pil',source="canvas", label="Mask", invert_colors=True),
|
118 |
+
gr.inputs.Image(type='pil',
|
119 |
+
tool="editor",
|
120 |
+
label="Mask"),
|
121 |
gr.inputs.Radio(choices=["Automatic", "Manual"], type="value", default="Manual", label="Masking Choice")
|
122 |
]
|
123 |
|
124 |
gradio_outputs = [gr.outputs.Image(label='Image with Hole'),
|
125 |
gr.outputs.Image(label='Inpainted Image')]
|
126 |
|
127 |
+
examples = [['test_512/person512.png', 'test_512/person512.png', 'Automatic'],
|
128 |
+
['test_512/a_org.png', 'test_512/a_overlay.png', 'Manual'],
|
129 |
+
['test_512/b_org.png', 'test_512/b_overlay.png', 'Manual'],
|
130 |
+
['test_512/c_org.png', 'test_512/c_overlay.png', 'Manual'],
|
131 |
+
['test_512/d_org.png', 'test_512/d_overlay.png', 'Manual'],
|
132 |
+
['test_512/e_org.png', 'test_512/e_overlay.png', 'Manual'],
|
133 |
+
['test_512/f_org.png', 'test_512/f_overlay.png', 'Manual'],
|
134 |
+
['test_512/g_org.png', 'test_512/g_overlay.png', 'Manual'],
|
135 |
+
['test_512/h_org.png', 'test_512/h_overlay.png', 'Manual'],
|
136 |
+
['test_512/i_org.png', 'test_512/i_overlay.png', 'Manual']]
|
137 |
|
138 |
title = "FcF-Inpainting"
|
139 |
description = "[Note: Queue time may take upto 20 seconds! The image and mask are resized to 512x512 before inpainting.] To use FcF-Inpainting: \n \
|
140 |
(1) Upload an Image; \n \
|
141 |
+
(2a) Draw (Manual) a Mask using the brush (click on the edit option in the top right of the Mask View) \n \
|
142 |
+
(2b) You can also generate a mask using U2Net by selecting the Automatic option; \n \
|
143 |
(3) Click on Submit and witness the MAGIC! 🪄 ✨ ✨"
|
144 |
+
article = "<p style='text-align: center'><a href='https://github.com/SHI-Labs/FcF-Inpainting' target='_blank'> Keys to Better Image Inpainting: Structure and Texture Go Hand in Hand</a> | <a href='https://github.com/SHI-Labs/FcF-Inpainting' target='_blank'>Github Repo</a></p>"
|
145 |
|
146 |
css = ".image-preview {height: 32rem; width: auto;} .output-image {height: 32rem; width: auto;} .panel-buttons { display: flex; flex-direction: row;}"
|
147 |
|
test_512/a_overlay.png
ADDED
test_512/b_overlay.png
ADDED
test_512/c_overlay.png
ADDED
test_512/d_overlay.png
ADDED
test_512/e_overlay.png
ADDED
test_512/f_overlay.png
ADDED
test_512/g_overlay.png
ADDED
test_512/h_overlay.png
ADDED
test_512/i_overlay.png
ADDED