Spaces:
Running
on
Zero
Running
on
Zero
This PR allows to upload existing mask
#2
by
Fabrice-TIERCELIN
- opened
app.py
CHANGED
@@ -101,6 +101,7 @@ def process(
|
|
101 |
randomize_seed_checkbox: bool,
|
102 |
strength_slider: float,
|
103 |
num_inference_steps_slider: int,
|
|
|
104 |
progress=gr.Progress(track_tqdm=True)
|
105 |
):
|
106 |
if not input_text:
|
@@ -108,14 +109,17 @@ def process(
|
|
108 |
return None, None
|
109 |
|
110 |
image = input_image_editor['background']
|
111 |
-
|
|
|
|
|
|
|
112 |
|
113 |
if not image:
|
114 |
gr.Info("Please upload an image.")
|
115 |
return None, None
|
116 |
|
117 |
if not mask:
|
118 |
-
gr.Info("Please draw a mask on the image.")
|
119 |
return None, None
|
120 |
|
121 |
width, height = resize_image_dimensions(original_resolution_wh=image.size)
|
@@ -151,6 +155,9 @@ with gr.Blocks() as demo:
|
|
151 |
layers=False,
|
152 |
brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed"))
|
153 |
|
|
|
|
|
|
|
154 |
with gr.Row():
|
155 |
input_text_component = gr.Text(
|
156 |
label="Prompt",
|
@@ -211,7 +218,8 @@ with gr.Blocks() as demo:
|
|
211 |
# seed_slicer_component,
|
212 |
# randomize_seed_checkbox_component,
|
213 |
# strength_slider_component,
|
214 |
-
# num_inference_steps_slider_component
|
|
|
215 |
# ],
|
216 |
# outputs=[
|
217 |
# output_image_component,
|
@@ -229,7 +237,8 @@ with gr.Blocks() as demo:
|
|
229 |
seed_slicer_component,
|
230 |
randomize_seed_checkbox_component,
|
231 |
strength_slider_component,
|
232 |
-
num_inference_steps_slider_component
|
|
|
233 |
],
|
234 |
outputs=[
|
235 |
output_image_component,
|
|
|
101 |
randomize_seed_checkbox: bool,
|
102 |
strength_slider: float,
|
103 |
num_inference_steps_slider: int,
|
104 |
+
uploaded_mask: Image.Image,
|
105 |
progress=gr.Progress(track_tqdm=True)
|
106 |
):
|
107 |
if not input_text:
|
|
|
109 |
return None, None
|
110 |
|
111 |
image = input_image_editor['background']
|
112 |
+
if uploaded_mask is None:
|
113 |
+
mask = input_image_editor['layers'][0]
|
114 |
+
else:
|
115 |
+
mask = uploaded_mask
|
116 |
|
117 |
if not image:
|
118 |
gr.Info("Please upload an image.")
|
119 |
return None, None
|
120 |
|
121 |
if not mask:
|
122 |
+
gr.Info("Please draw a mask on the image or upload a mask.")
|
123 |
return None, None
|
124 |
|
125 |
width, height = resize_image_dimensions(original_resolution_wh=image.size)
|
|
|
155 |
layers=False,
|
156 |
brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed"))
|
157 |
|
158 |
+
with gr.Accordion("Upload a mask", open = False):
|
159 |
+
uploaded_mask_component = gr.Image(label = "Already made mask (white pixels will be preserved, black pixels will be redrawn)", sources = ["upload"], type = "pil")
|
160 |
+
|
161 |
with gr.Row():
|
162 |
input_text_component = gr.Text(
|
163 |
label="Prompt",
|
|
|
218 |
# seed_slicer_component,
|
219 |
# randomize_seed_checkbox_component,
|
220 |
# strength_slider_component,
|
221 |
+
# num_inference_steps_slider_component,
|
222 |
+
# uploaded_mask_component
|
223 |
# ],
|
224 |
# outputs=[
|
225 |
# output_image_component,
|
|
|
237 |
seed_slicer_component,
|
238 |
randomize_seed_checkbox_component,
|
239 |
strength_slider_component,
|
240 |
+
num_inference_steps_slider_component,
|
241 |
+
uploaded_mask_component
|
242 |
],
|
243 |
outputs=[
|
244 |
output_image_component,
|