Spaces:
Running
Running
support mask
Browse files- app.py +6 -5
- opencvinpaint.py +3 -2
app.py
CHANGED
@@ -15,6 +15,7 @@ def sanitize_prompt(prompt):
|
|
15 |
#@spaces.GPU(duration=120)
|
16 |
def process_images(image, image2=None,inpaint_radius=3,blur_radius=25,edge_expand=8,inpaint_mode="Telea",progress=gr.Progress(track_tqdm=True)):
|
17 |
progress(0, desc="Start Inpainting")
|
|
|
18 |
# I'm not sure when this happen
|
19 |
if not isinstance(image, dict):
|
20 |
if image2 == None:
|
@@ -32,7 +33,7 @@ def process_images(image, image2=None,inpaint_radius=3,blur_radius=25,edge_expan
|
|
32 |
mask = image['layers'][0]
|
33 |
|
34 |
|
35 |
-
output = opencvinpaint.
|
36 |
|
37 |
return output,mask
|
38 |
|
@@ -58,13 +59,13 @@ css="""
|
|
58 |
"""
|
59 |
|
60 |
#css=css,
|
61 |
-
|
62 |
-
with
|
63 |
with gr.Column():
|
64 |
gr.HTML(read_file("demo_header.html"))
|
65 |
with gr.Row():
|
66 |
with gr.Column():
|
67 |
-
image = gr.ImageEditor(sources=['upload','clipboard'],transforms=[],image_mode='RGB', layers=False, elem_id="image_upload", type="pil", label="Upload",brush=gr.Brush(colors=["#
|
68 |
with gr.Row(elem_id="prompt-container", equal_height=False):
|
69 |
with gr.Row():
|
70 |
btn = gr.Button("Inpaint!", elem_id="run_button")
|
@@ -100,4 +101,4 @@ with demo_blocks as demo:
|
|
100 |
"""
|
101 |
)
|
102 |
|
103 |
-
|
|
|
15 |
#@spaces.GPU(duration=120)
|
16 |
def process_images(image, image2=None,inpaint_radius=3,blur_radius=25,edge_expand=8,inpaint_mode="Telea",progress=gr.Progress(track_tqdm=True)):
|
17 |
progress(0, desc="Start Inpainting")
|
18 |
+
print("process_images")
|
19 |
# I'm not sure when this happen
|
20 |
if not isinstance(image, dict):
|
21 |
if image2 == None:
|
|
|
33 |
mask = image['layers'][0]
|
34 |
|
35 |
|
36 |
+
output = opencvinpaint.process_cvinpaint(image["background"],mask,inpaint_radius,blur_radius,edge_expand,inpaint_mode)
|
37 |
|
38 |
return output,mask
|
39 |
|
|
|
59 |
"""
|
60 |
|
61 |
#css=css,
|
62 |
+
|
63 |
+
with gr.Blocks(css=css, elem_id="demo-container") as demo:
|
64 |
with gr.Column():
|
65 |
gr.HTML(read_file("demo_header.html"))
|
66 |
with gr.Row():
|
67 |
with gr.Column():
|
68 |
+
image = gr.ImageEditor(sources=['upload','clipboard'],transforms=[],image_mode='RGB', layers=False, elem_id="image_upload", type="pil", label="Upload",brush=gr.Brush(colors=["#fff"], color_mode="fixed"))
|
69 |
with gr.Row(elem_id="prompt-container", equal_height=False):
|
70 |
with gr.Row():
|
71 |
btn = gr.Button("Inpaint!", elem_id="run_button")
|
|
|
101 |
"""
|
102 |
)
|
103 |
|
104 |
+
demo.launch()
|
opencvinpaint.py
CHANGED
@@ -43,7 +43,8 @@ def blend_rgb_images(image1: np.ndarray, image2: np.ndarray, mask: np.ndarray) -
|
|
43 |
|
44 |
return blended.astype(np.uint8)
|
45 |
|
46 |
-
def
|
|
|
47 |
#print(blur_radius,",",edge_expand)
|
48 |
cv_image = pil_to_cv(image)
|
49 |
|
@@ -92,5 +93,5 @@ def process_image(image,mask_image,inpaint_radius,blur_radius,edge_expand,inpain
|
|
92 |
if __name__ == "__main__":
|
93 |
image = Image.open(sys.argv[1])
|
94 |
mask = Image.open(sys.argv[2])
|
95 |
-
output =
|
96 |
output.save(sys.argv[3])
|
|
|
43 |
|
44 |
return blended.astype(np.uint8)
|
45 |
|
46 |
+
def process_cvinpaint(image,mask_image,inpaint_radius,blur_radius,edge_expand,inpaint_mode):
|
47 |
+
print("process cvinpaint")
|
48 |
#print(blur_radius,",",edge_expand)
|
49 |
cv_image = pil_to_cv(image)
|
50 |
|
|
|
93 |
if __name__ == "__main__":
|
94 |
image = Image.open(sys.argv[1])
|
95 |
mask = Image.open(sys.argv[2])
|
96 |
+
output = process_cvinpaint(image,mask)
|
97 |
output.save(sys.argv[3])
|