Spaces:
Build error
Build error
import os | |
os.system("wget https://huggingface.co/akhaliq/lama/resolve/main/best.ckpt") | |
os.system("pip install imageio") | |
os.system("pip install albumentations==0.5.2") | |
import cv2 | |
import paddlehub as hub | |
import gradio as gr | |
import torch | |
from PIL import Image, ImageOps | |
import numpy as np | |
import imageio | |
os.mkdir("data") | |
os.rename("best.ckpt", "models/best.ckpt") | |
os.mkdir("dataout") | |
model = hub.Module(name='U2Net') | |
def infer(img, mask): | |
img = Image.open(img) | |
mask = Image.open(mask) | |
inverted_mask = ImageOps.invert(mask) | |
imageio.imwrite("./data/data.png", img) | |
imageio.imwrite("./data/data_mask.png", inverted_mask) | |
os.system('python predict.py model.path=/home/user/app/ indir=/home/user/app/data/ outdir=/home/user/app/dataout/ device=cpu') | |
return "./dataout/data_mask.png", "./data/data_mask.png" | |
inputs = [gr.Image(label="Input", source="upload", type="filepath"), | |
gr.Image(label="Mask", source="upload", type="filepath")] | |
outputs = [gr.outputs.Image(type="file", label="output"), | |
gr.outputs.Image(type="file", label="Mask")] | |
title = "LaMa Image Inpainting" | |
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" | |
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>" | |
gr.Interface(infer, inputs, outputs, title=title, | |
description=description, article=article).launch() | |