admin08077 commited on
Commit
65fe9b3
Β·
verified Β·
1 Parent(s): 70da456

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -33
app.py CHANGED
@@ -2,32 +2,43 @@ import os, subprocess, time, yaml, json, inspect, requests
2
  import gradio as gr
3
  from aibanking import Jocall3
4
 
5
- # 1. Start Prism Mock Server
 
 
 
 
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"πŸš€ Launching Prism for all endpoints...")
11
  subprocess.Popen(["prism", "mock", OPENAPI_URL, "-p", "4010", "-h", "0.0.0.0"])
12
 
13
- # 2. FIX: Wait for a VALID endpoint (/system/status) instead of root (/)
 
14
  max_retries = 30
15
  prism_ready = False
16
  for i in range(max_retries):
17
  try:
18
- # Hit a known endpoint to verify readiness
19
- requests.get("http://127.0.0.1:4010/system/status", timeout=1)
20
- print("βœ… Prism is verified healthy!")
21
- prism_ready = True
22
- break
 
 
 
 
 
23
  except:
24
- print(f"⏳ Waiting for Prism... ({i+1}/{max_retries})")
25
  time.sleep(2)
26
 
27
- # 3. Setup Client
28
- client = Jocall3(base_url="http://127.0.0.1:4010", api_key="boss-mode")
 
29
 
30
- # 4. Map the entire SDK tree
31
  RESOURCES = {
32
  "Accounts": client.accounts,
33
  "Accounts - Statements": client.accounts.statements,
@@ -44,31 +55,52 @@ RESOURCES = {
44
  "AI - Advisor Chat": client.ai.advisor.chat,
45
  "AI - Advisor Tools": client.ai.advisor.tools,
46
  "AI - Agent": client.ai.agent,
 
47
  "AI - Models": client.ai.models,
48
  "Corporate": client.corporate,
49
  "Corporate - Compliance": client.corporate.compliance,
50
  "Corporate - Treasury": client.corporate.treasury,
51
  "Corporate - Risk": client.corporate.risk,
52
  "Corporate - Fraud": client.corporate.risk.fraud,
 
53
  "Corporate - Governance": client.corporate.governance,
 
54
  "Investments": client.investments,
55
  "Investments - Portfolios": client.investments.portfolios,
 
 
56
  "Lending": client.lending,
57
  "Lending - Applications": client.lending.applications,
 
58
  "Marketplace": client.marketplace,
 
59
  "Payments": client.payments,
60
  "Payments - Domestic": client.payments.domestic,
61
  "Payments - International": client.payments.international,
62
  "Payments - FX": client.payments.fx,
63
  "Sustainability": client.sustainability,
 
 
64
  "System": client.system,
65
  "System - Notifications": client.system.notifications,
66
  "System - Verification": client.system.verification,
 
 
67
  "Transactions": client.transactions,
 
 
68
  "Users": client.users,
69
  "Users - Me": client.users.me,
 
 
 
 
70
  "Web3": client.web3,
71
  "Web3 - Wallets": client.web3.wallets,
 
 
 
 
72
  }
73
 
74
  def get_methods(res_name):
@@ -76,47 +108,44 @@ def get_methods(res_name):
76
  methods = [m for m, _ in inspect.getmembers(res, predicate=inspect.ismethod) if not m.startswith('_')]
77
  return gr.Dropdown(choices=sorted(methods))
78
 
79
- def generate_payload_template(res_name, method_name):
80
  res = RESOURCES.get(res_name)
81
  method = getattr(res, method_name)
82
  sig = inspect.signature(method)
83
  payload = {}
84
  for name, param in sig.parameters.items():
85
- if name in ['extra_headers', 'extra_query', 'extra_body', 'timeout', 'self']:
86
- continue
87
- # provide a smart hint based on type
88
- payload[name] = "string" if param.annotation == str else 0.0
89
  return json.dumps(payload, indent=2)
90
 
91
- def run_api(res_name, method_name, params_json):
92
  try:
93
  res = RESOURCES.get(res_name)
94
  method = getattr(res, method_name)
95
  kwargs = json.loads(params_json) if params_json.strip() else {}
96
  output = method(**kwargs)
97
  if hasattr(output, 'to_dict'): return json.dumps(output.to_dict(), indent=2)
98
- return json.dumps(output, indent=2) if output is not None else "βœ… Success: Command accepted by server."
99
  except Exception as e:
100
- return f"❌ SDK Error: {str(e)}"
101
 
102
- # 5. The UI
103
- with gr.Blocks(theme=gr.themes.Default(primary_hue="cyan")) as demo:
104
- gr.Markdown("# πŸ›οΈ Jocall3 AI Banking: The Complete 152-Endpoint Console")
105
- gr.Markdown("This interface dynamically inspects the `aibanking` SDK and generates requests for the local Prism Mock.")
106
-
107
  with gr.Row():
108
  with gr.Column(scale=1):
109
- res_choice = gr.Dropdown(list(RESOURCES.keys()), label="1. Select API Resource Group")
110
- method_choice = gr.Dropdown([], label="2. Select SDK Method")
111
- params_input = gr.TextArea(label="3. Arguments (Auto-Generated JSON)", lines=12)
112
- run_btn = gr.Button("πŸš€ EXECUTE REMOTE CALL", variant="primary")
113
-
114
  with gr.Column(scale=2):
115
- output_display = gr.Code(label="Mock Server Response", language="json", lines=30)
116
 
117
  res_choice.change(get_methods, inputs=res_choice, outputs=method_choice)
118
- method_choice.change(generate_payload_template, inputs=[res_choice, method_choice], outputs=params_input)
119
- run_btn.click(run_api, inputs=[res_choice, method_choice, params_input], outputs=output_display)
120
 
121
  if __name__ == "__main__":
122
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
2
  import gradio as gr
3
  from aibanking import Jocall3
4
 
5
+ # 1. Get your Secret/Env Var
6
+ # Your SDK specifically looks for X_API_KEY, so we pull it here
7
+ HF_API_KEY = os.environ.get("X_API_KEY", "mock-default-key")
8
+
9
+ # 2. Start Prism Mock Server
10
  with open(".stats.yml", 'r') as f:
11
  stats = yaml.safe_load(f)
12
  OPENAPI_URL = stats.get('openapi_spec_url')
13
 
14
+ print(f"πŸš€ Starting Prism Mock Server...")
15
  subprocess.Popen(["prism", "mock", OPENAPI_URL, "-p", "4010", "-h", "0.0.0.0"])
16
 
17
+ # 3. AUTHORIZED Health Check
18
+ # Prism was throwing 401 because we didn't send the key. This fixed it:
19
  max_retries = 30
20
  prism_ready = False
21
  for i in range(max_retries):
22
  try:
23
+ # We send the x-api-key header to satisfy the 'Invalid security scheme' error
24
+ response = requests.get(
25
+ "http://127.0.0.1:4010/system/status",
26
+ headers={"x-api-key": HF_API_KEY},
27
+ timeout=1
28
+ )
29
+ if response.status_code < 500:
30
+ print("βœ… Prism authorized and ready!")
31
+ prism_ready = True
32
+ break
33
  except:
34
+ print(f"⏳ Waiting for Prism to authorize... ({i+1}/{max_retries})")
35
  time.sleep(2)
36
 
37
+ # 4. Setup SDK Client
38
+ # It will use the local mock server but send your real X_API_KEY
39
+ client = Jocall3(base_url="http://127.0.0.1:4010", api_key=HF_API_KEY)
40
 
41
+ # 5. ALL Endpoints Mapping (Complete SDK Tree)
42
  RESOURCES = {
43
  "Accounts": client.accounts,
44
  "Accounts - Statements": client.accounts.statements,
 
55
  "AI - Advisor Chat": client.ai.advisor.chat,
56
  "AI - Advisor Tools": client.ai.advisor.tools,
57
  "AI - Agent": client.ai.agent,
58
+ "AI - Agent Prompts": client.ai.agent.prompts,
59
  "AI - Models": client.ai.models,
60
  "Corporate": client.corporate,
61
  "Corporate - Compliance": client.corporate.compliance,
62
  "Corporate - Treasury": client.corporate.treasury,
63
  "Corporate - Risk": client.corporate.risk,
64
  "Corporate - Fraud": client.corporate.risk.fraud,
65
+ "Corporate - Fraud Rules": client.corporate.risk.fraud.rules,
66
  "Corporate - Governance": client.corporate.governance,
67
+ "Corporate - Anomalies": client.corporate.anomalies,
68
  "Investments": client.investments,
69
  "Investments - Portfolios": client.investments.portfolios,
70
+ "Investments - Assets": client.investments.assets,
71
+ "Investments - Performance": client.investments.performance,
72
  "Lending": client.lending,
73
  "Lending - Applications": client.lending.applications,
74
+ "Lending - Decisions": client.lending.decisions,
75
  "Marketplace": client.marketplace,
76
+ "Marketplace - Offers": client.marketplace.offers,
77
  "Payments": client.payments,
78
  "Payments - Domestic": client.payments.domestic,
79
  "Payments - International": client.payments.international,
80
  "Payments - FX": client.payments.fx,
81
  "Sustainability": client.sustainability,
82
+ "Sustainability - Impact": client.sustainability.impact,
83
+ "Sustainability - Offsets": client.sustainability.offsets,
84
  "System": client.system,
85
  "System - Notifications": client.system.notifications,
86
  "System - Verification": client.system.verification,
87
+ "System - Webhooks": client.system.webhooks,
88
+ "System - Sandbox": client.system.sandbox,
89
  "Transactions": client.transactions,
90
+ "Transactions - Recurring": client.transactions.recurring,
91
+ "Transactions - Insights": client.transactions.insights,
92
  "Users": client.users,
93
  "Users - Me": client.users.me,
94
+ "Users - Me Devices": client.users.me.devices,
95
+ "Users - Me Security": client.users.me.security,
96
+ "Users - Me Preferences": client.users.me.preferences,
97
+ "Users - Me Biometrics": client.users.me.biometrics,
98
  "Web3": client.web3,
99
  "Web3 - Wallets": client.web3.wallets,
100
+ "Web3 - NFTs": client.web3.nfts,
101
+ "Web3 - Contracts": client.web3.contracts,
102
+ "Web3 - Transactions": client.web3.transactions,
103
+ "Web3 - Network": client.web3.network,
104
  }
105
 
106
  def get_methods(res_name):
 
108
  methods = [m for m, _ in inspect.getmembers(res, predicate=inspect.ismethod) if not m.startswith('_')]
109
  return gr.Dropdown(choices=sorted(methods))
110
 
111
+ def generate_payload(res_name, method_name):
112
  res = RESOURCES.get(res_name)
113
  method = getattr(res, method_name)
114
  sig = inspect.signature(method)
115
  payload = {}
116
  for name, param in sig.parameters.items():
117
+ if name in ['extra_headers', 'extra_query', 'extra_body', 'timeout', 'self']: continue
118
+ if "amount" in name or "deposit" in name: payload[name] = 100.0
119
+ elif "id" in name or "token" in name: payload[name] = "string_id"
120
+ else: payload[name] = "string"
121
  return json.dumps(payload, indent=2)
122
 
123
+ def execute(res_name, method_name, params_json):
124
  try:
125
  res = RESOURCES.get(res_name)
126
  method = getattr(res, method_name)
127
  kwargs = json.loads(params_json) if params_json.strip() else {}
128
  output = method(**kwargs)
129
  if hasattr(output, 'to_dict'): return json.dumps(output.to_dict(), indent=2)
130
+ return json.dumps(output, indent=2) if output is not None else "βœ… Command Accepted"
131
  except Exception as e:
132
+ return f"❌ Error: {str(e)}"
133
 
134
+ # 6. The UI
135
+ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue")) as demo:
136
+ gr.Markdown("# πŸ›οΈ Jocall3 SDK: The Complete 152-Endpoint Console")
 
 
137
  with gr.Row():
138
  with gr.Column(scale=1):
139
+ res_choice = gr.Dropdown(sorted(list(RESOURCES.keys())), label="Resource Group")
140
+ method_choice = gr.Dropdown([], label="SDK Method")
141
+ params_input = gr.TextArea(label="Arguments (JSON)", lines=10)
142
+ run_btn = gr.Button("πŸš€ EXECUTE COMMAND", variant="primary")
 
143
  with gr.Column(scale=2):
144
+ output_display = gr.Code(label="SDK Response", language="json", lines=25)
145
 
146
  res_choice.change(get_methods, inputs=res_choice, outputs=method_choice)
147
+ method_choice.change(generate_payload, inputs=[res_choice, method_choice], outputs=params_input)
148
+ run_btn.click(execute, inputs=[res_choice, method_choice, params_input], outputs=output_display)
149
 
150
  if __name__ == "__main__":
151
  demo.launch(server_name="0.0.0.0", server_port=7860)