File size: 1,073 Bytes
7ce944b
092ed82
8131498
291c9e6
50e4934
65f5da2
172e9b7
f508a4a
 
a7069c4
65f5da2
50e4934
 
65f5da2
8f8598a
50e4934
806ce40
8f8598a
 
 
 
 
988ed53
 
2fbb632
 
 
 
6b3f326
 
a7069c4
65f5da2
 
 
 
 
 
 
50e4934
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
35
36
37
38
39
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()