Ahsen Khaliq commited on
Commit
03898c7
1 Parent(s): 19dac07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -10,25 +10,28 @@ import numpy as np
10
  os.mkdir("data")
11
  os.mkdir("dataout")
12
  model = hub.Module(name='U2Net')
13
- def infer(img):
14
  basewidth = 600
15
  wpercent = (basewidth/float(img.size[0]))
16
  hsize = int((float(img.size[1])*float(wpercent)))
17
  img = img.resize((basewidth,hsize), Image.ANTIALIAS)
18
  img.save("./data/data.png")
19
- result = model.Segmentation(
20
- images=[cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)],
21
- paths=None,
22
- batch_size=1,
23
- input_size=320,
24
- output_dir='output',
25
- visualization=True)
26
- im = Image.fromarray(result[0]['mask'])
 
 
 
27
  im.save("./data/data_mask.png")
28
  os.system('python predict.py model.path=/home/user/app/big-lama/ indir=/home/user/app/data/ outdir=/home/user/app/dataout/ device=cpu')
29
  return "./dataout/data_mask.png",im
30
- inputs = gr.inputs.Image(type='pil', label="Original Image")
31
- outputs = [gr.outputs.Image(type="file",label="output"),gr.outputs.Image(type="pil",label="Mask from U^2Net")]
32
  title = "LaMa Image Inpainting"
33
  description = "Gradio demo for LaMa: Resolution-robust Large Mask Inpainting with Fourier Convolutions. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below. Masks are generated by U^2net"
34
  article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2109.07161' target='_blank'>Resolution-robust Large Mask Inpainting with Fourier Convolutions</a> | <a href='https://github.com/saic-mdal/lama' target='_blank'>Github Repo</a></p>"
 
10
  os.mkdir("data")
11
  os.mkdir("dataout")
12
  model = hub.Module(name='U2Net')
13
+ def infer(img,mask,option):
14
  basewidth = 600
15
  wpercent = (basewidth/float(img.size[0]))
16
  hsize = int((float(img.size[1])*float(wpercent)))
17
  img = img.resize((basewidth,hsize), Image.ANTIALIAS)
18
  img.save("./data/data.png")
19
+ if option == "automatic (U2net)"
20
+ result = model.Segmentation(
21
+ images=[cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)],
22
+ paths=None,
23
+ batch_size=1,
24
+ input_size=320,
25
+ output_dir='output',
26
+ visualization=True)
27
+ im = Image.fromarray(result[0]['mask'])
28
+ else:
29
+ im = mask
30
  im.save("./data/data_mask.png")
31
  os.system('python predict.py model.path=/home/user/app/big-lama/ indir=/home/user/app/data/ outdir=/home/user/app/dataout/ device=cpu')
32
  return "./dataout/data_mask.png",im
33
+ inputs = [gr.inputs.Image(type='pil', label="Original Image"),gr.inputs.Image(type='pil',source="canvas", label="Mask",optional=True),gr.inputs.Radio(choices=["automatic (U2net)","manual"], type="value", default="manual", label="Masking option")]
34
+ outputs = [gr.outputs.Image(type="file",label="output"),gr.outputs.Image(type="pil",label="Mask")]
35
  title = "LaMa Image Inpainting"
36
  description = "Gradio demo for LaMa: Resolution-robust Large Mask Inpainting with Fourier Convolutions. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below. Masks are generated by U^2net"
37
  article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2109.07161' target='_blank'>Resolution-robust Large Mask Inpainting with Fourier Convolutions</a> | <a href='https://github.com/saic-mdal/lama' target='_blank'>Github Repo</a></p>"