File size: 1,082 Bytes
13a751b
2136b2c
13a751b
 
 
649dc8d
13a751b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa9649d
cf29b6f
 
 
281204b
cf29b6f
281204b
cf29b6f
49e4d1e
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import gradio as gr
import numpy as np
import imageio
from PIL import Image

source_img = gr.Image(source="upload", type="numpy", tool="sketch", elem_id="source_container");
outputs = [gr.outputs.Image(type="file",label="output"),gr.outputs.Image(type="file",label="Mask")]
def resize(height,img):
  baseheight = height
  img = Image.open(img)
  hpercent = (baseheight/float(img.size[1]))
  wsize = int((float(img.size[0])*float(hpercent)))
  img = img.resize((wsize,baseheight), Image.Resampling.LANCZOS)
  return img

def predict(source_img):
    
    #print(sketch)
    #print(sketch.mode)
    #sketch_png = resize(512,source_img)
    #sketch_png.save('source.png')
    #print(sketch_png)
    imageio.imwrite("data.png", source_img["image"])
    imageio.imwrite("data_mask.png", source_img["mask"]) 
    
    src = resize(512, "data.png")
    src.save("src.png")
    mask = resize(512, "data_mask.png")  
    mask.save("mask.png")
    return src, mask

custom_css="style.css"

gr.Interface(fn=predict, inputs=source_img, outputs=outputs, css=custom_css).launch(enable_queue=True)