Akjava commited on
Commit
8a56dc6
1 Parent(s): 3272647

add size check

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -32,6 +32,10 @@ def process_images(image, image2=None,inpaint_radius=3,blur_radius=25,edge_expan
32
  return image
33
  mask = image['layers'][0]
34
 
 
 
 
 
35
 
36
  output = opencvinpaint.process_cvinpaint(image["background"],mask,inpaint_radius,blur_radius,edge_expand,inpaint_mode)
37
 
@@ -65,7 +69,7 @@ with gr.Blocks(css=css, elem_id="demo-container") as demo:
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")
@@ -79,7 +83,7 @@ with gr.Blocks(css=css, elem_id="demo-container") as demo:
79
  modes = ["Telea", "Navier-Stokes"]
80
  inpaint_mode = gr.Dropdown(label="modes", choices=modes, value="Telea")
81
  with gr.Column():
82
- image_out = gr.Image(sources=[],label="Output", elem_id="output-img")
83
  mask_out = gr.Image(height=800,sources=[],label="Mask", elem_id="mask-img",format="jpeg")
84
 
85
 
 
32
  return image
33
  mask = image['layers'][0]
34
 
35
+ img_width,img_height = image["background"].size
36
+ mask_width, mask_height = mask.size
37
+ if img_width!=mask_width or img_height!=mask_height:
38
+ gr.Error(f"image size({img_width},{img_height}) must be same as mask size({mask_width},{mask_height})")
39
 
40
  output = opencvinpaint.process_cvinpaint(image["background"],mask,inpaint_radius,blur_radius,edge_expand,inpaint_mode)
41
 
 
69
  gr.HTML(read_file("demo_header.html"))
70
  with gr.Row():
71
  with gr.Column():
72
+ image = gr.ImageEditor(height=800,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"))
73
  with gr.Row(elem_id="prompt-container", equal_height=False):
74
  with gr.Row():
75
  btn = gr.Button("Inpaint!", elem_id="run_button")
 
83
  modes = ["Telea", "Navier-Stokes"]
84
  inpaint_mode = gr.Dropdown(label="modes", choices=modes, value="Telea")
85
  with gr.Column():
86
+ image_out = gr.Image(height=800,sources=[],label="Output", elem_id="output-img")
87
  mask_out = gr.Image(height=800,sources=[],label="Mask", elem_id="mask-img",format="jpeg")
88
 
89