Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,104 +1,109 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import subprocess
|
| 3 |
-
import time
|
| 4 |
-
import json
|
| 5 |
-
|
| 6 |
-
import yaml
|
| 7 |
import gradio as gr
|
| 8 |
from aibanking import Jocall3
|
| 9 |
|
| 10 |
-
# 1. Start Prism
|
| 11 |
with open(".stats.yml", 'r') as f:
|
| 12 |
stats = yaml.safe_load(f)
|
| 13 |
OPENAPI_URL = stats.get('openapi_spec_url')
|
| 14 |
|
|
|
|
| 15 |
subprocess.Popen(["prism", "mock", OPENAPI_URL, "-p", "4010", "-h", "0.0.0.0"])
|
| 16 |
time.sleep(5)
|
| 17 |
|
| 18 |
-
# 2. Setup
|
| 19 |
-
client = Jocall3(base_url="http://127.0.0.1:4010", api_key="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
def
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
return str(data)
|
| 27 |
|
| 28 |
-
|
| 29 |
-
def master_controller(category, action, p1, p2):
|
| 30 |
try:
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
if category == "Users":
|
| 45 |
-
if action == "Get Me": return format_res(client.users.me.retrieve())
|
| 46 |
-
if action == "Get Preferences": return format_res(client.users.me.preferences.retrieve())
|
| 47 |
-
if action == "List Devices": return format_res(client.users.me.devices.list())
|
| 48 |
-
|
| 49 |
-
# --- ACCOUNTS ---
|
| 50 |
-
if category == "Accounts":
|
| 51 |
-
if action == "List All": return format_res(client.accounts.retrieve_me())
|
| 52 |
-
if action == "Get Details": return format_res(client.accounts.retrieve_details(p1 or "acc_123"))
|
| 53 |
-
|
| 54 |
-
# --- AI ORACLE ---
|
| 55 |
-
if category == "AI Oracle":
|
| 56 |
-
if action == "Market Crash Prediction": return format_res(client.ai.oracle.predictions.retrieve_market_crash_probability())
|
| 57 |
-
if action == "Run Simulation": return format_res(client.ai.oracle.simulate.create(prompt=p1 or "Global Recession"))
|
| 58 |
-
|
| 59 |
-
# --- WEB3 ---
|
| 60 |
-
if category == "Web3":
|
| 61 |
-
if action == "List Wallets": return format_res(client.web3.wallets.list())
|
| 62 |
-
if action == "Network Status": return format_res(client.web3.network.get_status())
|
| 63 |
-
|
| 64 |
-
# --- PAYMENTS ---
|
| 65 |
-
if category == "Payments":
|
| 66 |
-
if action == "Get FX Rates": return format_res(client.payments.fx.get_rates(pair=p1 or "EURUSD"))
|
| 67 |
-
if action == "List All Payments": return format_res(client.payments.list())
|
| 68 |
-
|
| 69 |
-
return f"Error: Action '{action}' not found in router logic."
|
| 70 |
except Exception as e:
|
| 71 |
-
return f"❌ SDK Error: {str(e)}"
|
| 72 |
|
| 73 |
-
# 4.
|
| 74 |
-
|
| 75 |
-
"
|
| 76 |
-
"
|
| 77 |
-
"Accounts": ["List All", "Get Details"],
|
| 78 |
-
"AI Oracle": ["Market Crash Prediction", "Run Simulation"],
|
| 79 |
-
"Web3": ["List Wallets", "Network Status"],
|
| 80 |
-
"Payments": ["Get FX Rates", "List All Payments"]
|
| 81 |
-
}
|
| 82 |
-
|
| 83 |
-
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 84 |
-
gr.Markdown("# 🏦 Jocall3 AI Banking: Enterprise Explorer")
|
| 85 |
|
| 86 |
with gr.Row():
|
| 87 |
with gr.Column(scale=1):
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
with gr.Column(scale=2):
|
| 95 |
-
|
|
|
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
-
|
| 101 |
-
run_btn.click(master_controller, inputs=[category_radio, action_dropdown, p1, p2], outputs=output_code)
|
| 102 |
|
| 103 |
if __name__ == "__main__":
|
| 104 |
demo.launch()
|
|
|
|
| 1 |
+
import os, subprocess, time, yaml, json, inspect
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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"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,
|
| 22 |
+
"AI - Ads": client.ai.ads,
|
| 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()
|