Spaces:
Runtime error
Runtime error
Commit
路
172e9b7
1
Parent(s):
ffdb3e9
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,25 @@
|
|
1 |
-
import gradio as gr
|
2 |
import os
|
3 |
-
os.system('/usr/local/bin/python -m pip install --upgrade pip')
|
4 |
os.system("pip install opencv-python")
|
5 |
-
os.system("pip install
|
|
|
|
|
6 |
import cv2
|
7 |
import numpy as np
|
8 |
|
9 |
def image_to_silhouette(image):
|
10 |
-
|
11 |
-
|
12 |
|
13 |
-
|
14 |
-
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
|
22 |
-
|
23 |
|
24 |
# Crear interfaz de usuario con Gradio
|
25 |
interface = gr.Interface(fn=image_to_silhouette, inputs="image", outputs="image")
|
@@ -31,12 +31,18 @@ convert_button = gr.Button("Convertir")
|
|
31 |
|
32 |
# Funci贸n para manejar el evento de clic del bot贸n
|
33 |
def on_button_clicked(sender):
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
output_box.value = silhouette
|
40 |
|
41 |
-
#
|
42 |
-
interface.launch
|
|
|
|
|
1 |
import os
|
|
|
2 |
os.system("pip install opencv-python")
|
3 |
+
os.system("pip install gradio --upgrade")
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
import cv2
|
7 |
import numpy as np
|
8 |
|
9 |
def image_to_silhouette(image):
|
10 |
+
# Convertir imagen a escala de grises
|
11 |
+
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
12 |
|
13 |
+
# Aplicar bordes
|
14 |
+
edges = cv2.Canny(gray, 50, 150)
|
15 |
|
16 |
+
# Crear m谩scara con forma de silueta negra
|
17 |
+
silhouette = np.zeros_like(image)
|
18 |
+
silhouette[:,:,0] = edges
|
19 |
+
silhouette[:,:,1] = edges
|
20 |
+
silhouette[:,:,2] = edges
|
21 |
|
22 |
+
return silhouette
|
23 |
|
24 |
# Crear interfaz de usuario con Gradio
|
25 |
interface = gr.Interface(fn=image_to_silhouette, inputs="image", outputs="image")
|
|
|
31 |
|
32 |
# Funci贸n para manejar el evento de clic del bot贸n
|
33 |
def on_button_clicked(sender):
|
34 |
+
# Obtener imagen de la caja de entrada
|
35 |
+
image = input_box.value
|
36 |
+
|
37 |
+
# Convertir imagen a silueta y mostrar en la caja de salida
|
38 |
+
silhouette = image_to_silhouette(image)
|
39 |
+
output_box.value = silhouette
|
40 |
+
|
41 |
+
# A帽adir evento de clic al bot贸n
|
42 |
+
convert_button.on_click(on_button_clicked)
|
43 |
|
44 |
+
# A帽adir bot贸n a la interfaz
|
45 |
+
interface.sidebar.append(convert_button)
|
|
|
46 |
|
47 |
+
# Mostrar interfaz
|
48 |
+
interface.launch()
|