Spaces:
Runtime error
Runtime error
Commit
Β·
c9a8878
1
Parent(s):
ee0b2cb
Update app.py
Browse files
app.py
CHANGED
@@ -14,32 +14,18 @@ import rembg
|
|
14 |
from rembg import remove
|
15 |
|
16 |
|
17 |
-
def
|
18 |
img = Image.open(img)
|
19 |
img = np.array(img)
|
20 |
input_img = cv2.imread(img)
|
21 |
-
if input_img is None:
|
22 |
-
raise Exception("La imagen no se ha podido cargar correctamente.")
|
23 |
output = remove(input_img[:, :, [2,1,0]])
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
def silhouette(img):
|
28 |
-
input_img = cv2.imdecode(np.frombuffer(img, np.uint8), cv2.IMREAD_COLOR)
|
29 |
-
if input_img is None:
|
30 |
-
raise Exception("La imagen no se ha podido cargar correctamente.")
|
31 |
-
gray = cv2.cvtColor(input_img, cv2.COLOR_BGR2GRAY)
|
32 |
edges = cv2.Canny(gray, 50, 150)
|
33 |
contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
34 |
-
silhouette = np.zeros_like(
|
35 |
cv2.drawContours(silhouette, contours, -1, (255, 255, 255), 1)
|
36 |
return silhouette
|
37 |
|
38 |
-
def inference(img):
|
39 |
-
img = remove_background(img)
|
40 |
-
img = silhouette(img)
|
41 |
-
return img
|
42 |
-
|
43 |
# Crear interfaz de usuario con Gradio
|
44 |
gr.Interface(
|
45 |
inference,
|
|
|
14 |
from rembg import remove
|
15 |
|
16 |
|
17 |
+
def inference(img):
|
18 |
img = Image.open(img)
|
19 |
img = np.array(img)
|
20 |
input_img = cv2.imread(img)
|
|
|
|
|
21 |
output = remove(input_img[:, :, [2,1,0]])
|
22 |
+
gray = cv2.cvtColor(output, cv2.COLOR_BGR2GRAY)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
edges = cv2.Canny(gray, 50, 150)
|
24 |
contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
25 |
+
silhouette = np.zeros_like(output)
|
26 |
cv2.drawContours(silhouette, contours, -1, (255, 255, 255), 1)
|
27 |
return silhouette
|
28 |
|
|
|
|
|
|
|
|
|
|
|
29 |
# Crear interfaz de usuario con Gradio
|
30 |
gr.Interface(
|
31 |
inference,
|