Fernandosr85 commited on
Commit
5ef8f7c
·
verified ·
1 Parent(s): 643c6a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -12
app.py CHANGED
@@ -899,15 +899,51 @@ def build_dynamic_scenarios(max_items: int = 9) -> list[str]:
899
  SCENARIOS = build_dynamic_scenarios()
900
 
901
 
902
- def refresh_scenarios() -> tuple[dict, str]:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
903
  choices = build_dynamic_scenarios()
904
- note = (
905
- "<div style='color:#94a3b8;font-size:0.76rem;font-family:IBM Plex Mono,monospace;margin-top:0.35rem'>"
906
- f"Generated {len(choices)} scenarios from the currently loaded regulatory index. "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
907
  "To reflect new laws or resolutions, update the corpus/index first, then restart or refresh."
908
- "</div>"
909
  )
910
- return gr.update(choices=choices, value=choices[0] if choices else None), note
911
 
912
 
913
  def analyze(query: str) -> tuple[str, str, str]:
@@ -995,13 +1031,15 @@ with gr.Blocks(css=CSS, title="RegTech BR") as demo:
995
  interactive=True,
996
  )
997
 
 
 
998
  with gr.Row():
999
- use_example_btn = gr.Button("Load scenario", elem_classes=["analyze-btn"])
1000
- refresh_scenarios_btn = gr.Button("Refresh scenarios", elem_classes=["analyze-btn"])
1001
 
1002
  scenario_status = gr.HTML(
1003
- "<div style='color:#64748b;font-size:0.74rem;font-family:IBM Plex Mono,monospace;margin-top:0.25rem'>"
1004
- "Scenarios are generated from the indexed regulatory corpus loaded by this Space."
1005
  "</div>"
1006
  )
1007
 
@@ -1024,8 +1062,17 @@ with gr.Blocks(css=CSS, title="RegTech BR") as demo:
1024
  </div>
1025
  """)
1026
 
1027
- use_example_btn.click(fn=lambda example: example or "", inputs=[example_dropdown], outputs=[query_box])
1028
- refresh_scenarios_btn.click(fn=refresh_scenarios, inputs=None, outputs=[example_dropdown, scenario_status])
 
 
 
 
 
 
 
 
 
1029
  analyze_btn.click(fn=analyze, inputs=[query_box], outputs=[report_html, evidence_html, context_box])
1030
  query_box.submit(fn=analyze, inputs=[query_box], outputs=[report_html, evidence_html, context_box])
1031
 
 
899
  SCENARIOS = build_dynamic_scenarios()
900
 
901
 
902
+ def scenario_note(message: str, color: str = "#94a3b8") -> str:
903
+ return (
904
+ f"<div style='color:{color};font-size:0.76rem;"
905
+ "font-family:IBM Plex Mono,monospace;margin-top:0.35rem'>"
906
+ f"{esc(message)}"
907
+ "</div>"
908
+ )
909
+
910
+
911
+ def load_next_scenario(cursor: int | None) -> tuple[str, dict, int, str]:
912
+ """Cycle through generated scenarios one by one.
913
+
914
+ Each click loads a different scenario into the query box, updates the
915
+ dropdown selection, and advances the internal cursor. This avoids the
916
+ previous behavior where the same selected scenario was repeatedly copied.
917
+ """
918
  choices = build_dynamic_scenarios()
919
+ if not choices:
920
+ return (
921
+ "",
922
+ gr.update(choices=[], value=None),
923
+ 0,
924
+ scenario_note("No scenarios were generated from the current index.", "#fca5a5"),
925
+ )
926
+
927
+ try:
928
+ idx = int(cursor or 0) % len(choices)
929
+ except Exception:
930
+ idx = 0
931
+
932
+ scenario = choices[idx]
933
+ next_cursor = (idx + 1) % len(choices)
934
+ note = scenario_note(
935
+ f"Loaded scenario {idx + 1}/{len(choices)}. Click Load next scenario to rotate to another issue."
936
+ )
937
+ return scenario, gr.update(choices=choices, value=scenario), next_cursor, note
938
+
939
+
940
+ def refresh_scenarios() -> tuple[dict, int, str]:
941
+ choices = build_dynamic_scenarios()
942
+ note = scenario_note(
943
+ f"Regenerated {len(choices)} scenarios from the currently loaded regulatory index. "
944
  "To reflect new laws or resolutions, update the corpus/index first, then restart or refresh."
 
945
  )
946
+ return gr.update(choices=choices, value=None), 0, note
947
 
948
 
949
  def analyze(query: str) -> tuple[str, str, str]:
 
1031
  interactive=True,
1032
  )
1033
 
1034
+ scenario_cursor = gr.State(0)
1035
+
1036
  with gr.Row():
1037
+ use_example_btn = gr.Button("Load next scenario", elem_classes=["analyze-btn"])
1038
+ refresh_scenarios_btn = gr.Button("Refresh scenario list", elem_classes=["analyze-btn"])
1039
 
1040
  scenario_status = gr.HTML(
1041
+ "<div style='color:#94a3b8;font-size:0.74rem;font-family:IBM Plex Mono,monospace;margin-top:0.25rem'>"
1042
+ "Scenarios are generated from the indexed regulatory corpus. Click Load next scenario to rotate through them."
1043
  "</div>"
1044
  )
1045
 
 
1062
  </div>
1063
  """)
1064
 
1065
+ example_dropdown.change(fn=lambda example: example or "", inputs=[example_dropdown], outputs=[query_box])
1066
+ use_example_btn.click(
1067
+ fn=load_next_scenario,
1068
+ inputs=[scenario_cursor],
1069
+ outputs=[query_box, example_dropdown, scenario_cursor, scenario_status],
1070
+ )
1071
+ refresh_scenarios_btn.click(
1072
+ fn=refresh_scenarios,
1073
+ inputs=None,
1074
+ outputs=[example_dropdown, scenario_cursor, scenario_status],
1075
+ )
1076
  analyze_btn.click(fn=analyze, inputs=[query_box], outputs=[report_html, evidence_html, context_box])
1077
  query_box.submit(fn=analyze, inputs=[query_box], outputs=[report_html, evidence_html, context_box])
1078