maskil commited on
Commit
0046e68
Β·
verified Β·
1 Parent(s): a5bed81

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -25
app.py CHANGED
@@ -508,7 +508,8 @@ def _empty_ws(msg=""):
508
  None, False, None,
509
  "", None, gr.Column(visible=False), None,
510
  None,
511
- "", None, "", None, gr.Column(visible=False), None)
 
512
 
513
 
514
  def fetch_next(username):
@@ -568,6 +569,9 @@ def fetch_next(username):
568
  show_flip_single = flip_reg is not None and overlap and show_fit
569
  show_flip_dual = (not overlap) and show_fit and (
570
  flip_reg is not None or flip_ai is not None)
 
 
 
571
 
572
  # Single flip info
573
  flip_info = ""
@@ -602,7 +606,9 @@ def fetch_next(username):
602
  flip_reg if overlap else None,
603
  exp_data,
604
  flip_reg_info, None, flip_ai_info, None,
605
- gr.Column(visible=show_flip_dual), dual_state)
 
 
606
  except Exception as e:
607
  print(f"fetch_next render error: {e}\n{traceback.format_exc()}")
608
  return _empty_ws(f"❌ Render failed: {e}")
@@ -756,21 +762,24 @@ def update_workspace_state(data_val, fit_s_val, fit_reg_val, fit_ai_val,
756
  """Centralized state recalculation. Called when user changes any rating.
757
  Recomputes flip points, redraws plot, recalculates all visibility.
758
 
759
- Visibility rule:
760
- - Explicit "Bad (0)" β†’ hide fit + flip sections
761
- - None (cleared) or Borderline/Perfect β†’ show fit + flip sections
 
762
  Flip-point gating:
763
- - Uses effective data quality (user > model) for computation
764
 
765
- Outputs 13 items: (plot, fs_col, fd_col,
766
  flip_info, flip_tag, flip_col, flip_state,
767
  flip_reg_info, flip_reg_tag, flip_ai_info, flip_ai_tag,
768
- flip_dual_col, flip_dual_state)
 
769
  """
770
  _empty = (None,
771
  gr.Column(visible=True), gr.Column(visible=False),
772
  "", None, gr.Column(visible=False), None,
773
- "", None, "", None, gr.Column(visible=False), None)
 
774
  if exp_data is None:
775
  return _empty
776
 
@@ -781,9 +790,14 @@ def update_workspace_state(data_val, fit_s_val, fit_reg_val, fit_ai_val,
781
  mc = (model_preds or {}).get('model_classes', {})
782
 
783
  # ── UI VISIBILITY: only explicit "Bad" hides sections ──
784
- # None (cleared) always shows β†’ lets user see everything and decide
785
  ui_show = data_val != 'Bad (0)'
786
 
 
 
 
 
 
 
787
  # ── FLIP-POINT GATING: uses effective quality for computation ──
788
  if data_val is not None:
789
  eff_data = RATING_MAP.get(data_val, -1)
@@ -813,12 +827,18 @@ def update_workspace_state(data_val, fit_s_val, fit_reg_val, fit_ai_val,
813
  fig = create_plot(raw_data, fname, reg_params, ai_params, overlap,
814
  flip_reg=flip_reg, flip_ai=flip_ai)
815
 
816
- # ── Section visibility (ui_show controls all downstream sections) ──
817
  show_fit_single = overlap and ui_show
818
  show_fit_dual = (not overlap) and ui_show
819
- show_flip_single = flip_reg is not None and overlap and ui_show
820
- show_flip_dual = (not overlap) and ui_show and (
821
- flip_reg is not None or flip_ai is not None)
 
 
 
 
 
 
822
 
823
  # ── Info strings ──
824
  flip_info = ""
@@ -830,13 +850,13 @@ def update_workspace_state(data_val, fit_s_val, fit_reg_val, fit_ai_val,
830
  flip_reg_info = ""
831
  flip_ai_info = ""
832
  if not overlap and ui_show:
833
- if flip_reg:
834
  flip_reg_info = f"Reg Flip: x = {flip_reg['x']:.5f}, y = {flip_reg['y']:.4f} ({flip_reg['type']})"
835
- elif data_gate and fit_gate:
836
  flip_reg_info = "No flip point detected."
837
- if flip_ai:
838
  flip_ai_info = f"AI Flip: x = {flip_ai['x']:.5f}, y = {flip_ai['y']:.4f} ({flip_ai['type']})"
839
- elif data_gate and ai_fit_gate:
840
  flip_ai_info = "No flip point detected."
841
 
842
  dual_state = {'reg': flip_reg, 'ai': flip_ai} if not overlap else None
@@ -849,7 +869,9 @@ def update_workspace_state(data_val, fit_s_val, fit_reg_val, fit_ai_val,
849
  flip_reg if overlap else None,
850
  flip_reg_info, None, flip_ai_info, None,
851
  gr.Column(visible=show_flip_dual),
852
- dual_state)
 
 
853
 
854
 
855
  # ═════════════════════════════════════════════════════════════════════════
@@ -1228,7 +1250,7 @@ def build_ui():
1228
  with gr.Column(visible=False) as ws_flip_dual_col:
1229
  gr.Markdown("### 🎯 Flip-Point Detection (Diverging Fits)")
1230
  with gr.Row():
1231
- with gr.Column():
1232
  gr.Markdown("#### 🟦 Regular Fit Flip")
1233
  ws_flip_reg_info = gr.Textbox(
1234
  label="Regular Flip", interactive=False, lines=1)
@@ -1236,7 +1258,7 @@ def build_ui():
1236
  choices=["βœ… Correct", "❌ Wrong"], value=None,
1237
  label="Regular flip correct?",
1238
  elem_classes=["rating-radio"])
1239
- with gr.Column():
1240
  gr.Markdown("#### 🟩 AI Fit Flip")
1241
  ws_flip_ai_info = gr.Textbox(
1242
  label="AI Flip", interactive=False, lines=1)
@@ -1258,7 +1280,8 @@ def build_ui():
1258
  ws_flip_info, ws_flip_tag, ws_flip_col, ws_flip_state,
1259
  ws_flip_reg_info, ws_flip_reg_tag,
1260
  ws_flip_ai_info, ws_flip_ai_tag,
1261
- ws_flip_dual_col, ws_flip_dual_state])
 
1262
 
1263
  # Centralized state recalculation on any rating change
1264
  _state_inputs = [ws_dr, ws_fs, ws_fr, ws_fa,
@@ -1267,13 +1290,14 @@ def build_ui():
1267
  ws_flip_info, ws_flip_tag, ws_flip_col, ws_flip_state,
1268
  ws_flip_reg_info, ws_flip_reg_tag,
1269
  ws_flip_ai_info, ws_flip_ai_tag,
1270
- ws_flip_dual_col, ws_flip_dual_state]
 
1271
  ws_dr.input(update_workspace_state, _state_inputs, _state_outputs)
1272
  ws_fs.input(update_workspace_state, _state_inputs, _state_outputs)
1273
  ws_fr.input(update_workspace_state, _state_inputs, _state_outputs)
1274
  ws_fa.input(update_workspace_state, _state_inputs, _state_outputs)
1275
 
1276
- # Output list β€” 29 components
1277
  ws_outs = [ws_status, ws_plot, ws_info, ws_ov_msg, ws_conf,
1278
  ws_fs_col, ws_fd_col,
1279
  ws_dr, ws_fs, ws_fr, ws_fa,
@@ -1283,7 +1307,8 @@ def build_ui():
1283
  ws_exp_data,
1284
  ws_flip_reg_info, ws_flip_reg_tag,
1285
  ws_flip_ai_info, ws_flip_ai_tag,
1286
- ws_flip_dual_col, ws_flip_dual_state]
 
1287
 
1288
  ws_fetch.click(fetch_next, [ws_user], ws_outs)
1289
  ws_submit.click(submit_feedback,
 
508
  None, False, None,
509
  "", None, gr.Column(visible=False), None,
510
  None,
511
+ "", None, "", None, gr.Column(visible=False), None,
512
+ gr.Column(visible=True), gr.Column(visible=True))
513
 
514
 
515
  def fetch_next(username):
 
569
  show_flip_single = flip_reg is not None and overlap and show_fit
570
  show_flip_dual = (not overlap) and show_fit and (
571
  flip_reg is not None or flip_ai is not None)
572
+ # Fit-specific flip sub-section visibility (initial load: both visible)
573
+ show_flip_reg_sub = True
574
+ show_flip_ai_sub = True
575
 
576
  # Single flip info
577
  flip_info = ""
 
606
  flip_reg if overlap else None,
607
  exp_data,
608
  flip_reg_info, None, flip_ai_info, None,
609
+ gr.Column(visible=show_flip_dual), dual_state,
610
+ gr.Column(visible=show_flip_reg_sub),
611
+ gr.Column(visible=show_flip_ai_sub))
612
  except Exception as e:
613
  print(f"fetch_next render error: {e}\n{traceback.format_exc()}")
614
  return _empty_ws(f"❌ Render failed: {e}")
 
762
  """Centralized state recalculation. Called when user changes any rating.
763
  Recomputes flip points, redraws plot, recalculates all visibility.
764
 
765
+ Visibility rules:
766
+ - Explicit "Bad (0)" on DATA β†’ hide ALL fit + flip sections
767
+ - Explicit "Bad (0)" on a FIT β†’ hide only THAT fit's flip section
768
+ - None (cleared) or Borderline/Perfect β†’ show sections
769
  Flip-point gating:
770
+ - Uses effective quality (user > model) for computation
771
 
772
+ Outputs 15 items: (plot, fs_col, fd_col,
773
  flip_info, flip_tag, flip_col, flip_state,
774
  flip_reg_info, flip_reg_tag, flip_ai_info, flip_ai_tag,
775
+ flip_dual_col, flip_dual_state,
776
+ flip_reg_sub, flip_ai_sub)
777
  """
778
  _empty = (None,
779
  gr.Column(visible=True), gr.Column(visible=False),
780
  "", None, gr.Column(visible=False), None,
781
+ "", None, "", None, gr.Column(visible=False), None,
782
+ gr.Column(visible=True), gr.Column(visible=True))
783
  if exp_data is None:
784
  return _empty
785
 
 
790
  mc = (model_preds or {}).get('model_classes', {})
791
 
792
  # ── UI VISIBILITY: only explicit "Bad" hides sections ──
 
793
  ui_show = data_val != 'Bad (0)'
794
 
795
+ # ── Fit-specific UI visibility for flip sections ──
796
+ # Explicit "Bad" on a fit hides only THAT fit's flip section
797
+ fit_s_ui_ok = fit_s_val != 'Bad (0)'
798
+ fit_reg_ui_ok = fit_reg_val != 'Bad (0)'
799
+ fit_ai_ui_ok = fit_ai_val != 'Bad (0)'
800
+
801
  # ── FLIP-POINT GATING: uses effective quality for computation ──
802
  if data_val is not None:
803
  eff_data = RATING_MAP.get(data_val, -1)
 
827
  fig = create_plot(raw_data, fname, reg_params, ai_params, overlap,
828
  flip_reg=flip_reg, flip_ai=flip_ai)
829
 
830
+ # ── Section visibility ──
831
  show_fit_single = overlap and ui_show
832
  show_fit_dual = (not overlap) and ui_show
833
+
834
+ # Single flip: visible only if data OK AND fit not Bad
835
+ show_flip_single = (flip_reg is not None and overlap
836
+ and ui_show and fit_s_ui_ok)
837
+
838
+ # Dual flip: outer container visible if at least one sub-section is active
839
+ show_flip_reg_sub = (flip_reg is not None and ui_show and fit_reg_ui_ok)
840
+ show_flip_ai_sub = (flip_ai is not None and ui_show and fit_ai_ui_ok)
841
+ show_flip_dual = (not overlap) and (show_flip_reg_sub or show_flip_ai_sub)
842
 
843
  # ── Info strings ──
844
  flip_info = ""
 
850
  flip_reg_info = ""
851
  flip_ai_info = ""
852
  if not overlap and ui_show:
853
+ if flip_reg and fit_reg_ui_ok:
854
  flip_reg_info = f"Reg Flip: x = {flip_reg['x']:.5f}, y = {flip_reg['y']:.4f} ({flip_reg['type']})"
855
+ elif data_gate and fit_gate and fit_reg_ui_ok:
856
  flip_reg_info = "No flip point detected."
857
+ if flip_ai and fit_ai_ui_ok:
858
  flip_ai_info = f"AI Flip: x = {flip_ai['x']:.5f}, y = {flip_ai['y']:.4f} ({flip_ai['type']})"
859
+ elif data_gate and ai_fit_gate and fit_ai_ui_ok:
860
  flip_ai_info = "No flip point detected."
861
 
862
  dual_state = {'reg': flip_reg, 'ai': flip_ai} if not overlap else None
 
869
  flip_reg if overlap else None,
870
  flip_reg_info, None, flip_ai_info, None,
871
  gr.Column(visible=show_flip_dual),
872
+ dual_state,
873
+ gr.Column(visible=show_flip_reg_sub),
874
+ gr.Column(visible=show_flip_ai_sub))
875
 
876
 
877
  # ═════════════════════════════════════════════════════════════════════════
 
1250
  with gr.Column(visible=False) as ws_flip_dual_col:
1251
  gr.Markdown("### 🎯 Flip-Point Detection (Diverging Fits)")
1252
  with gr.Row():
1253
+ with gr.Column(visible=True) as ws_flip_reg_sub:
1254
  gr.Markdown("#### 🟦 Regular Fit Flip")
1255
  ws_flip_reg_info = gr.Textbox(
1256
  label="Regular Flip", interactive=False, lines=1)
 
1258
  choices=["βœ… Correct", "❌ Wrong"], value=None,
1259
  label="Regular flip correct?",
1260
  elem_classes=["rating-radio"])
1261
+ with gr.Column(visible=True) as ws_flip_ai_sub:
1262
  gr.Markdown("#### 🟩 AI Fit Flip")
1263
  ws_flip_ai_info = gr.Textbox(
1264
  label="AI Flip", interactive=False, lines=1)
 
1280
  ws_flip_info, ws_flip_tag, ws_flip_col, ws_flip_state,
1281
  ws_flip_reg_info, ws_flip_reg_tag,
1282
  ws_flip_ai_info, ws_flip_ai_tag,
1283
+ ws_flip_dual_col, ws_flip_dual_state,
1284
+ ws_flip_reg_sub, ws_flip_ai_sub])
1285
 
1286
  # Centralized state recalculation on any rating change
1287
  _state_inputs = [ws_dr, ws_fs, ws_fr, ws_fa,
 
1290
  ws_flip_info, ws_flip_tag, ws_flip_col, ws_flip_state,
1291
  ws_flip_reg_info, ws_flip_reg_tag,
1292
  ws_flip_ai_info, ws_flip_ai_tag,
1293
+ ws_flip_dual_col, ws_flip_dual_state,
1294
+ ws_flip_reg_sub, ws_flip_ai_sub]
1295
  ws_dr.input(update_workspace_state, _state_inputs, _state_outputs)
1296
  ws_fs.input(update_workspace_state, _state_inputs, _state_outputs)
1297
  ws_fr.input(update_workspace_state, _state_inputs, _state_outputs)
1298
  ws_fa.input(update_workspace_state, _state_inputs, _state_outputs)
1299
 
1300
+ # Output list β€” 31 components
1301
  ws_outs = [ws_status, ws_plot, ws_info, ws_ov_msg, ws_conf,
1302
  ws_fs_col, ws_fd_col,
1303
  ws_dr, ws_fs, ws_fr, ws_fa,
 
1307
  ws_exp_data,
1308
  ws_flip_reg_info, ws_flip_reg_tag,
1309
  ws_flip_ai_info, ws_flip_ai_tag,
1310
+ ws_flip_dual_col, ws_flip_dual_state,
1311
+ ws_flip_reg_sub, ws_flip_ai_sub]
1312
 
1313
  ws_fetch.click(fetch_next, [ws_user], ws_outs)
1314
  ws_submit.click(submit_feedback,