Spaces:
Runtime error
Runtime error
Commit
Β·
65f5da2
1
Parent(s):
d64cb62
Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,134 @@
|
|
1 |
import os
|
|
|
|
|
|
|
|
|
2 |
os.system('/usr/local/bin/python -m pip install --upgrade pip')
|
|
|
|
|
3 |
os.system("pip install opencv-python")
|
|
|
|
|
4 |
os.system("pip install pillow")
|
|
|
|
|
5 |
os.system("pip install rembg")
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
import gradio as gr
|
|
|
|
|
8 |
import cv2
|
|
|
|
|
9 |
import numpy as np
|
|
|
|
|
10 |
from PIL import Image
|
|
|
|
|
11 |
from io import BytesIO
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
import rembg
|
|
|
|
|
14 |
from rembg import remove
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
def inference(img):
|
|
|
|
|
17 |
input_img = cv2.imread(img)
|
|
|
|
|
18 |
output = remove(input_img[:, :, [2,1,0]])
|
|
|
|
|
19 |
return output
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
def inference(img):
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
# Crear interfaz de usuario con Gradio
|
|
|
|
|
34 |
gr.Interface(
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
).launch()
|
43 |
|
|
|
|
1 |
import os
|
2 |
+
|
3 |
+
|
4 |
+
|
5 |
+
|
6 |
os.system('/usr/local/bin/python -m pip install --upgrade pip')
|
7 |
+
|
8 |
+
|
9 |
os.system("pip install opencv-python")
|
10 |
+
|
11 |
+
|
12 |
os.system("pip install pillow")
|
13 |
+
|
14 |
+
|
15 |
os.system("pip install rembg")
|
16 |
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
import gradio as gr
|
24 |
+
|
25 |
+
|
26 |
import cv2
|
27 |
+
|
28 |
+
|
29 |
import numpy as np
|
30 |
+
|
31 |
+
|
32 |
from PIL import Image
|
33 |
+
|
34 |
+
|
35 |
from io import BytesIO
|
36 |
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
|
42 |
+
|
43 |
import rembg
|
44 |
+
|
45 |
+
|
46 |
from rembg import remove
|
47 |
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
def inference(img):
|
55 |
+
|
56 |
+
|
57 |
input_img = cv2.imread(img)
|
58 |
+
|
59 |
+
|
60 |
output = remove(input_img[:, :, [2,1,0]])
|
61 |
+
|
62 |
+
|
63 |
return output
|
64 |
|
65 |
+
|
66 |
+
|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
+
|
71 |
def inference(img):
|
72 |
+
|
73 |
+
|
74 |
+
input_img = cv2.imread(img)
|
75 |
+
|
76 |
+
|
77 |
+
gray = cv2.cvtColor(input_img, cv2.COLOR_BGR2GRAY)
|
78 |
+
|
79 |
+
|
80 |
+
edges = cv2.Canny(gray, 50, 150)
|
81 |
+
|
82 |
+
|
83 |
+
contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
84 |
+
|
85 |
+
|
86 |
+
silhouette = np.zeros_like(input_img)
|
87 |
+
|
88 |
+
|
89 |
+
cv2.drawContours(silhouette, contours, -1, (255, 255, 255), 1)
|
90 |
+
|
91 |
+
|
92 |
+
return silhouette
|
93 |
+
|
94 |
+
|
95 |
+
|
96 |
+
|
97 |
+
|
98 |
+
|
99 |
+
|
100 |
+
|
101 |
+
|
102 |
+
|
103 |
+
|
104 |
|
105 |
# Crear interfaz de usuario con Gradio
|
106 |
+
|
107 |
+
|
108 |
gr.Interface(
|
109 |
+
|
110 |
+
|
111 |
+
inference,
|
112 |
+
|
113 |
+
|
114 |
+
gr.inputs.Image(type="filepath", label="Input"),
|
115 |
+
|
116 |
+
|
117 |
+
gr.outputs.Image(type="numpy", label="Output"),
|
118 |
+
|
119 |
+
|
120 |
+
title="Convertir a silueta",
|
121 |
+
|
122 |
+
|
123 |
+
description="Ingresa una imagen para convertirla a silueta",
|
124 |
+
|
125 |
+
|
126 |
+
article="",
|
127 |
+
|
128 |
+
|
129 |
+
css="Footer {visibility: hidden}"
|
130 |
+
|
131 |
+
|
132 |
).launch()
|
133 |
|
134 |
+
|