Ahsen Khaliq commited on
Commit
19dac07
1 Parent(s): 8ce9b88

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -11,8 +11,11 @@ os.mkdir("data")
11
  os.mkdir("dataout")
12
  model = hub.Module(name='U2Net')
13
  def infer(img):
 
 
 
 
14
  img.save("./data/data.png")
15
- os.system("ls data")
16
  result = model.Segmentation(
17
  images=[cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)],
18
  paths=None,
@@ -22,12 +25,10 @@ def infer(img):
22
  visualization=True)
23
  im = Image.fromarray(result[0]['mask'])
24
  im.save("./data/data_mask.png")
25
- os.system("ls data")
26
  os.system('python predict.py model.path=/home/user/app/big-lama/ indir=/home/user/app/data/ outdir=/home/user/app/dataout/ device=cpu')
27
- os.system("ls dataout")
28
- return "./dataout/data_mask.png"
29
  inputs = gr.inputs.Image(type='pil', label="Original Image")
30
- outputs = gr.outputs.Image(type="file",label="output")
31
  title = "LaMa Image Inpainting"
32
  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"
33
  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>"
 
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,
 
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>"