ajflorez commited on
Commit
3061070
·
verified ·
1 Parent(s): f4cc1ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -14
app.py CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  import gradio as gr
2
  from PIL import Image
3
  import os
@@ -9,6 +13,18 @@ from matplotlib.colors import Normalize
9
  from io import BytesIO
10
  import re
11
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  # Images path
13
  path_main = 'Data/'
14
  images_file = path_main + 'Scennarios init/Scennarios W'
@@ -67,27 +83,29 @@ def load_plan_vi(mapa_seleccionado, uploaded_file):
67
  return plan_im, plan_im_meters
68
 
69
  def validate_coords(num_aps, coords):
70
- matches = re.findall(r"\(\s*\d+\s*,\s*\d+\s*\)", coords)
71
-
72
- if len(matches) > int(num_aps):
73
- new_coords = ", ".join(matches[:int(num_aps)])
74
  return new_coords
75
- return coords
 
 
76
 
77
  def coordinates_process(texto, interference):
78
  a = False
79
 
80
- texto = re.sub(r'\s*,\s*', ', ', texto)
81
- texto = re.sub(r'\)\s*,\s*\(', '), (', texto)
82
- texto = texto.strip()
83
 
84
  coordinates = texto.split("), ")
85
 
86
  resultado = []
87
  for coord in coordinates:
88
  try:
89
- coord = coord.replace("(", "").replace(")", "")
90
- x, y = map(int, coord.split(","))
91
 
92
  if 0 <= x <= 255 and 0 <= y <= 255:
93
  resultado.append((x, y))
@@ -104,8 +122,7 @@ def coordinates_process(texto, interference):
104
  while len(resultado) < 5 and interference == False:
105
  resultado.append((0, 0))
106
 
107
- resultado_str = ", ".join([f"({x}, {y})" for x, y in resultado])
108
- return resultado_str
109
 
110
  # plan images path
111
  def plan_images_list():
@@ -114,7 +131,7 @@ def plan_images_list():
114
  # MAIN FUNCTION ****************************************************************
115
  def main_function(plan_name, interference = True, aps_int = 0, aps_coor = '(0,0)',
116
  apch1 = 0, apch6 = 0, apch11 = 0, coord1 = '(0,0)', coord6 = '(0,0)', coord11 = '(0,0)'):
117
-
118
  plan_name = str(plan_name)
119
  interference = bool(interference)
120
  aps_int = int(aps_int)
@@ -606,4 +623,4 @@ with gr.Blocks() as demo:
606
  coords_ch1_input, coords_ch6_input, coords_ch11_input],
607
  outputs=[image_ch1, image_ch6, image_ch11, image_ap1, image_ap2, image_cover_final, image_cells])
608
 
609
- demo.launch()
 
1
+ # Commented out IPython magic to ensure Python compatibility.
2
+ # %%capture
3
+ # !pip install gradio
4
+
5
  import gradio as gr
6
  from PIL import Image
7
  import os
 
13
  from io import BytesIO
14
  import re
15
 
16
+ # import gradio
17
+ # import PIL
18
+ # import tensorflow as tf
19
+ # import numpy as np
20
+ # import matplotlib
21
+
22
+ # print("Gradio:", gradio.__version__)
23
+ # print("Pillow (PIL):", PIL.__version__)
24
+ # print("TensorFlow:", tf.__version__)
25
+ # print("NumPy:", np.__version__)
26
+ # print("Matplotlib:", matplotlib.__version__)
27
+
28
  # Images path
29
  path_main = 'Data/'
30
  images_file = path_main + 'Scennarios init/Scennarios W'
 
83
  return plan_im, plan_im_meters
84
 
85
  def validate_coords(num_aps, coords):
86
+ matches = re.findall(r"\(\s*\d+\s*,\s*\d+\s*\)", coords)
87
+
88
+ if len(matches) > int(num_aps):
89
+ new_coords = ", ".join(matches[:int(num_aps)])
90
  return new_coords
91
+ return coords
92
+
93
+ import re
94
 
95
  def coordinates_process(texto, interference):
96
  a = False
97
 
98
+ texto = re.sub(r'\s*,\s*', ', ', texto) # Normalizar espacios entre comas
99
+ texto = re.sub(r'\)\s*,\s*\(', '), (', texto) # Asegurarse de que las tuplas estén separadas por "), ("
100
+ texto = texto.strip() # Eliminar cualquier espacio en exceso al principio o al final
101
 
102
  coordinates = texto.split("), ")
103
 
104
  resultado = []
105
  for coord in coordinates:
106
  try:
107
+ coord = coord.replace("(", "").replace(")", "") # Eliminar paréntesis
108
+ x, y = map(int, coord.split(",")) # Convertir a enteros
109
 
110
  if 0 <= x <= 255 and 0 <= y <= 255:
111
  resultado.append((x, y))
 
122
  while len(resultado) < 5 and interference == False:
123
  resultado.append((0, 0))
124
 
125
+ return resultado # Devolver como arreglo de tuplas
 
126
 
127
  # plan images path
128
  def plan_images_list():
 
131
  # MAIN FUNCTION ****************************************************************
132
  def main_function(plan_name, interference = True, aps_int = 0, aps_coor = '(0,0)',
133
  apch1 = 0, apch6 = 0, apch11 = 0, coord1 = '(0,0)', coord6 = '(0,0)', coord11 = '(0,0)'):
134
+
135
  plan_name = str(plan_name)
136
  interference = bool(interference)
137
  aps_int = int(aps_int)
 
623
  coords_ch1_input, coords_ch6_input, coords_ch11_input],
624
  outputs=[image_ch1, image_ch6, image_ch11, image_ap1, image_ap2, image_cover_final, image_cells])
625
 
626
+ demo.launch(debug = True)