Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,37 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
-
import matplotlib.pyplot as plt
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
plt.axis('off')
|
| 12 |
-
plt.close(fig)
|
| 13 |
-
return fig
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
iface = gr.Interface(
|
| 16 |
-
fn=
|
| 17 |
inputs=[
|
| 18 |
-
gr.
|
| 19 |
-
gr.Slider(0,
|
| 20 |
-
gr.Slider(0,
|
| 21 |
-
gr.Slider(0,
|
| 22 |
-
gr.
|
| 23 |
],
|
| 24 |
-
outputs=
|
| 25 |
-
live=True
|
| 26 |
)
|
| 27 |
|
|
|
|
| 28 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import cv2
|
| 3 |
import numpy as np
|
|
|
|
| 4 |
|
| 5 |
+
# Funci贸n para dibujar rect谩ngulos en la imagen
|
| 6 |
+
def draw_rectangle(img, x1, y1, x2, y2, color):
|
| 7 |
+
# Convertir los valores a enteros
|
| 8 |
+
x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
|
| 9 |
+
# Dibujar el rect谩ngulo en la imagen
|
| 10 |
+
cv2.rectangle(img, (x1, y1), (x2, y2), color, -1) # -1 para rellenar el rect谩ngulo
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
# Funci贸n principal para la interfaz
|
| 13 |
+
def paint_app(color, x1, y1, x2, y2):
|
| 14 |
+
# Crear una imagen en blanco
|
| 15 |
+
img = np.zeros((400, 400, 3), dtype=np.uint8)
|
| 16 |
+
# Dibujar el rect谩ngulo
|
| 17 |
+
draw_rectangle(img, x1, y1, x2, y2, color)
|
| 18 |
+
return img
|
| 19 |
+
|
| 20 |
+
# Definir los colores disponibles
|
| 21 |
+
colors = ["Red", "Green", "Blue", "Yellow", "White"]
|
| 22 |
+
|
| 23 |
+
# Crear la interfaz de Gradio
|
| 24 |
iface = gr.Interface(
|
| 25 |
+
fn=paint_app,
|
| 26 |
inputs=[
|
| 27 |
+
gr.Slider(minimum=0, maximum=399, step=1, label="X1"), # Coordenada X1 del rect谩ngulo
|
| 28 |
+
gr.Slider(minimum=0, maximum=399, step=1, label="Y1"), # Coordenada Y1 del rect谩ngulo
|
| 29 |
+
gr.Slider(minimum=0, maximum=399, step=1, label="X2"), # Coordenada X2 del rect谩ngulo
|
| 30 |
+
gr.Slider(minimum=0, maximum=399, step=1, label="Y2"), # Coordenada Y2 del rect谩ngulo
|
| 31 |
+
gr.Dropdown(colors, label="Color") # Selecci贸n de color
|
| 32 |
],
|
| 33 |
+
outputs=gr.Image(width=400, height=400)
|
|
|
|
| 34 |
)
|
| 35 |
|
| 36 |
+
# Ejecutar la interfaz
|
| 37 |
iface.launch()
|