GaetanoParente commited on
Commit
ef72586
·
1 Parent(s): 3a24a7b

fix bug visivo in seguito a cambio del modulo visualizzato

Browse files
app.py CHANGED
@@ -320,26 +320,83 @@ with gr.Blocks(title="NGT AI Platform", theme=theme, css_paths="style.css") as d
320
  inputs=sentiment_input,
321
  outputs=sentiment_output
322
  )
323
-
 
 
 
324
  sidebar_explorer.change(
325
  fn=utils.global_file_loader,
326
  inputs=sidebar_explorer,
327
  outputs=[bpo_input, image_input, image_input_dr, multi_input, sentiment_input]
328
  )
329
 
330
- ui_outputs = [main_sidebar, sidebar_explorer, image_input, image_input_dr]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
331
 
332
- tab_bpo.select(fn=utils.disable_sidebar, outputs=ui_outputs)
333
- tab_news.select(fn=utils.disable_sidebar, outputs=ui_outputs)
334
- tab_sentiment.select(fn=utils.disable_sidebar, outputs=ui_outputs)
 
 
 
335
 
 
336
  tab_xray.select(
337
  fn=lambda: utils.enable_sidebar(PATH_XRAY),
338
  outputs=ui_outputs
 
 
339
  )
 
340
  tab_retina.select(
341
  fn=lambda: utils.enable_sidebar(PATH_RETINA),
342
  outputs=ui_outputs
 
 
343
  )
344
 
345
  if __name__ == "__main__":
 
320
  inputs=sentiment_input,
321
  outputs=sentiment_output
322
  )
323
+
324
+ ui_outputs = [main_sidebar, sidebar_explorer, image_input, image_input_dr]
325
+
326
+ # 1. Click-to-Load (Rimane invariato)
327
  sidebar_explorer.change(
328
  fn=utils.global_file_loader,
329
  inputs=sidebar_explorer,
330
  outputs=[bpo_input, image_input, image_input_dr, multi_input, sentiment_input]
331
  )
332
 
333
+ # 2. DEFINIZIONE DEL RESET TOTALE
334
+ # Questa funzione restituisce valori "vuoti" per tutti i campi sensibili
335
+ def reset_all_fields():
336
+ return (
337
+ None, # bpo_input (Textbox)
338
+ None, # bpo_intent (Label)
339
+ None, # bpo_urgency (Textbox)
340
+ None, # bpo_action (Textbox)
341
+ None, # bpo_ner (HTML)
342
+ None, # image_input (Image Xray)
343
+ None, # output_label (Label Xray)
344
+ None, # image_input_dr (Image Retina)
345
+ None, # output_dr_diag (Label Retina)
346
+ None, # output_dr_prob (Label Retina)
347
+ None, # multi_input (Textbox News)
348
+ None, # multi_output (Label News)
349
+ None, # sentiment_input (Textbox)
350
+ None # sentiment_output (Label)
351
+ )
352
+
353
+ # Lista ordinata di TUTTI gli output da pulire
354
+ # DEVE corrispondere esattamente all'ordine del return sopra!
355
+ reset_outputs = [
356
+ bpo_input, bpo_intent_output, bpo_urgency_output, bpo_action_output, bpo_ner_output,
357
+ image_input, output_label,
358
+ image_input_dr, output_dr_diagnosis, output_dr_prob,
359
+ multi_input, multi_output,
360
+ sentiment_input, sentiment_output
361
+ ]
362
+
363
+ # 3. GESTIONE CAMBIO TAB (RESET + SIDEBAR)
364
+
365
+ # Per i Tab NLP: Disabilita Sidebar + Resetta TUTTO
366
+ tab_bpo.select(
367
+ fn=utils.disable_sidebar,
368
+ outputs=ui_outputs
369
+ ).then(
370
+ fn=reset_all_fields, outputs=reset_outputs
371
+ )
372
+
373
+ tab_news.select(
374
+ fn=utils.disable_sidebar,
375
+ outputs=ui_outputs
376
+ ).then(
377
+ fn=reset_all_fields, outputs=reset_outputs
378
+ )
379
 
380
+ tab_sentiment.select(
381
+ fn=utils.disable_sidebar,
382
+ outputs=ui_outputs
383
+ ).then(
384
+ fn=reset_all_fields, outputs=reset_outputs
385
+ )
386
 
387
+ # Per i Tab VISION: Abilita Sidebar specifica + Resetta TUTTO
388
  tab_xray.select(
389
  fn=lambda: utils.enable_sidebar(PATH_XRAY),
390
  outputs=ui_outputs
391
+ ).then(
392
+ fn=reset_all_fields, outputs=reset_outputs
393
  )
394
+
395
  tab_retina.select(
396
  fn=lambda: utils.enable_sidebar(PATH_RETINA),
397
  outputs=ui_outputs
398
+ ).then(
399
+ fn=reset_all_fields, outputs=reset_outputs
400
  )
401
 
402
  if __name__ == "__main__":
modules/image_classification.py CHANGED
@@ -34,7 +34,6 @@ def load_resources():
34
  load_resources()
35
 
36
  def image_classification(image_array):
37
- print(image_array)
38
  """
39
  Analizza un'immagine radiografica (numpy array) e restituisce le probabilità.
40
  """
@@ -59,7 +58,6 @@ def image_classification(image_array):
59
  raw_label = RAW_CLASSES[i]
60
  user_label = CLASS_MAP.get(raw_label, raw_label)
61
  response[user_label] = float(prob)
62
- print(response)
63
  return response
64
 
65
  except Exception as e:
 
34
  load_resources()
35
 
36
  def image_classification(image_array):
 
37
  """
38
  Analizza un'immagine radiografica (numpy array) e restituisce le probabilità.
39
  """
 
58
  raw_label = RAW_CLASSES[i]
59
  user_label = CLASS_MAP.get(raw_label, raw_label)
60
  response[user_label] = float(prob)
 
61
  return response
62
 
63
  except Exception as e:
modules/utilities/utils.py CHANGED
@@ -70,11 +70,11 @@ def global_file_loader(file_data):
70
 
71
  def enable_sidebar(new_root):
72
  """Mostra la sidebar e aggiorna il path (Per Computer Vision)"""
73
- return gr.update(visible=True), gr.update(root_dir=new_root), None, None
74
 
75
  def disable_sidebar():
76
  """Nasconde la sidebar (Per NLP)"""
77
- return gr.update(visible=False), gr.update(), None, None
78
 
79
  def render_ner_html(entities):
80
  """
 
70
 
71
  def enable_sidebar(new_root):
72
  """Mostra la sidebar e aggiorna il path (Per Computer Vision)"""
73
+ return gr.update(visible=True), gr.update(root_dir=new_root, value=[], interactive=True), None, None
74
 
75
  def disable_sidebar():
76
  """Nasconde la sidebar (Per NLP)"""
77
+ return gr.update(visible=False), gr.update(value=[]), None, None
78
 
79
  def render_ner_html(entities):
80
  """