pasuntaxih commited on
Commit
1f14c06
verified
1 Parent(s): 2e0acec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -18
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
- def draw_rectangle(color, x, y, width, height):
6
- fig, ax = plt.subplots()
7
- rect = plt.Rectangle((x, y), width, height, color=color)
8
- ax.add_patch(rect)
9
- ax.set_xlim(0, 10)
10
- ax.set_ylim(0, 10)
11
- plt.axis('off')
12
- plt.close(fig)
13
- return fig
14
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  iface = gr.Interface(
16
- fn=draw_rectangle,
17
  inputs=[
18
- gr.ColorPicker(label="Color del Rect谩ngulo"),
19
- gr.Slider(0, 10, 1, label="Posici贸n X"),
20
- gr.Slider(0, 10, 1, label="Posici贸n Y"),
21
- gr.Slider(0, 10, 1, label="Ancho"),
22
- gr.Slider(0, 10, 1, label="Alto")
23
  ],
24
- outputs="plot",
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()