Spaces:
Runtime error
Runtime error
Fabrice-TIERCELIN
commited on
Commit
•
91805f7
1
Parent(s):
21fd598
This PR allows to upload existing mask
Browse files
app.py
CHANGED
@@ -48,7 +48,8 @@ EXAMPLES = [
|
|
48 |
42,
|
49 |
False,
|
50 |
0.85,
|
51 |
-
30
|
|
|
52 |
],
|
53 |
[
|
54 |
{
|
@@ -60,7 +61,8 @@ EXAMPLES = [
|
|
60 |
42,
|
61 |
False,
|
62 |
0.85,
|
63 |
-
30
|
|
|
64 |
]
|
65 |
]
|
66 |
|
@@ -101,6 +103,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 +111,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)
|
@@ -162,6 +168,9 @@ with gr.Blocks() as demo:
|
|
162 |
submit_button_component = gr.Button(
|
163 |
value='Submit', variant='primary', scale=0)
|
164 |
|
|
|
|
|
|
|
165 |
with gr.Accordion("Advanced Settings", open=False):
|
166 |
seed_slicer_component = gr.Slider(
|
167 |
label="Seed",
|
@@ -211,7 +220,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 +239,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,
|
|
|
48 |
42,
|
49 |
False,
|
50 |
0.85,
|
51 |
+
30,
|
52 |
+
None
|
53 |
],
|
54 |
[
|
55 |
{
|
|
|
61 |
42,
|
62 |
False,
|
63 |
0.85,
|
64 |
+
30,
|
65 |
+
None
|
66 |
]
|
67 |
]
|
68 |
|
|
|
103 |
randomize_seed_checkbox: bool,
|
104 |
strength_slider: float,
|
105 |
num_inference_steps_slider: int,
|
106 |
+
uploaded_mask: Image.Image,
|
107 |
progress=gr.Progress(track_tqdm=True)
|
108 |
):
|
109 |
if not input_text:
|
|
|
111 |
return None, None
|
112 |
|
113 |
image = input_image_editor['background']
|
114 |
+
if uploaded_mask is None:
|
115 |
+
mask = input_image_editor['layers'][0]
|
116 |
+
else:
|
117 |
+
mask = uploaded_mask
|
118 |
|
119 |
if not image:
|
120 |
gr.Info("Please upload an image.")
|
121 |
return None, None
|
122 |
|
123 |
if not mask:
|
124 |
+
gr.Info("Please draw a mask on the image or upload a mask.")
|
125 |
return None, None
|
126 |
|
127 |
width, height = resize_image_dimensions(original_resolution_wh=image.size)
|
|
|
168 |
submit_button_component = gr.Button(
|
169 |
value='Submit', variant='primary', scale=0)
|
170 |
|
171 |
+
with gr.Accordion("Upload a mask", open = False):
|
172 |
+
uploaded_mask_component = gr.Image(label = "Already made mask (white pixels will be preserved, black pixels will be redrawn)", sources = ["upload"], type = "pil")
|
173 |
+
|
174 |
with gr.Accordion("Advanced Settings", open=False):
|
175 |
seed_slicer_component = gr.Slider(
|
176 |
label="Seed",
|
|
|
220 |
seed_slicer_component,
|
221 |
randomize_seed_checkbox_component,
|
222 |
strength_slider_component,
|
223 |
+
num_inference_steps_slider_component,
|
224 |
+
uploaded_mask_component
|
225 |
],
|
226 |
outputs=[
|
227 |
output_image_component,
|
|
|
239 |
seed_slicer_component,
|
240 |
randomize_seed_checkbox_component,
|
241 |
strength_slider_component,
|
242 |
+
num_inference_steps_slider_component,
|
243 |
+
uploaded_mask_component
|
244 |
],
|
245 |
outputs=[
|
246 |
output_image_component,
|