ajflorez commited on
Commit
f08ca73
·
verified ·
1 Parent(s): 0d2505c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +303 -103
app.py CHANGED
@@ -9,17 +9,17 @@ from matplotlib.colors import Normalize
9
  from io import BytesIO
10
 
11
  # Images path
12
- path_main = 'Data/'
13
  images_file = path_main + 'Scennarios init/Scennarios W'
14
 
15
  # Load DL models
16
- modelo_1ap = load_model(path_main + 'Models/modelo_1ap_app.keras')
17
- modelo_2ap = load_model(path_main + 'Models/modelo_2ap_app.keras')
18
 
19
  plt.rc('font', family='Times New Roman')
20
  fontsize_t = 15
21
 
22
- def coordinates_process(texto):
23
  coordinates = texto.split("), ")
24
 
25
  resultado = []
@@ -35,64 +35,84 @@ def coordinates_process(texto):
35
  except ValueError:
36
  return False
37
 
38
- while len(resultado) < 3:
 
 
 
39
  resultado.append((0, 0))
40
 
41
  return resultado
42
 
43
  # plan images path
44
  def plan_images_list():
45
- return [file_ for file_ in os.listdir(images_file) if file_.endswith((".JPG", ".jpg", ".jpeg", ".png", "PNG"))]
46
-
47
- # Valdate inputs
48
- def validate_input(value):
49
- if value == "" or value is None:
50
- return 0
51
- elif value >= 0 or value <= 2:
52
- return value
53
 
54
  # MAIN FUNCTION ****************************************************************
55
- def main_function(plan_name, apch1, apch6, apch11, coord1, coord6, coord11):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  image_plan_path = os.path.join(images_file, plan_name)
57
  imagen1 = Image.open(image_plan_path)
58
 
59
- # No negative number as input
60
- if not (0 <= apch1 <= 2):
61
- return False
62
- if not (0 <= apch6 <= 2):
63
- return False
64
- if not (0 <= apch11 <= 2):
65
- return False
66
-
67
  # Some variables init
68
  deep_count = 0
69
  deep_coverage = []
70
- channels = [1, 6, 11]
71
- num_APs = np.zeros(len(channels), dtype=int)
72
- num_APs[0] = apch1
73
- num_APs[1] = apch6
74
- num_APs[2] = apch11
75
  dimension = 256
76
- aps_chs = np.zeros((dimension, dimension, len(channels)))
77
-
78
- # Load plan
79
- numero = plan_name.split('.')[0]
80
- plan_in = np.array(Image.open(f"{path_main}Scennarios init/Scennarios B/{numero}.png")) / 255
81
 
82
- coords = [coord1, coord6, coord11]
83
- for att, channel in enumerate(channels):
84
- if num_APs[att] > 0:
85
- coordinates = coordinates_process(coords[att])
86
- for x, y in coordinates:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  if x != 0 and y != 0:
88
- aps_chs[int(y), int(x), att] = 1
89
 
90
  # Coverage process
91
  deep_coverage = []
92
  ap_images = []
93
  layer_indices = []
94
- imagencober = {}
95
- for k in range(len(channels)):
96
  capa = aps_chs[:, :, k]
97
  filas, columnas = np.where(capa == 1)
98
 
@@ -123,14 +143,15 @@ def main_function(plan_name, apch1, apch6, apch11, coord1, coord6, coord11):
123
  # print(prediction.shape)
124
  deep_coverage.append(prediction)
125
  prediction_rgb = np.squeeze((Normalize()(prediction)))
126
- ap_images.append(prediction_rgb) # Guardar la imagen de cobertura del AP
127
 
128
  if np.all(prediction == 0):
129
- plt.imshow(prediction_rgb)
130
- plt.title('No coverage', fontsize=fontsize_t + 2, family='Times New Roman')
131
  plt.axis("off")
132
  else:
133
  plt.imshow(prediction_rgb, cmap='jet')
 
134
  cbar = plt.colorbar(ticks=np.linspace(0, 1, num=6),)
135
  cbar.set_label('SINR [dB]', fontsize=fontsize_t, fontname='Times New Roman')
136
  cbar.set_ticklabels(['-3.01', '20.29', '43.60', '66.90', '90.20', '113.51'])
@@ -173,7 +194,9 @@ def main_function(plan_name, apch1, apch6, apch11, coord1, coord6, coord11):
173
  # Convert buffer to an image
174
  imagen3 = Image.open(buf)
175
 
176
- if num_APs[0] > 0 and num_APs[1] > 0 and num_APs[2] > 0:
 
 
177
  cmap = plt.cm.colors.ListedColormap(['blue', 'red', 'green'])
178
  plt.imshow(celdas, cmap=cmap)
179
  cbar = plt.colorbar()
@@ -192,7 +215,7 @@ def main_function(plan_name, apch1, apch6, apch11, coord1, coord6, coord11):
192
  # Convert buffer to an image
193
  imagen4 = Image.open(buf)
194
 
195
- elif num_APs[0] > 0 and num_APs[1] > 0:
196
  cmap = plt.cm.colors.ListedColormap(['blue', 'red'])
197
  plt.imshow(celdas, cmap=cmap)
198
  cbar = plt.colorbar()
@@ -211,7 +234,7 @@ def main_function(plan_name, apch1, apch6, apch11, coord1, coord6, coord11):
211
  # Convert buffer to an image
212
  imagen4 = Image.open(buf)
213
 
214
- elif num_APs[0] > 0 and num_APs[2] > 0:
215
  cmap = plt.cm.colors.ListedColormap(['blue', 'red'])
216
  plt.imshow(celdas, cmap=cmap)
217
  cbar = plt.colorbar()
@@ -230,7 +253,7 @@ def main_function(plan_name, apch1, apch6, apch11, coord1, coord6, coord11):
230
  # Convert buffer to an image
231
  imagen4 = Image.open(buf)
232
 
233
- elif num_APs[1] > 0 and num_APs[2] > 0:
234
  cmap = plt.cm.colors.ListedColormap(['blue', 'red'])
235
  plt.imshow(celdas, cmap=cmap)
236
  cbar = plt.colorbar()
@@ -249,7 +272,27 @@ def main_function(plan_name, apch1, apch6, apch11, coord1, coord6, coord11):
249
  # Convert buffer to an image
250
  imagen4 = Image.open(buf)
251
 
252
- else:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  cmap = plt.cm.colors.ListedColormap(['blue'])
254
  plt.imshow(celdas, cmap=cmap)
255
  cbar = plt.colorbar()
@@ -268,90 +311,247 @@ def main_function(plan_name, apch1, apch6, apch11, coord1, coord6, coord11):
268
  # Convert buffer to an image
269
  imagen4 = Image.open(buf)
270
 
271
- return [imagencober[0], imagencober[1], imagencober[2], imagen3, imagen4]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
 
273
- # plan visualization
274
- def load_plan_vi(mapa_seleccionado):
 
 
 
 
 
 
 
275
 
276
- image_plan_path1 = os.path.join(images_file, mapa_seleccionado)
277
- plan_image = Image.open(image_plan_path1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
 
279
  plan_n = np.array(plan_image.convert('RGB'))
280
- plt.figure(figsize=(3, 3))
281
  plt.imshow(plan_n)
282
- plt.xticks(np.arange(0, 256, 50))
283
- plt.yticks(np.arange(0, 256, 50))
 
 
284
 
285
- # Save the plot to a buffer
286
  buf = BytesIO()
287
  plt.savefig(buf, format='png')
288
  buf.seek(0)
289
  plt.close()
290
 
291
- # Convert buffer to an image
292
  plan_im = Image.open(buf)
293
 
294
- return plan_im
 
295
 
296
- with gr.Blocks() as demo:
 
 
 
 
 
297
 
298
- gr.Markdown("""
299
- ## Fast Indoor Radio Propagation Prediction using Deep Learning
300
- This app use deep learning models to radio map estimation (RME). RME entails estimating the received RF power based on spatial information maps.
301
 
302
- Instructions for use:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
 
304
- - A predefined list of indoor floor plans is available for use.
305
- - A maximum of (255,255) pixels is allowed for image size.
306
- - Negative numbers are not allowed.
307
- - The established format for the coordinates of each access point (AP) must be maintained.
308
- - A maximum of 2 APs are allowed per channel.
309
  """)
310
 
 
 
311
  with gr.Row():
312
- # Input left panel
313
- with gr.Column(scale=1): # Scale to resize
314
- map_dropdown = gr.Dropdown(choices=plan_images_list(), label="Select indoor plan")
315
  ch1_input = gr.Dropdown(choices=[i for i in range(0, 3)], label="Select APs CH 1")
316
  ch6_input = gr.Dropdown(choices=[i for i in range(0, 3)], label="Select APs CH 6")
317
  ch11_input = gr.Dropdown(choices=[i for i in range(0, 3)], label="Select APs CH 11")
318
- coords_ch1_input = gr.Textbox(label="Coordinate CH 1", placeholder="Format: (x1, y1), (x2, y2)")
319
- coords_ch6_input = gr.Textbox(label="Coordinate CH 6", placeholder="Format: (x1, y1), (x2, y2)")
320
- coords_ch11_input = gr.Textbox(label="Coordinate CH 11", placeholder="Format: (x1, y1), (x2, y2)")
 
 
 
 
321
  button1 = gr.Button("Load plan")
322
  button2 = gr.Button("Predict coverage")
323
 
324
- # Rigth panel
325
- a_images = 320 # Size putput images
326
-
327
  with gr.Column(scale=3):
328
- first_image_output = gr.Image(label="plan image", height=a_images, width=a_images)
329
- # with gr.Row():
330
  with gr.Row():
331
- image_ch1 = gr.Image(label="CH 1 coverage", height=a_images, width=a_images)
332
- image_ch6 = gr.Image(label="CH 6 coverage", height=a_images, width=a_images)
333
- image_ch11 = gr.Image(label="CH 11 coverage", height=a_images, width=a_images)
334
-
335
  with gr.Row():
336
- image_cover_final = gr.Image(label="Final coverage", height=a_images, width=a_images)
337
- image_cells = gr.Image(label="Cells coverage", height=a_images, width=a_images)
338
-
339
-
340
- # Buttons
341
- button1.click(load_plan_vi, inputs=[map_dropdown], outputs=first_image_output)
342
- button2.click(
343
- lambda map_dropdown, ch1, ch6, ch11, coords1, coords6, coords11: main_function(
344
- map_dropdown,
345
- validate_input(ch1),
346
- validate_input(ch6),
347
- validate_input(ch11),
348
- coords1,
349
- coords6,
350
- coords11,
351
- ),
352
- inputs=[map_dropdown, ch1_input, ch6_input, ch11_input, coords_ch1_input, coords_ch6_input, coords_ch11_input],
353
- outputs=[image_ch1, image_ch6, image_ch11, image_cover_final, image_cells]
354
- )
355
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
356
 
357
  demo.launch()
 
9
  from io import BytesIO
10
 
11
  # Images path
12
+ path_main = '/content/drive/Othercomputers/False-2-Tesis-Maestria /Phase-3-thesis/'
13
  images_file = path_main + 'Scennarios init/Scennarios W'
14
 
15
  # Load DL models
16
+ modelo_1ap = load_model(path_main + 'Models/SINR-2APs/modelo_1ap_app.keras')
17
+ modelo_2ap = load_model(path_main + 'Models/SINR-2APs/modelo_2ap_app.keras')
18
 
19
  plt.rc('font', family='Times New Roman')
20
  fontsize_t = 15
21
 
22
+ def coordinates_process(texto, interference):
23
  coordinates = texto.split("), ")
24
 
25
  resultado = []
 
35
  except ValueError:
36
  return False
37
 
38
+ while len(resultado) < 3 and interference == True:
39
+ resultado.append((0, 0))
40
+
41
+ while len(resultado) < 5 and interference == False:
42
  resultado.append((0, 0))
43
 
44
  return resultado
45
 
46
  # plan images path
47
  def plan_images_list():
48
+ return [file_ for file_ in os.listdir(images_file) if file_.endswith((".JPG", ".jpg", ".jpeg", ".png", ".PNG"))]
 
 
 
 
 
 
 
49
 
50
  # MAIN FUNCTION ****************************************************************
51
+ def main_function(plan_name, interference, aps_int, aps_coor,
52
+ apch1, apch6, apch11, coord1, coord6, coord11):
53
+
54
+ # **************************************************************************
55
+ imagencober = {}
56
+
57
+ prediction_rgb = np.zeros((256, 256))
58
+
59
+ for k in range(5):
60
+ plt.imshow(prediction_rgb, cmap='gray')
61
+ plt.title(f'No coverage', fontsize=fontsize_t + 2, family='Times New Roman')
62
+ plt.axis("off")
63
+
64
+ buf = BytesIO()
65
+ plt.savefig(buf, format='png')
66
+ buf.seek(0)
67
+ plt.close()
68
+
69
+ imagencober[k] = Image.open(buf)
70
+ # **************************************************************************
71
+
72
+ # Load plan
73
+ numero = plan_name.split('.')[0]
74
+ plan_in = np.array(Image.open(f"{path_main}Scennarios init/Scennarios B/{numero}.png")) / 255
75
+
76
  image_plan_path = os.path.join(images_file, plan_name)
77
  imagen1 = Image.open(image_plan_path)
78
 
 
 
 
 
 
 
 
 
79
  # Some variables init
80
  deep_count = 0
81
  deep_coverage = []
 
 
 
 
 
82
  dimension = 256
 
 
 
 
 
83
 
84
+ if interference:
85
+ # channels_c = [1, 6 , 11]
86
+ channels = 3
87
+ num_APs = np.zeros(channels, dtype=int)
88
+ num_APs[0] = apch1
89
+ num_APs[1] = apch6
90
+ num_APs[2] = apch11
91
+ aps_chs = np.zeros((dimension, dimension, channels))
92
+ coords = [coord1, coord6, coord11]
93
+
94
+ for att, channel in enumerate(range(channels)):
95
+ if num_APs[att] > 0:
96
+ coordinates = coordinates_process(coords[att], interference)
97
+ for x, y in coordinates:
98
+ if x != 0 and y != 0:
99
+ aps_chs[int(y), int(x), att] = 1
100
+
101
+ if not interference:
102
+ channels = aps_int
103
+ aps_chs = np.zeros((dimension, dimension, channels)) # Crear la matriz
104
+ coordinates = coordinates_process(aps_coor, interference)
105
+
106
+ for att, (x, y) in enumerate(coordinates):
107
  if x != 0 and y != 0:
108
+ aps_chs[int(y), int(x), att] = 1
109
 
110
  # Coverage process
111
  deep_coverage = []
112
  ap_images = []
113
  layer_indices = []
114
+
115
+ for k in range(channels):
116
  capa = aps_chs[:, :, k]
117
  filas, columnas = np.where(capa == 1)
118
 
 
143
  # print(prediction.shape)
144
  deep_coverage.append(prediction)
145
  prediction_rgb = np.squeeze((Normalize()(prediction)))
146
+ ap_images.append(prediction_rgb)
147
 
148
  if np.all(prediction == 0):
149
+ plt.imshow(prediction_rgb, cmap='gray')
150
+ plt.title(f'No coverage', fontsize=fontsize_t + 2, family='Times New Roman')
151
  plt.axis("off")
152
  else:
153
  plt.imshow(prediction_rgb, cmap='jet')
154
+ # plt.title(f'Coverage CH {channels_c[k]}', fontsize=fontsize_t + 2, family='Times New Roman')
155
  cbar = plt.colorbar(ticks=np.linspace(0, 1, num=6),)
156
  cbar.set_label('SINR [dB]', fontsize=fontsize_t, fontname='Times New Roman')
157
  cbar.set_ticklabels(['-3.01', '20.29', '43.60', '66.90', '90.20', '113.51'])
 
194
  # Convert buffer to an image
195
  imagen3 = Image.open(buf)
196
 
197
+ # **************************************************************************
198
+
199
+ if num_APs[0] > 0 and num_APs[1] > 0 and num_APs[2] > 0 and interference == True:
200
  cmap = plt.cm.colors.ListedColormap(['blue', 'red', 'green'])
201
  plt.imshow(celdas, cmap=cmap)
202
  cbar = plt.colorbar()
 
215
  # Convert buffer to an image
216
  imagen4 = Image.open(buf)
217
 
218
+ if num_APs[0] > 0 and num_APs[1] > 0 and interference == True:
219
  cmap = plt.cm.colors.ListedColormap(['blue', 'red'])
220
  plt.imshow(celdas, cmap=cmap)
221
  cbar = plt.colorbar()
 
234
  # Convert buffer to an image
235
  imagen4 = Image.open(buf)
236
 
237
+ if num_APs[0] > 0 and num_APs[2] > 0 and interference == True:
238
  cmap = plt.cm.colors.ListedColormap(['blue', 'red'])
239
  plt.imshow(celdas, cmap=cmap)
240
  cbar = plt.colorbar()
 
253
  # Convert buffer to an image
254
  imagen4 = Image.open(buf)
255
 
256
+ if num_APs[1] > 0 and num_APs[2] > 0 and interference == True:
257
  cmap = plt.cm.colors.ListedColormap(['blue', 'red'])
258
  plt.imshow(celdas, cmap=cmap)
259
  cbar = plt.colorbar()
 
272
  # Convert buffer to an image
273
  imagen4 = Image.open(buf)
274
 
275
+ if num_APs[0] > 0 and num_APs[1] == 0 and num_APs[2] == 0 and interference == True:
276
+ cmap = plt.cm.colors.ListedColormap(['blue'])
277
+ plt.imshow(celdas, cmap=cmap)
278
+ cbar = plt.colorbar()
279
+ cbar.set_ticks([0])
280
+ cbar.set_ticklabels(['1'])
281
+ cbar.set_label('Cell ID', fontsize=fontsize_t, fontname='Times New Roman')
282
+ cbar.ax.tick_params(labelsize=fontsize_t, labelfontfamily = 'Times New Roman')
283
+ plt.axis("off")
284
+
285
+ if num_APs[0] == 0 and num_APs[1] > 0 and num_APs[2] == 0 and interference == True:
286
+ cmap = plt.cm.colors.ListedColormap(['blue'])
287
+ plt.imshow(celdas, cmap=cmap)
288
+ cbar = plt.colorbar()
289
+ cbar.set_ticks([0])
290
+ cbar.set_ticklabels(['1'])
291
+ cbar.set_label('Cell ID', fontsize=fontsize_t, fontname='Times New Roman')
292
+ cbar.ax.tick_params(labelsize=fontsize_t, labelfontfamily = 'Times New Roman')
293
+ plt.axis("off")
294
+
295
+ if num_APs[0] == 0 and num_APs[1] == 0 and num_APs[2] > 0 and interference == True:
296
  cmap = plt.cm.colors.ListedColormap(['blue'])
297
  plt.imshow(celdas, cmap=cmap)
298
  cbar = plt.colorbar()
 
311
  # Convert buffer to an image
312
  imagen4 = Image.open(buf)
313
 
314
+ # **************************************************************************
315
+
316
+ if aps_int == 5 and interference == False:
317
+ cmap = plt.cm.colors.ListedColormap(['blue', 'red', 'green', 'yellow', 'green'])
318
+ plt.imshow(celdas, cmap=cmap)
319
+ cbar = plt.colorbar()
320
+ cbar.set_ticks([0, 1, 2])
321
+ cbar.set_ticklabels(['1', '2', '3', '4', '5'])
322
+ cbar.set_label('Cell ID', fontsize=fontsize_t, fontname='Times New Roman')
323
+ cbar.ax.tick_params(labelsize=fontsize_t, labelfontfamily = 'Times New Roman')
324
+ plt.axis("off")
325
+
326
+ # Save the plot to a buffer
327
+ buf = BytesIO()
328
+ plt.savefig(buf, format='png')
329
+ buf.seek(0)
330
+ plt.close()
331
+
332
+ # Convert buffer to an image
333
+ imagen4 = Image.open(buf)
334
 
335
+ if aps_int == 4 and interference == False:
336
+ cmap = plt.cm.colors.ListedColormap(['blue', 'red', 'green', 'yellow'])
337
+ plt.imshow(celdas, cmap=cmap)
338
+ cbar = plt.colorbar()
339
+ cbar.set_ticks([0, 1, 2])
340
+ cbar.set_ticklabels(['1', '2', '3', '4'])
341
+ cbar.set_label('Cell ID', fontsize=fontsize_t, fontname='Times New Roman')
342
+ cbar.ax.tick_params(labelsize=fontsize_t, labelfontfamily = 'Times New Roman')
343
+ plt.axis("off")
344
 
345
+ # Save the plot to a buffer
346
+ buf = BytesIO()
347
+ plt.savefig(buf, format='png')
348
+ buf.seek(0)
349
+ plt.close()
350
+
351
+ # Convert buffer to an image
352
+ imagen4 = Image.open(buf)
353
+
354
+ if aps_int == 3 and interference == False:
355
+ cmap = plt.cm.colors.ListedColormap(['blue', 'red', 'green'])
356
+ plt.imshow(celdas, cmap=cmap)
357
+ cbar = plt.colorbar()
358
+ cbar.set_ticks([0, 1, 2])
359
+ cbar.set_ticklabels(['1', '2', '3',])
360
+ cbar.set_label('Cell ID', fontsize=fontsize_t, fontname='Times New Roman')
361
+ cbar.ax.tick_params(labelsize=fontsize_t, labelfontfamily = 'Times New Roman')
362
+ plt.axis("off")
363
+
364
+ # Save the plot to a buffer
365
+ buf = BytesIO()
366
+ plt.savefig(buf, format='png')
367
+ buf.seek(0)
368
+ plt.close()
369
+
370
+ # Convert buffer to an image
371
+ imagen4 = Image.open(buf)
372
+
373
+ if aps_int == 2 and interference == False:
374
+ cmap = plt.cm.colors.ListedColormap(['blue', 'red'])
375
+ plt.imshow(celdas, cmap=cmap)
376
+ cbar = plt.colorbar()
377
+ cbar.set_ticks([0, 1, 2])
378
+ cbar.set_ticklabels(['1', '2'])
379
+ cbar.set_label('Cell ID', fontsize=fontsize_t, fontname='Times New Roman')
380
+ cbar.ax.tick_params(labelsize=fontsize_t, labelfontfamily = 'Times New Roman')
381
+ plt.axis("off")
382
+
383
+ # Save the plot to a buffer
384
+ buf = BytesIO()
385
+ plt.savefig(buf, format='png')
386
+ buf.seek(0)
387
+ plt.close()
388
+
389
+ # Convert buffer to an image
390
+ imagen4 = Image.open(buf)
391
+
392
+ if aps_int == 1 and interference == False:
393
+ cmap = plt.cm.colors.ListedColormap(['blue'])
394
+ plt.imshow(celdas, cmap=cmap)
395
+ cbar = plt.colorbar()
396
+ cbar.set_ticks([0, 1, 2])
397
+ cbar.set_ticklabels(['1'])
398
+ cbar.set_label('Cell ID', fontsize=fontsize_t, fontname='Times New Roman')
399
+ cbar.ax.tick_params(labelsize=fontsize_t, labelfontfamily = 'Times New Roman')
400
+ plt.axis("off")
401
+
402
+ # Save the plot to a buffer
403
+ buf = BytesIO()
404
+ plt.savefig(buf, format='png')
405
+ buf.seek(0)
406
+ plt.close()
407
+
408
+ # Convert buffer to an image
409
+ imagen4 = Image.open(buf)
410
+
411
+ # **************************************************************************
412
+
413
+ return [imagencober[0], imagencober[1], imagencober[2], imagencober[3], imagencober[4], imagen3, imagen4]
414
+
415
+ # Plan visualization
416
+ def load_plan_vi(mapa_seleccionado, uploaded_file):
417
+
418
+ if mapa_seleccionado == "Upload your own image":
419
+ plan_image = Image.open(uploaded_file.name)
420
+ else:
421
+ image_plan_path1 = os.path.join(images_file, mapa_seleccionado)
422
+ plan_image = Image.open(image_plan_path1)
423
 
424
  plan_n = np.array(plan_image.convert('RGB'))
425
+
426
  plt.imshow(plan_n)
427
+ plt.xticks(np.arange(0, 256, 50), fontsize=fontsize_t, fontname='Times New Roman')
428
+ plt.yticks(np.arange(0, 256, 50), fontsize=fontsize_t, fontname='Times New Roman')
429
+ plt.xlabel("X Coordinate [Pixels]", fontsize=fontsize_t, fontname='Times New Roman')
430
+ plt.ylabel("Y Coordinate [Pixels]", fontsize=fontsize_t, fontname='Times New Roman')
431
 
 
432
  buf = BytesIO()
433
  plt.savefig(buf, format='png')
434
  buf.seek(0)
435
  plt.close()
436
 
 
437
  plan_im = Image.open(buf)
438
 
439
+ tick_positions = np.linspace(0, 256, 15)
440
+ tick_labels = np.linspace(0, 20, 15, dtype=int)
441
 
442
+ buf = BytesIO()
443
+ plt.imshow(plan_n)
444
+ plt.xticks(tick_positions, tick_labels, fontsize=fontsize_t, fontname='Times New Roman')
445
+ plt.yticks(tick_positions, tick_labels, fontsize=fontsize_t, fontname='Times New Roman')
446
+ plt.xlabel("X Coordinate [meters]", fontsize=fontsize_t, fontname='Times New Roman')
447
+ plt.ylabel("Y Coordinate [meters]", fontsize=fontsize_t, fontname='Times New Roman')
448
 
449
+ plt.savefig(buf, format='png')
450
+ buf.seek(0)
451
+ plt.close()
452
 
453
+ plan_im_meters = Image.open(buf)
454
+
455
+ return plan_im, plan_im_meters
456
+
457
+ def update_interface(enable_interference):
458
+ if enable_interference:
459
+ return {
460
+ map_dropdown : gr.update(visible=True),
461
+ upload_image : gr.update(visible=True),
462
+ ch1_input: gr.update(visible=True),
463
+ ch6_input: gr.update(visible=True),
464
+ ch11_input: gr.update(visible=True),
465
+ coords_ch1_input: gr.update(visible=True),
466
+ coords_ch6_input: gr.update(visible=True),
467
+ coords_ch11_input: gr.update(visible=True),
468
+ button1: gr.update(visible=True),
469
+ button2: gr.update(visible=True),
470
+ image_ap1 : gr.update(visible=False),
471
+ image_ap2 : gr.update(visible=False),
472
+ image_ch1 : gr.update(visible=True),
473
+ image_ch6 : gr.update(visible=True),
474
+ image_ch11 : gr.update(visible=True)
475
+ }
476
+ else:
477
+ return {
478
+ map_dropdown: gr.update(visible=True),
479
+ upload_image : gr.update(visible=True),
480
+ ch1_input: gr.update(visible=False),
481
+ ch6_input: gr.update(visible=False),
482
+ ch11_input: gr.update(visible=False),
483
+ coords_ch1_input: gr.update(visible=False),
484
+ coords_ch6_input: gr.update(visible=False),
485
+ coords_ch11_input: gr.update(visible=False),
486
+ simple_dropdown: gr.update(visible=True, interactive=True),
487
+ simple_coords: gr.update(visible=True, interactive=True),
488
+ image_ap1 : gr.update(visible=True),
489
+ image_ap2 : gr.update(visible=True),
490
+ image_ch1 : gr.update(visible=True),
491
+ image_ch6 : gr.update(visible=True),
492
+ image_ch11 : gr.update(visible=True)
493
+ }
494
 
495
+ with gr.Blocks() as demo:
496
+ gr.Markdown("""
497
+ ## Fast Indoor Radio Propagation Prediction using Deep Learning
498
+ This app uses deep learning models for radio map estimation (RME). RME entails estimating the received RF power based on spatial information maps.
 
499
  """)
500
 
501
+ enable_interference = gr.Checkbox(label="Enable Interference Analysis", value=True)
502
+
503
  with gr.Row():
504
+ with gr.Column(scale=1):
505
+ map_dropdown = gr.Dropdown(choices=plan_images_list() + ["Upload your own image"], label="Select indoor plan")
506
+ upload_image = gr.File(label="Or upload your own image", file_types=[".JPG", ".jpg", ".jpeg", ".png", ".PNG"])
507
  ch1_input = gr.Dropdown(choices=[i for i in range(0, 3)], label="Select APs CH 1")
508
  ch6_input = gr.Dropdown(choices=[i for i in range(0, 3)], label="Select APs CH 6")
509
  ch11_input = gr.Dropdown(choices=[i for i in range(0, 3)], label="Select APs CH 11")
510
+ coords_ch1_input = gr.Textbox(label="Coordinate CH 1", placeholder="Format (Pixels): (x1, y1), (x2, y2)")
511
+ coords_ch6_input = gr.Textbox(label="Coordinate CH 6", placeholder="Format (Pixels): (x1, y1), (x2, y2)")
512
+ coords_ch11_input = gr.Textbox(label="Coordinate CH 11", placeholder="Format (Pixels): (x1, y1), (x2, y2)")
513
+
514
+ simple_dropdown = gr.Dropdown(choices=[str(i) for i in range(1, 6)], label="Select APs number", visible=False)
515
+ simple_coords = gr.Textbox(label="Enter APs coordinates", placeholder="Format (Pixels): (x1, y1), (x1, y1)...", visible=False)
516
+
517
  button1 = gr.Button("Load plan")
518
  button2 = gr.Button("Predict coverage")
519
 
 
 
 
520
  with gr.Column(scale=3):
 
 
521
  with gr.Row():
522
+ first_image_output = gr.Image(label="Plan image pixels")
523
+ second_image_output = gr.Image(label="Plan image meters")
 
 
524
  with gr.Row():
525
+ image_ch1 = gr.Image(label="Coverage 1")
526
+ image_ch6 = gr.Image(label="Coverage 2")
527
+ image_ch11 = gr.Image(label="Coverage 3")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
528
 
529
+ image_ap1 = gr.Image(label="Coverage 4", visible=False)
530
+ image_ap2 = gr.Image(label="Coverage 5", visible=False)
531
+ with gr.Row():
532
+ image_cover_final = gr.Image(label="Final coverage")
533
+ image_cells = gr.Image(label="Cells coverage")
534
+
535
+ enable_interference.change(update_interface, inputs=[enable_interference],
536
+ outputs=[map_dropdown, upload_image,
537
+ ch1_input, ch6_input, ch11_input,
538
+ coords_ch1_input, coords_ch6_input, coords_ch11_input,
539
+ button1, button2,
540
+ simple_dropdown, simple_coords,
541
+ image_ch1, image_ch6, image_ch11,
542
+ image_ap1, image_ap2])
543
+
544
+ button1.click(load_plan_vi,
545
+ inputs=[map_dropdown, upload_image], outputs=[first_image_output, second_image_output])
546
+
547
+ # Único bloque para el clic de button2
548
+ button2.click(main_function,
549
+ inputs=[map_dropdown,
550
+ enable_interference,
551
+ simple_dropdown,
552
+ simple_coords,
553
+ ch1_input, ch6_input, ch11_input,
554
+ coords_ch1_input, coords_ch6_input, coords_ch11_input],
555
+ outputs=[image_ch1, image_ch6, image_ch11, image_ap1, image_ap2, image_cover_final, image_cells])
556
 
557
  demo.launch()