|
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): |
|
|
|
|
|
|
|
|
|
|
|
|
|
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) |