Spaces:
Running
on
Zero
Running
on
Zero
Fabrice-TIERCELIN
commited on
Commit
•
208244e
1
Parent(s):
73ed8b7
This PR allows to upload existing mask
Browse filesClick on _Merge_ to add this feature.
I have rewriten my PR for this space. Perhaps you should make this space _private_.
app.py
CHANGED
@@ -43,7 +43,8 @@ EXAMPLES = [
|
|
43 |
42,
|
44 |
False,
|
45 |
0.85,
|
46 |
-
20
|
|
|
47 |
],
|
48 |
[
|
49 |
{
|
@@ -58,7 +59,8 @@ EXAMPLES = [
|
|
58 |
42,
|
59 |
False,
|
60 |
0.9,
|
61 |
-
20
|
|
|
62 |
]
|
63 |
]
|
64 |
|
@@ -163,24 +165,28 @@ def process(
|
|
163 |
seed_slicer: int,
|
164 |
randomize_seed_checkbox: bool,
|
165 |
strength_slider: float,
|
166 |
-
num_inference_steps_slider: int
|
|
|
167 |
):
|
168 |
if not inpainting_prompt_text:
|
169 |
gr.Info("Please enter inpainting text prompt.")
|
170 |
return None, None
|
171 |
|
172 |
image_path = input_image_editor['background']
|
173 |
-
mask_path = input_image_editor['layers'][0]
|
174 |
|
175 |
image = Image.open(image_path)
|
176 |
-
|
|
|
|
|
|
|
|
|
177 |
|
178 |
if not image:
|
179 |
gr.Info("Please upload an image.")
|
180 |
return None, None
|
181 |
|
182 |
if is_mask_empty(mask) and not masking_prompt_text:
|
183 |
-
gr.Info("Please draw a mask or enter a masking prompt.")
|
184 |
return None, None
|
185 |
|
186 |
if not is_mask_empty(mask) and masking_prompt_text:
|
@@ -240,6 +246,9 @@ with gr.Blocks() as demo:
|
|
240 |
submit_button_component = gr.Button(
|
241 |
value='Submit', variant='primary', scale=0)
|
242 |
|
|
|
|
|
|
|
243 |
with gr.Accordion("Advanced Settings", open=False):
|
244 |
masking_prompt_text_component = gr.Text(
|
245 |
label="Masking prompt",
|
@@ -320,7 +329,8 @@ with gr.Blocks() as demo:
|
|
320 |
seed_slicer_component,
|
321 |
randomize_seed_checkbox_component,
|
322 |
strength_slider_component,
|
323 |
-
num_inference_steps_slider_component
|
|
|
324 |
],
|
325 |
outputs=[
|
326 |
output_image_component,
|
@@ -341,7 +351,8 @@ with gr.Blocks() as demo:
|
|
341 |
seed_slicer_component,
|
342 |
randomize_seed_checkbox_component,
|
343 |
strength_slider_component,
|
344 |
-
num_inference_steps_slider_component
|
|
|
345 |
],
|
346 |
outputs=[
|
347 |
output_image_component,
|
|
|
43 |
42,
|
44 |
False,
|
45 |
0.85,
|
46 |
+
20,
|
47 |
+
None
|
48 |
],
|
49 |
[
|
50 |
{
|
|
|
59 |
42,
|
60 |
False,
|
61 |
0.9,
|
62 |
+
20,
|
63 |
+
None
|
64 |
]
|
65 |
]
|
66 |
|
|
|
165 |
seed_slicer: int,
|
166 |
randomize_seed_checkbox: bool,
|
167 |
strength_slider: float,
|
168 |
+
num_inference_steps_slider: int,
|
169 |
+
uploaded_mask: Image.Image
|
170 |
):
|
171 |
if not inpainting_prompt_text:
|
172 |
gr.Info("Please enter inpainting text prompt.")
|
173 |
return None, None
|
174 |
|
175 |
image_path = input_image_editor['background']
|
|
|
176 |
|
177 |
image = Image.open(image_path)
|
178 |
+
if uploaded_mask is None:
|
179 |
+
mask_path = input_image_editor['layers'][0]
|
180 |
+
mask = Image.open(mask_path)
|
181 |
+
else:
|
182 |
+
mask = uploaded_mask
|
183 |
|
184 |
if not image:
|
185 |
gr.Info("Please upload an image.")
|
186 |
return None, None
|
187 |
|
188 |
if is_mask_empty(mask) and not masking_prompt_text:
|
189 |
+
gr.Info("Please draw a mask, upload a mask or enter a masking prompt.")
|
190 |
return None, None
|
191 |
|
192 |
if not is_mask_empty(mask) and masking_prompt_text:
|
|
|
246 |
submit_button_component = gr.Button(
|
247 |
value='Submit', variant='primary', scale=0)
|
248 |
|
249 |
+
with gr.Accordion("Upload a mask", open = False):
|
250 |
+
uploaded_mask_component = gr.Image(label = "Already made mask (white pixels will be preserved, black pixels will be redrawn)", sources = ["upload"], type = "pil")
|
251 |
+
|
252 |
with gr.Accordion("Advanced Settings", open=False):
|
253 |
masking_prompt_text_component = gr.Text(
|
254 |
label="Masking prompt",
|
|
|
329 |
seed_slicer_component,
|
330 |
randomize_seed_checkbox_component,
|
331 |
strength_slider_component,
|
332 |
+
num_inference_steps_slider_component,
|
333 |
+
uploaded_mask_component
|
334 |
],
|
335 |
outputs=[
|
336 |
output_image_component,
|
|
|
351 |
seed_slicer_component,
|
352 |
randomize_seed_checkbox_component,
|
353 |
strength_slider_component,
|
354 |
+
num_inference_steps_slider_component,
|
355 |
+
uploaded_mask_component
|
356 |
],
|
357 |
outputs=[
|
358 |
output_image_component,
|