Spaces:
Runtime error
Runtime error
import os | |
os.system('/usr/local/bin/python -m pip install --upgrade pip') | |
os.system("pip install opencv-python") | |
os.system("pip install pillow") | |
os.system("pip install rembg") | |
import gradio as gr | |
import cv2 | |
import numpy as np | |
from PIL import Image | |
import rembg | |
from rembg import remove | |
def inference(img): | |
img = Image.open(img) | |
img = np.array(img) | |
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
edges = cv2.Canny(gray, 50, 150) | |
contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) | |
silhouette = np.zeros_like(img) | |
result = cv2.drawContours(silhouette, contours, -1, (255, 255, 255), 1) | |
output = remove_background(result) | |
return output | |
def remove_background(result): | |
output = remove(result) | |
return output | |
gr.Interface( | |
inference, | |
gr.inputs.Image(type="filepath", label="Input"), | |
gr.outputs.Image(type="numpy", label="Output"), | |
title="Convertir a silueta", | |
description="Ingresa una imagen para convertirla a silueta", | |
article="", | |
css="Footer {visibility: hidden}" | |
).launch() |