Spaces:
Running
on
Zero
Running
on
Zero
Fabrice-TIERCELIN
commited on
This PR allows to optionally upload a pre-existing mask
Browse files
app.py
CHANGED
@@ -17,20 +17,23 @@ pipe = FluxInpaintPipeline.from_pretrained(
|
|
17 |
|
18 |
|
19 |
@spaces.GPU()
|
20 |
-
def process(input_image_editor, input_text, strength, progress=gr.Progress(track_tqdm=True)):
|
21 |
if not input_text:
|
22 |
gr.Info("Please enter a text prompt.")
|
23 |
return None
|
24 |
|
25 |
image = input_image_editor['background']
|
26 |
-
|
|
|
|
|
|
|
27 |
|
28 |
if not image:
|
29 |
gr.Info("Please upload an image.")
|
30 |
return None
|
31 |
|
32 |
if not mask_image:
|
33 |
-
gr.Info("Please draw a mask on the image.")
|
34 |
return None
|
35 |
|
36 |
width, height = image.size
|
@@ -70,6 +73,8 @@ with gr.Blocks() as demo:
|
|
70 |
step=0.01,
|
71 |
label="Strength"
|
72 |
)
|
|
|
|
|
73 |
submit_button_component = gr.Button(
|
74 |
value='Submit', variant='primary')
|
75 |
with gr.Column():
|
@@ -80,6 +85,7 @@ with gr.Blocks() as demo:
|
|
80 |
fn=process,
|
81 |
inputs=[
|
82 |
input_image_editor_component,
|
|
|
83 |
input_text_component,
|
84 |
strength_slider
|
85 |
],
|
|
|
17 |
|
18 |
|
19 |
@spaces.GPU()
|
20 |
+
def process(input_image_editor, uploaded_mask, input_text, strength, progress=gr.Progress(track_tqdm=True)):
|
21 |
if not input_text:
|
22 |
gr.Info("Please enter a text prompt.")
|
23 |
return None
|
24 |
|
25 |
image = input_image_editor['background']
|
26 |
+
if uploaded_mask is None:
|
27 |
+
mask_image = input_image_editor['layers'][0]
|
28 |
+
else:
|
29 |
+
mask_image = uploaded_mask
|
30 |
|
31 |
if not image:
|
32 |
gr.Info("Please upload an image.")
|
33 |
return None
|
34 |
|
35 |
if not mask_image:
|
36 |
+
gr.Info("Please draw or upload a mask on the image.")
|
37 |
return None
|
38 |
|
39 |
width, height = image.size
|
|
|
73 |
step=0.01,
|
74 |
label="Strength"
|
75 |
)
|
76 |
+
with gr.Accordion("Upload a mask", open = False):
|
77 |
+
uploaded_mask_component = gr.Image(label = "Already made mask (black pixels will be preserved, white pixels will be redrawn)", sources = ["upload"], type = "pil")
|
78 |
submit_button_component = gr.Button(
|
79 |
value='Submit', variant='primary')
|
80 |
with gr.Column():
|
|
|
85 |
fn=process,
|
86 |
inputs=[
|
87 |
input_image_editor_component,
|
88 |
+
uploaded_mask_component,
|
89 |
input_text_component,
|
90 |
strength_slider
|
91 |
],
|