admin08077 commited on
Commit
0525ac9
·
verified ·
1 Parent(s): 8bf8a60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -46
app.py CHANGED
@@ -1,65 +1,109 @@
1
- import os
2
- import subprocess
3
- import time
4
- import yaml
5
  import gradio as gr
6
  from aibanking import Jocall3
7
 
8
- # 1. Dynamically get the OpenAPI spec from the cloned .stats.yml
9
  with open(".stats.yml", 'r') as f:
10
  stats = yaml.safe_load(f)
11
  OPENAPI_URL = stats.get('openapi_spec_url')
12
 
13
- # 2. Start Prism in the background on port 4010
14
  print(f"Starting Prism Mock Server...")
15
- subprocess.Popen([
16
- "prism", "mock", OPENAPI_URL,
17
- "-p", "4010",
18
- "-h", "0.0.0.0"
19
- ])
20
-
21
- # Give Prism time to boot
22
- time.sleep(5)
23
-
24
- # 3. Setup the SDK Client
25
- # It handles the 'x-api-key' header automatically
26
- client = Jocall3(
27
- base_url="http://127.0.0.1:4010",
28
- api_key="mock-key-123"
29
- )
30
-
31
- # 4. App Functions
32
- def check_status():
33
  try:
34
- status = client.system.get_status()
35
- return f"✅ API Status: {status.api_status}\nGemini Uptime: {status.gemini_uptime}"
36
- except Exception as e:
37
- return f"❌ SDK Error: {str(e)}"
 
 
38
 
39
- def create_demo_account():
 
40
  try:
41
- acc = client.accounts.open(
42
- currency="USD",
43
- initial_deposit=1000.0,
44
- product_type="high_yield_vault"
45
- )
46
- return f"Account ID: {acc.id}\nBalance: {acc.current_balance}\nBank: {acc.institution_name}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  except Exception as e:
48
- return f"❌ Error: {str(e)}"
49
 
50
- # 5. UI Layout
51
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
52
- gr.Markdown("# 🏦 Jocall3 AI Banking SDK Demo")
53
- gr.Markdown("Running a local **Prism Mock** server against the latest OpenAPI spec.")
54
 
55
  with gr.Row():
56
- btn_status = gr.Button("Check System Health", variant="primary")
57
- btn_acc = gr.Button("Simulate Open Account")
58
-
59
- output = gr.Textbox(label="Response from SDK", lines=5)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
- btn_status.click(check_status, outputs=output)
62
- btn_acc.click(create_demo_account, outputs=output)
63
 
64
  if __name__ == "__main__":
65
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
1
+ import os, subprocess, time, yaml, json
 
 
 
2
  import gradio as gr
3
  from aibanking import Jocall3
4
 
5
+ # 1. Start Prism (using the spec URL in your .stats.yml)
6
  with open(".stats.yml", 'r') as f:
7
  stats = yaml.safe_load(f)
8
  OPENAPI_URL = stats.get('openapi_spec_url')
9
 
 
10
  print(f"Starting Prism Mock Server...")
11
+ subprocess.Popen(["prism", "mock", OPENAPI_URL, "-p", "4010", "-h", "0.0.0.0"])
12
+ time.sleep(5)
13
+
14
+ # 2. Setup SDK Client
15
+ client = Jocall3(base_url="http://127.0.0.1:4010", api_key="demo-key")
16
+
17
+ # --- Helper for pretty printing ---
18
+ def format_res(data):
 
 
 
 
 
 
 
 
 
 
19
  try:
20
+ # If it's a Pydantic model (SDK response), convert to dict
21
+ if hasattr(data, 'to_dict'):
22
+ return json.dumps(data.to_dict(), indent=2)
23
+ return json.dumps(data, indent=2)
24
+ except:
25
+ return str(data)
26
 
27
+ # --- Resource Handlers ---
28
+ def api_router(category, action, param1=None, param2=None):
29
  try:
30
+ # SYSTEM
31
+ if category == "System":
32
+ if action == "Status": return format_res(client.system.get_status())
33
+ if action == "Audit Logs": return format_res(client.system.get_audit_logs(limit=5))
34
+ if action == "Webhooks": return format_res(client.system.webhooks.list())
35
+
36
+ # USERS
37
+ if category == "Users":
38
+ if action == "Me": return format_res(client.users.me.retrieve())
39
+ if action == "Preferences": return format_res(client.users.me.preferences.retrieve())
40
+ if action == "Devices": return format_res(client.users.me.devices.list())
41
+ if action == "Security Log": return format_res(client.users.me.security.retrieve_log())
42
+
43
+ # ACCOUNTS
44
+ if category == "Accounts":
45
+ if action == "List All": return format_res(client.accounts.retrieve_me())
46
+ if action == "Details": return format_res(client.accounts.retrieve_details(param1 or "acc_123"))
47
+ if action == "History": return format_res(client.accounts.retrieve_balance_history(param1 or "acc_123"))
48
+
49
+ # AI ORACLE
50
+ if category == "AI Oracle":
51
+ if action == "Market Crash Prob": return format_res(client.ai.oracle.predictions.retrieve_market_crash_probability())
52
+ if action == "Inflation": return format_res(client.ai.oracle.predictions.retrieve_inflation(region=param1 or "GLOBAL"))
53
+ if action == "Simulate": return format_res(client.ai.oracle.simulate.create(prompt=param1 or "Recession scenario"))
54
+
55
+ # CORPORATE
56
+ if category == "Corporate":
57
+ if action == "Risk Exposure": return format_res(client.corporate.risk.get_risk_exposure())
58
+ if action == "List Cards": return format_res(client.corporate.cards.list_all())
59
+ if action == "Anomalies": return format_res(client.corporate.anomalies.list_detected())
60
+ if action == "Liquidity": return format_res(client.corporate.treasury.get_liquidity_positions())
61
+
62
+ # WEB3
63
+ if category == "Web3":
64
+ if action == "Wallets": return format_res(client.web3.wallets.list())
65
+ if action == "Network": return format_res(client.web3.network.get_status())
66
+ if action == "NFTs": return format_res(client.web3.nfts.list())
67
+
68
+ # PAYMENTS / FX
69
+ if category == "Payments":
70
+ if action == "FX Rates": return format_res(client.payments.fx.get_rates(pair=param1 or "EURUSD"))
71
+ if action == "List Payments": return format_res(client.payments.list())
72
+
73
+ return "Action not implemented in UI yet, but endpoint is live in Prism."
74
  except Exception as e:
75
+ return f"❌ SDK Error: {str(e)}"
76
 
77
+ # --- UI Layout ---
78
+ with gr.Blocks(title="Jocall3 Full API Explorer") as demo:
79
+ gr.Markdown("# 🏛️ Jocall3 AI Banking: 152 Endpoints Live")
80
+ gr.Markdown("Select a category to test the SDK against the Prism Mock Server.")
81
 
82
  with gr.Row():
83
+ with gr.Column(scale=1):
84
+ cat = gr.Radio(["System", "Users", "Accounts", "AI Oracle", "Corporate", "Web3", "Payments"], label="Resource Category")
85
+ act = gr.Dropdown(choices=[], label="Action / Endpoint")
86
+ p1 = gr.Textbox(label="Parameter 1 (ID/Prompt/Region)", visible=True)
87
+ run_btn = gr.Button("Execute Request", variant="primary")
88
+
89
+ with gr.Column(scale=2):
90
+ output = gr.Code(label="SDK JSON Response", language="json", lines=25)
91
+
92
+ # Dynamic Dropdown Logic
93
+ def update_actions(category):
94
+ actions = {
95
+ "System": ["Status", "Audit Logs", "Webhooks"],
96
+ "Users": ["Me", "Preferences", "Devices", "Security Log"],
97
+ "Accounts": ["List All", "Details", "History"],
98
+ "AI Oracle": ["Market Crash Prob", "Inflation", "Simulate"],
99
+ "Corporate": ["Risk Exposure", "List Cards", "Anomalies", "Liquidity"],
100
+ "Web3": ["Wallets", "Network", "NFTs"],
101
+ "Payments": ["FX Rates", "List Payments"]
102
+ }
103
+ return gr.Dropdown(choices=actions.get(category, []))
104
 
105
+ cat.change(update_actions, inputs=cat, outputs=act)
106
+ run_btn.click(api_router, inputs=[cat, act, p1], outputs=output)
107
 
108
  if __name__ == "__main__":
109
  demo.launch(server_name="0.0.0.0", server_port=7860)