Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
"
|
| 459 |
-
"
|
|
|
|
|
|
|
|
|
|
| 460 |
}
|
| 461 |
|
| 462 |
-
|
| 463 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 600 |
-
"""
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 608 |
|
| 609 |
-
result =
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 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
|
| 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=
|
| 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 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
label="
|
| 884 |
-
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
|
| 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=
|
| 979 |
|
| 980 |
resolve_btn.click(
|
| 981 |
-
fn=
|
| 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 |
|