admin08077 commited on
Commit
3305861
Β·
verified Β·
1 Parent(s): 6cd083c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -67
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import os, subprocess, time, yaml, json, inspect
2
  import gradio as gr
3
  from aibanking import Jocall3
4
 
@@ -7,15 +7,31 @@ 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 for 152 endpoints...")
 
11
  subprocess.Popen(["prism", "mock", OPENAPI_URL, "-p", "4010", "-h", "0.0.0.0"])
12
- time.sleep(5)
13
 
14
- # 2. Setup Client
15
- client = Jocall3(base_url="http://127.0.0.1:4010", api_key="boss-mode-key")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- # 3. Dynamic SDK Mapping
18
- # This maps the high-level resources in your SDK
19
  RESOURCES = {
20
  "Accounts": client.accounts,
21
  "AI - Oracle": client.ai.oracle,
@@ -23,87 +39,52 @@ RESOURCES = {
23
  "AI - Incubator": client.ai.incubator,
24
  "AI - Advisor": client.ai.advisor,
25
  "AI - Agent": client.ai.agent,
26
- "AI - Models": client.ai.models,
27
  "Corporate": client.corporate,
28
- "Corporate - Compliance": client.corporate.compliance,
29
- "Corporate - Treasury": client.corporate.treasury,
30
  "Corporate - Risk": client.corporate.risk,
31
- "Corporate - Governance": client.corporate.governance,
32
- "Investments": client.investments,
33
- "Lending": client.lending,
34
- "Marketplace": client.marketplace,
35
  "Payments": client.payments,
36
- "Payments - FX": client.payments.fx,
37
- "Sustainability": client.sustainability,
38
  "System": client.system,
39
  "Transactions": client.transactions,
40
- "Users": client.users,
41
- "Users - Me": client.users.me,
42
- "Web3": client.web3,
43
- "Web3 - Wallets": client.web3.wallets,
44
  }
45
 
46
- def get_methods_for_resource(res_name):
47
  res = RESOURCES.get(res_name)
48
- # Get all public methods that aren't built-in properties
49
  methods = [m for m, _ in inspect.getmembers(res, predicate=inspect.ismethod) if not m.startswith('_')]
50
  return gr.Dropdown(choices=methods)
51
 
52
- def execute_call(res_name, method_name, params_json):
 
 
 
 
 
 
 
53
  try:
54
  res = RESOURCES.get(res_name)
55
  method = getattr(res, method_name)
56
-
57
- # Parse parameters from JSON box
58
  kwargs = json.loads(params_json) if params_json.strip() else {}
59
-
60
- # Call the actual SDK
61
  output = method(**kwargs)
62
-
63
- # Format result
64
- if hasattr(output, 'to_dict'):
65
- return json.dumps(output.to_dict(), indent=2)
66
- return json.dumps(output, indent=2) if output is not None else "βœ… Command Executed Successfully (No Content)"
67
  except Exception as e:
68
- return f"❌ SDK Error: {str(e)}\n\nHint: Check if your JSON parameters match the SDK expectations."
69
 
70
- # 4. UI Layout
71
- with gr.Blocks(theme=gr.themes.Default(primary_hue="orange")) as demo:
72
- gr.Markdown("# 🏦 Jocall3 AI Banking: UNLIMITED SDK EXPLORER")
73
- gr.Markdown("### Direct Access to all 152 Endpoints via the aibanking SDK")
74
-
75
  with gr.Row():
76
  with gr.Column(scale=1):
77
- res_choice = gr.Dropdown(list(RESOURCES.keys()), label="1. Select Resource Group")
78
- method_choice = gr.Dropdown([], label="2. Select SDK Method")
79
-
80
- gr.Markdown("#### 3. Parameters (JSON)")
81
- params_input = gr.TextArea(
82
- label="Arguments",
83
- placeholder='{\n "account_id": "string",\n "amount": 100\n}',
84
- lines=8
85
- )
86
-
87
- run_btn = gr.Button("πŸ”₯ EXECUTE SDK CALL", variant="primary")
88
-
89
  with gr.Column(scale=2):
90
- gr.Markdown("#### Live Mock Response")
91
- output_display = gr.Code(label="JSON", language="json", lines=30)
92
-
93
- # UI Interactivity
94
- res_choice.change(get_methods_for_resource, inputs=res_choice, outputs=method_choice)
95
-
96
- # Auto-fill parameter hints when method changes
97
- def update_params_hint(res_name, method_name):
98
- res = RESOURCES.get(res_name)
99
- method = getattr(res, method_name)
100
- sig = inspect.signature(method)
101
- params = {k: "value" for k in sig.parameters.keys() if k not in ['extra_headers', 'extra_query', 'extra_body', 'timeout']}
102
- return json.dumps(params, indent=2)
103
 
104
- method_choice.change(update_params_hint, inputs=[res_choice, method_choice], outputs=params_input)
105
-
106
- run_btn.click(execute_call, inputs=[res_choice, method_choice, params_input], outputs=output_display)
107
 
108
  if __name__ == "__main__":
109
- demo.launch()
 
1
+ import os, subprocess, time, yaml, json, inspect, requests
2
  import gradio as gr
3
  from aibanking import Jocall3
4
 
 
7
  stats = yaml.safe_load(f)
8
  OPENAPI_URL = stats.get('openapi_spec_url')
9
 
10
+ print(f"πŸš€ Starting Prism Mock Server...")
11
+ # Start Prism as a background process
12
  subprocess.Popen(["prism", "mock", OPENAPI_URL, "-p", "4010", "-h", "0.0.0.0"])
 
13
 
14
+ # 2. WAIT for Prism to be healthy (This prevents the 'Restarting' loop)
15
+ max_retries = 20
16
+ prism_ready = False
17
+ for i in range(max_retries):
18
+ try:
19
+ # Try to hit the Prism health check/root
20
+ response = requests.get("http://127.0.0.1:4010", timeout=1)
21
+ print("βœ… Prism is up and running!")
22
+ prism_ready = True
23
+ break
24
+ except:
25
+ print(f"⏳ Waiting for Prism... ({i+1}/{max_retries})")
26
+ time.sleep(2)
27
+
28
+ if not prism_ready:
29
+ print("❌ Prism failed to start. App might crash.")
30
+
31
+ # 3. Setup Client
32
+ client = Jocall3(base_url="http://127.0.0.1:4010", api_key="demo-key")
33
 
34
+ # --- Dynamic Logic ---
 
35
  RESOURCES = {
36
  "Accounts": client.accounts,
37
  "AI - Oracle": client.ai.oracle,
 
39
  "AI - Incubator": client.ai.incubator,
40
  "AI - Advisor": client.ai.advisor,
41
  "AI - Agent": client.ai.agent,
 
42
  "Corporate": client.corporate,
 
 
43
  "Corporate - Risk": client.corporate.risk,
44
+ "Web3 - Wallets": client.web3.wallets,
 
 
 
45
  "Payments": client.payments,
 
 
46
  "System": client.system,
47
  "Transactions": client.transactions,
 
 
 
 
48
  }
49
 
50
+ def get_methods(res_name):
51
  res = RESOURCES.get(res_name)
 
52
  methods = [m for m, _ in inspect.getmembers(res, predicate=inspect.ismethod) if not m.startswith('_')]
53
  return gr.Dropdown(choices=methods)
54
 
55
+ def update_hint(res_name, method_name):
56
+ res = RESOURCES.get(res_name)
57
+ method = getattr(res, method_name)
58
+ sig = inspect.signature(method)
59
+ params = {k: "value" for k in sig.parameters.keys() if k not in ['extra_headers', 'extra_query', 'extra_body', 'timeout']}
60
+ return json.dumps(params, indent=2)
61
+
62
+ def execute(res_name, method_name, params_json):
63
  try:
64
  res = RESOURCES.get(res_name)
65
  method = getattr(res, method_name)
 
 
66
  kwargs = json.loads(params_json) if params_json.strip() else {}
 
 
67
  output = method(**kwargs)
68
+ if hasattr(output, 'to_dict'): return json.dumps(output.to_dict(), indent=2)
69
+ return json.dumps(output, indent=2) if output is not None else "βœ… Success (No Content)"
 
 
 
70
  except Exception as e:
71
+ return f"❌ Error: {str(e)}"
72
 
73
+ # 4. UI
74
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
75
+ gr.Markdown("# 🏦 Jocall3 AI Banking: Enterprise Explorer")
 
 
76
  with gr.Row():
77
  with gr.Column(scale=1):
78
+ res_choice = gr.Dropdown(list(RESOURCES.keys()), label="1. Resource")
79
+ method_choice = gr.Dropdown([], label="2. Method")
80
+ params_input = gr.TextArea(label="3. Arguments (JSON)", lines=8)
81
+ run_btn = gr.Button("πŸš€ EXECUTE", variant="primary")
 
 
 
 
 
 
 
 
82
  with gr.Column(scale=2):
83
+ output_display = gr.Code(label="SDK Response", language="json", lines=25)
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
+ res_choice.change(get_methods, inputs=res_choice, outputs=method_choice)
86
+ method_choice.change(update_hint, inputs=[res_choice, method_choice], outputs=params_input)
87
+ run_btn.click(execute, inputs=[res_choice, method_choice, params_input], outputs=output_display)
88
 
89
  if __name__ == "__main__":
90
+ demo.launch(server_name="0.0.0.0", server_port=7860)