akhaliq HF staff commited on
Commit
0c217d4
·
1 Parent(s): 877d1ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -12,7 +12,9 @@ os.rename("best.ckpt", "models/best.ckpt")
12
  os.mkdir("dataout")
13
  model = hub.Module(name='U2Net')
14
  def infer(img,option):
15
- img = ImageOps.contain(img["image"], (700,700))
 
 
16
  width, height = img.size
17
  img.save("./data/data.png")
18
  if option == "automatic (U2net)":
@@ -25,13 +27,12 @@ def infer(img,option):
25
  visualization=True)
26
  im = Image.fromarray(result[0]['mask'])
27
  else:
28
- mask = img["mask"].resize((width,height))
29
- im = mask
30
- im.save("./data/data_mask.png")
31
  os.system('python predict.py model.path=/home/user/app/ indir=/home/user/app/data/ outdir=/home/user/app/dataout/ device=cpu')
32
- return "./dataout/data_mask.png",im
33
 
34
- inputs = [gr.inputs.Image(source="upload",tool="sketch", label="Input", type="pil"),gr.inputs.Radio(choices=["automatic (U2net)","manual"], type="value", default="manual", label="Masking option")]
35
  outputs = [gr.outputs.Image(type="file",label="output"),gr.outputs.Image(type="pil",label="Mask")]
36
  title = "LaMa Image Inpainting"
37
  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"
 
12
  os.mkdir("dataout")
13
  model = hub.Module(name='U2Net')
14
  def infer(img,option):
15
+ img = Image.fromarray(img["image"])
16
+ mask = Image.fromarray(img["mask"])
17
+ img = ImageOps.contain(img, (700,700))
18
  width, height = img.size
19
  img.save("./data/data.png")
20
  if option == "automatic (U2net)":
 
27
  visualization=True)
28
  im = Image.fromarray(result[0]['mask'])
29
  else:
30
+ mask = mask.resize((width,height))
31
+ mask.save("./data/data_mask.png")
 
32
  os.system('python predict.py model.path=/home/user/app/ indir=/home/user/app/data/ outdir=/home/user/app/dataout/ device=cpu')
33
+ return "./dataout/data_mask.png",mask
34
 
35
+ inputs = [gr.inputs.Image(source="upload",tool="sketch", label="Input"),gr.inputs.Radio(choices=["automatic (U2net)","manual"], type="value", default="manual", label="Masking option")]
36
  outputs = [gr.outputs.Image(type="file",label="output"),gr.outputs.Image(type="pil",label="Mask")]
37
  title = "LaMa Image Inpainting"
38
  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"