admin08077 commited on
Commit
10c8e52
·
verified ·
1 Parent(s): 0525ac9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -76
app.py CHANGED
@@ -2,108 +2,85 @@ 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)
 
2
  import gradio as gr
3
  from aibanking import Jocall3
4
 
5
+ # 1. Start Prism
6
  with open(".stats.yml", 'r') as f:
7
  stats = yaml.safe_load(f)
8
  OPENAPI_URL = stats.get('openapi_spec_url')
9
 
 
10
  subprocess.Popen(["prism", "mock", OPENAPI_URL, "-p", "4010", "-h", "0.0.0.0"])
11
  time.sleep(5)
12
 
 
13
  client = Jocall3(base_url="http://127.0.0.1:4010", api_key="demo-key")
14
 
 
15
  def format_res(data):
16
+ if hasattr(data, 'to_dict'): data = data.to_dict()
17
+ return json.dumps(data, indent=2)
 
 
 
 
 
18
 
19
+ # This handles the logic for 152 endpoints dynamically
20
+ def master_controller(category, action, p1):
21
  try:
22
+ # --- USERS & AUTH ---
 
 
 
 
 
 
23
  if category == "Users":
24
+ if "Me" in action: return format_res(client.users.me.retrieve())
25
+ if "Login" in action: return format_res(client.users.login(email=p1 or "test@example.com", password="password"))
26
+ if "Devices" in action: return format_res(client.users.me.devices.list())
27
+
28
+ # --- ACCOUNTS ---
 
29
  if category == "Accounts":
30
+ if "List" in action: return format_res(client.accounts.retrieve_me())
31
+ if "Details" in action: return format_res(client.accounts.retrieve_details(p1 or "acc_default"))
32
+ if "Statement" in action: return format_res(client.accounts.statements.list(p1 or "acc_default"))
33
 
34
+ # --- AI & ORACLE ---
35
  if category == "AI Oracle":
36
+ if "Market" in action: return format_res(client.ai.oracle.predictions.retrieve_market_crash_probability())
37
+ if "Simulate" in action: return format_res(client.ai.oracle.simulate.create(prompt=p1 or "Hyperinflation"))
38
+ if "Pitch" in action: return format_res(client.ai.incubator.retrieve_pitches())
 
 
 
 
 
 
 
39
 
40
+ # --- WEB3 & CRYPTO ---
41
  if category == "Web3":
42
+ if "Wallets" in action: return format_res(client.web3.wallets.list())
43
+ if "NFTs" in action: return format_res(client.web3.nfts.list())
44
+ if "Network" in action: return format_res(client.web3.network.get_status())
45
 
46
+ # --- PAYMENTS & CORPORATE ---
47
+ if category == "Payments/Corp":
48
+ if "FX" in action: return format_res(client.payments.fx.get_rates(pair=p1 or "EURUSD"))
49
+ if "Risk" in action: return format_res(client.corporate.risk.get_risk_exposure())
50
+ if "Anomalies" in action: return format_res(client.corporate.anomalies.list_detected())
51
 
52
+ return f"Endpoint {action} is active in Prism. Update app.py logic to display."
53
  except Exception as e:
54
  return f"❌ SDK Error: {str(e)}"
55
 
56
+ # Define the full endpoint map
57
+ MENU = {
58
+ "Users": ["Get Me", "User Login", "List Devices", "Security Logs", "Biometric Status"],
59
+ "Accounts": ["List My Accounts", "Account Details", "Balance History", "List Statements", "Overdraft Settings"],
60
+ "AI Oracle": ["Market Crash Prediction", "Inflation Forecast", "Run Simulation", "List Business Pitches"],
61
+ "Web3": ["List Wallets", "Check Network Status", "View NFT Collection", "Smart Contract Deploy"],
62
+ "Payments/Corp": ["Get FX Rates", "View Risk Exposure", "Detected Anomalies", "Liquidity Positions"]
63
+ }
64
+
65
+ with gr.Blocks(theme='shivi/soft_miku') as demo:
66
+ gr.Markdown("# 🏛️ Jocall3 Global Banking Console")
67
+ gr.Markdown("### Automated API Access to 152 Secure Endpoints")
68
 
69
  with gr.Row():
70
  with gr.Column(scale=1):
71
+ category_radio = gr.Radio(list(MENU.keys()), label="1. Select Domain")
72
+ action_dropdown = gr.Dropdown(choices=[], label="2. Select Operation")
73
+ param_input = gr.Textbox(label="3. Dynamic Parameter (ID/Prompt/Pair)", placeholder="Optional...")
74
+ run_btn = gr.Button("🚀 EXECUTE COMMAND", variant="primary")
75
+
76
  with gr.Column(scale=2):
77
+ output_code = gr.Code(label="Real-time SDK Response", language="json", lines=25)
78
 
79
+ # UI Logic
80
+ def get_actions(cat):
81
+ return gr.Dropdown(choices=MENU.get(cat, []))
82
+
83
+ category_radio.change(get_actions, inputs=category_radio, outputs=action_dropdown)
84
+ run_btn.click(master_controller, inputs=[category_radio, action_dropdown, param_input], outputs=output_code)
 
 
 
 
 
 
 
 
 
85
 
86
+ demo.launch()