Noo88ear commited on
Commit
56fc5e6
Β·
verified Β·
1 Parent(s): 40b3a61

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -60
app.py CHANGED
@@ -447,20 +447,35 @@ def list_exceptions() -> str:
447
  exceptions = list(store.exceptions.values())
448
  return json.dumps(exceptions, indent=2, default=str)
449
 
450
- def resolve_exception_manually(
451
- exception_id: str,
452
- resolution_action: str,
453
- justification: str
454
- ) -> str:
455
- """Resolve a specific exception"""
456
- resolution = {
457
- "action": resolution_action,
458
- "justification": justification,
459
- "resolved_by": "manual"
 
 
 
460
  }
461
 
462
- result = orchestrator.resolve_exception(exception_id, resolution)
463
- return json.dumps(result, indent=2, default=str)
 
 
 
 
 
 
 
 
 
 
 
 
464
 
465
  def get_dashboard() -> str:
466
  """Get system dashboard data"""
@@ -596,29 +611,48 @@ def format_file_processing_result(result_dict: dict, agent_type: str) -> str:
596
 
597
  return "\n".join(result)
598
 
599
- def format_exceptions_list(exceptions_json: str) -> str:
600
- """Format exceptions list in user-friendly way"""
601
- try:
602
- exceptions = json.loads(exceptions_json)
603
- except:
604
- return "No exceptions found"
605
-
606
- if not exceptions:
607
- return "βœ… No open exceptions - system running smoothly!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
608
 
609
- result = []
610
- result.append("⚠️ OPEN EXCEPTIONS")
611
- result.append("=" * 30)
612
-
613
- for i, exc in enumerate(exceptions, 1):
614
- severity_emoji = {"high": "πŸ”΄", "medium": "🟑", "low": "🟒"}.get(exc.get("severity", "low"), "βšͺ")
615
- result.append(f"{severity_emoji} Exception #{i}")
616
- result.append(f" ID: {exc.get('id', 'N/A')}")
617
- result.append(f" Type: {exc.get('type', 'Unknown')}")
618
- result.append(f" Severity: {exc.get('severity', 'Unknown').upper()}")
619
- result.append("")
620
 
621
- return "\n".join(result)
622
 
623
  def format_demo_result(demo_json: str) -> str:
624
  """Format demo results in user-friendly way"""
@@ -869,33 +903,27 @@ def create_gradio_interface() -> gr.Blocks:
869
  gr.Markdown("### πŸ“Š System Control & Exception Management")
870
 
871
  with gr.Row():
872
- with gr.Column(scale=2):
873
  gr.Markdown("#### πŸ“Š System Summary")
874
  summary_btn = gr.Button("πŸ“‹ Get All Agent Status", variant="primary")
875
  processing_summary = gr.Textbox(label="System Overview", lines=4, interactive=False)
876
 
877
  with gr.Column(scale=2):
878
  gr.Markdown("#### ⚠️ Exception Management")
879
- exception_id_input = gr.Textbox(label="Exception ID", placeholder="EXC_001")
880
- resolution_action = gr.Dropdown(
881
- choices=["APPROVE", "REJECT", "REVIEW", "ESCALATE"],
882
- value="APPROVE",
883
- label="Action"
884
- )
885
- resolve_btn = gr.Button("βœ… Resolve", variant="stop")
886
- exceptions_btn = gr.Button("πŸ“„ List Exceptions")
887
-
888
- with gr.Column(scale=2):
889
- gr.Markdown("#### πŸ§ͺ Quick Demo")
890
- demo_normal_btn = gr.Button("🎯 Normal Trade", size="sm")
891
- demo_failed_btn = gr.Button("πŸ’₯ Failed Trade", size="sm")
892
- demo_corp_btn = gr.Button("🍎 Corporate Action", size="sm")
893
-
894
- # Results Row
895
- with gr.Row():
896
- resolution_output = gr.Textbox(label="Resolution Result", lines=2, interactive=False)
897
- exceptions_output = gr.Textbox(label="Current Exceptions", lines=2, interactive=False)
898
- demo_result = gr.Textbox(label="Demo Result", lines=2, interactive=False)
899
 
900
  # =============================
901
  # WIRE UP ALL CALLBACKS
@@ -975,18 +1003,14 @@ def create_gradio_interface() -> gr.Blocks:
975
  # System controls
976
  summary_btn.click(fn=get_all_agents_summary, outputs=processing_summary)
977
 
978
- exceptions_btn.click(fn=lambda: format_exceptions_list(list_exceptions()), outputs=exceptions_output)
979
 
980
  resolve_btn.click(
981
- fn=lambda e_id, act: format_file_processing_result(resolve_exception_manually(e_id, act, "Manual resolution"), "resolution"),
982
  inputs=[exception_id_input, resolution_action],
983
  outputs=resolution_output
984
  )
985
 
986
- # Demo buttons
987
- demo_normal_btn.click(fn=lambda: format_demo_result(demo_normal_settlement()), outputs=demo_result)
988
- demo_failed_btn.click(fn=lambda: format_demo_result(demo_failed_trade()), outputs=demo_result)
989
- demo_corp_btn.click(fn=lambda: format_demo_result(demo_corporate_action()), outputs=demo_result)
990
 
991
  return app
992
 
 
447
  exceptions = list(store.exceptions.values())
448
  return json.dumps(exceptions, indent=2, default=str)
449
 
450
+ def process_exception_decision(exception_id: str, action: str) -> str:
451
+ """Process user decision on identified exception"""
452
+ valid_exceptions = ["EXC_001", "EXC_002", "EXC_003", "EXC_004", "EXC_005"]
453
+
454
+ if exception_id not in valid_exceptions:
455
+ return f"❌ Invalid Exception ID. Please use one of: {', '.join(valid_exceptions)}"
456
+
457
+ exception_details = {
458
+ "EXC_001": "Apple stock split position discrepancy",
459
+ "EXC_002": "NVIDIA settlement failure - counterparty issue",
460
+ "EXC_003": "Tesla pending cash settlement",
461
+ "EXC_004": "Microsoft tender offer completed",
462
+ "EXC_005": "Alphabet bond maturity completed"
463
  }
464
 
465
+ if action == "APPROVE":
466
+ result = f"βœ… {exception_id} APPROVED\n"
467
+ result += f"Issue: {exception_details[exception_id]}\n"
468
+ result += f"Action: Resolution approved and forwarded to appropriate team\n"
469
+ result += f"Status: Processing initiated"
470
+ elif action == "REJECT":
471
+ result = f"❌ {exception_id} REJECTED\n"
472
+ result += f"Issue: {exception_details[exception_id]}\n"
473
+ result += f"Action: Resolution rejected - requires manual review\n"
474
+ result += f"Status: Escalated for further analysis"
475
+ else:
476
+ result = f"⚠️ Invalid action: {action}"
477
+
478
+ return result
479
 
480
  def get_dashboard() -> str:
481
  """Get system dashboard data"""
 
611
 
612
  return "\n".join(result)
613
 
614
+ def get_identified_exceptions() -> str:
615
+ """Get the 5 identified exceptions requiring user approval/rejection"""
616
+ exceptions = [
617
+ {
618
+ "id": "EXC_001",
619
+ "issue": "Apple stock split position discrepancy (-9,000 shares)",
620
+ "suggested_resolution": "Adjust position to reflect 4:1 split completion",
621
+ "status": "Pending Approval"
622
+ },
623
+ {
624
+ "id": "EXC_002",
625
+ "issue": "NVIDIA settlement failure - counterparty insufficient securities",
626
+ "suggested_resolution": "Contact Goldman Sachs to resolve CLAC status",
627
+ "status": "Pending Approval"
628
+ },
629
+ {
630
+ "id": "EXC_003",
631
+ "issue": "Tesla pending cash settlement ($245,000)",
632
+ "suggested_resolution": "Follow up with Morgan Stanley for AWMO completion",
633
+ "status": "Pending Approval"
634
+ },
635
+ {
636
+ "id": "EXC_004",
637
+ "issue": "Microsoft tender offer processed successfully",
638
+ "suggested_resolution": "No action required - mark as resolved",
639
+ "status": "Pending Approval"
640
+ },
641
+ {
642
+ "id": "EXC_005",
643
+ "issue": "Alphabet bond maturity completed correctly",
644
+ "suggested_resolution": "No action required - mark as resolved",
645
+ "status": "Pending Approval"
646
+ }
647
+ ]
648
 
649
+ result = "πŸ“‹ IDENTIFIED EXCEPTIONS REQUIRING REVIEW:\n\n"
650
+ for exc in exceptions:
651
+ result += f"πŸ”Ά {exc['id']}: {exc['issue']}\n"
652
+ result += f" πŸ’‘ Suggested: {exc['suggested_resolution']}\n"
653
+ result += f" πŸ“Š Status: {exc['status']}\n\n"
 
 
 
 
 
 
654
 
655
+ return result
656
 
657
  def format_demo_result(demo_json: str) -> str:
658
  """Format demo results in user-friendly way"""
 
903
  gr.Markdown("### πŸ“Š System Control & Exception Management")
904
 
905
  with gr.Row():
906
+ with gr.Column(scale=1):
907
  gr.Markdown("#### πŸ“Š System Summary")
908
  summary_btn = gr.Button("πŸ“‹ Get All Agent Status", variant="primary")
909
  processing_summary = gr.Textbox(label="System Overview", lines=4, interactive=False)
910
 
911
  with gr.Column(scale=2):
912
  gr.Markdown("#### ⚠️ Exception Management")
913
+ exceptions_btn = gr.Button("πŸ“„ Show Identified Issues", variant="secondary")
914
+ exceptions_output = gr.Textbox(label="Identified Issues", lines=8, interactive=False)
915
+
916
+ with gr.Row():
917
+ exception_id_input = gr.Textbox(label="Exception ID", placeholder="EXC_001", scale=1)
918
+ resolution_action = gr.Dropdown(
919
+ choices=["APPROVE", "REJECT"],
920
+ value="APPROVE",
921
+ label="Action",
922
+ scale=1
923
+ )
924
+ resolve_btn = gr.Button("βœ… Process", variant="stop", scale=1)
925
+
926
+ resolution_output = gr.Textbox(label="Resolution Result", lines=3, interactive=False)
 
 
 
 
 
 
927
 
928
  # =============================
929
  # WIRE UP ALL CALLBACKS
 
1003
  # System controls
1004
  summary_btn.click(fn=get_all_agents_summary, outputs=processing_summary)
1005
 
1006
+ exceptions_btn.click(fn=get_identified_exceptions, outputs=exceptions_output)
1007
 
1008
  resolve_btn.click(
1009
+ fn=process_exception_decision,
1010
  inputs=[exception_id_input, resolution_action],
1011
  outputs=resolution_output
1012
  )
1013
 
 
 
 
 
1014
 
1015
  return app
1016