Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,11 +2,7 @@ import os, subprocess, time, yaml, json, inspect, requests
|
|
| 2 |
import gradio as gr
|
| 3 |
from aibanking import Jocall3
|
| 4 |
|
| 5 |
-
# 1.
|
| 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')
|
|
@@ -14,16 +10,16 @@ with open(".stats.yml", 'r') as f:
|
|
| 14 |
print(f"π Starting Prism Mock Server...")
|
| 15 |
subprocess.Popen(["prism", "mock", OPENAPI_URL, "-p", "4010", "-h", "0.0.0.0"])
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
| 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":
|
| 27 |
timeout=1
|
| 28 |
)
|
| 29 |
if response.status_code < 500:
|
|
@@ -31,44 +27,48 @@ for i in range(max_retries):
|
|
| 31 |
prism_ready = True
|
| 32 |
break
|
| 33 |
except:
|
| 34 |
-
print(f"β³ Waiting for Prism
|
| 35 |
time.sleep(2)
|
| 36 |
|
| 37 |
-
#
|
| 38 |
-
|
| 39 |
-
client = Jocall3(base_url="http://127.0.0.1:4010", api_key=HF_API_KEY)
|
| 40 |
|
| 41 |
-
#
|
| 42 |
RESOURCES = {
|
| 43 |
"Accounts": client.accounts,
|
| 44 |
"Accounts - Statements": client.accounts.statements,
|
| 45 |
"Accounts - Transactions": client.accounts.transactions,
|
| 46 |
"Accounts - Overdraft": client.accounts.overdraft_settings,
|
| 47 |
-
"AI - Oracle": client.ai.oracle,
|
| 48 |
-
"AI - Oracle Predictions": client.ai.oracle.predictions,
|
| 49 |
-
"AI - Oracle Simulations": client.ai.oracle.simulations,
|
| 50 |
"AI - Ads": client.ai.ads,
|
| 51 |
"AI - Ads Generate": client.ai.ads.generate,
|
| 52 |
-
"AI - Incubator": client.ai.incubator,
|
| 53 |
-
"AI - Incubator Pitch": client.ai.incubator.pitch,
|
| 54 |
"AI - Advisor": client.ai.advisor,
|
| 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 -
|
|
|
|
|
|
|
| 63 |
"Corporate - Risk": client.corporate.risk,
|
| 64 |
"Corporate - Fraud": client.corporate.risk.fraud,
|
| 65 |
"Corporate - Fraud Rules": client.corporate.risk.fraud.rules,
|
| 66 |
-
"Corporate -
|
| 67 |
-
"Corporate -
|
|
|
|
|
|
|
| 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,
|
|
@@ -83,74 +83,86 @@ RESOURCES = {
|
|
| 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
|
| 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):
|
| 107 |
res = RESOURCES.get(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 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
-
def
|
| 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
|
| 131 |
except Exception as e:
|
| 132 |
return f"β Error: {str(e)}"
|
| 133 |
|
| 134 |
-
#
|
| 135 |
with gr.Blocks(theme=gr.themes.Default(primary_hue="blue")) as demo:
|
| 136 |
-
gr.Markdown("# ποΈ Jocall3 SDK
|
|
|
|
|
|
|
| 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=
|
| 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=
|
| 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(
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
)
|
| 154 |
|
| 155 |
if __name__ == "__main__":
|
| 156 |
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 Mock Server
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
with open(".stats.yml", 'r') as f:
|
| 7 |
stats = yaml.safe_load(f)
|
| 8 |
OPENAPI_URL = stats.get('openapi_spec_url')
|
|
|
|
| 10 |
print(f"π Starting Prism Mock Server...")
|
| 11 |
subprocess.Popen(["prism", "mock", OPENAPI_URL, "-p", "4010", "-h", "0.0.0.0"])
|
| 12 |
|
| 13 |
+
# 2. Get API Key and Wait for Authorization
|
| 14 |
+
API_KEY = os.environ.get("X_API_KEY", "default-mock-key")
|
| 15 |
max_retries = 30
|
| 16 |
prism_ready = False
|
| 17 |
+
|
| 18 |
for i in range(max_retries):
|
| 19 |
try:
|
|
|
|
| 20 |
response = requests.get(
|
| 21 |
"http://127.0.0.1:4010/system/status",
|
| 22 |
+
headers={"x-api-key": API_KEY},
|
| 23 |
timeout=1
|
| 24 |
)
|
| 25 |
if response.status_code < 500:
|
|
|
|
| 27 |
prism_ready = True
|
| 28 |
break
|
| 29 |
except:
|
| 30 |
+
print(f"β³ Waiting for Prism... ({i+1}/{max_retries})")
|
| 31 |
time.sleep(2)
|
| 32 |
|
| 33 |
+
# 3. Setup SDK Client
|
| 34 |
+
client = Jocall3(base_url="http://127.0.0.1:4010", api_key=API_KEY)
|
|
|
|
| 35 |
|
| 36 |
+
# 4. Map the ENTIRE SDK for 152 Endpoints
|
| 37 |
RESOURCES = {
|
| 38 |
"Accounts": client.accounts,
|
| 39 |
"Accounts - Statements": client.accounts.statements,
|
| 40 |
"Accounts - Transactions": client.accounts.transactions,
|
| 41 |
"Accounts - Overdraft": client.accounts.overdraft_settings,
|
|
|
|
|
|
|
|
|
|
| 42 |
"AI - Ads": client.ai.ads,
|
| 43 |
"AI - Ads Generate": client.ai.ads.generate,
|
|
|
|
|
|
|
| 44 |
"AI - Advisor": client.ai.advisor,
|
| 45 |
"AI - Advisor Chat": client.ai.advisor.chat,
|
| 46 |
"AI - Advisor Tools": client.ai.advisor.tools,
|
| 47 |
"AI - Agent": client.ai.agent,
|
| 48 |
"AI - Agent Prompts": client.ai.agent.prompts,
|
| 49 |
+
"AI - Incubator": client.ai.incubator,
|
| 50 |
+
"AI - Incubator Pitch": client.ai.incubator.pitch,
|
| 51 |
"AI - Models": client.ai.models,
|
| 52 |
+
"AI - Oracle": client.ai.oracle,
|
| 53 |
+
"AI - Oracle Predictions": client.ai.oracle.predictions,
|
| 54 |
+
"AI - Oracle Simulations": client.ai.oracle.simulations,
|
| 55 |
"Corporate": client.corporate,
|
| 56 |
+
"Corporate - Anomalies": client.corporate.anomalies,
|
| 57 |
"Corporate - Compliance": client.corporate.compliance,
|
| 58 |
+
"Corporate - Compliance Audits": client.corporate.compliance.audits,
|
| 59 |
+
"Corporate - Governance": client.corporate.governance,
|
| 60 |
+
"Corporate - Gov Proposals": client.corporate.governance.proposals,
|
| 61 |
"Corporate - Risk": client.corporate.risk,
|
| 62 |
"Corporate - Fraud": client.corporate.risk.fraud,
|
| 63 |
"Corporate - Fraud Rules": client.corporate.risk.fraud.rules,
|
| 64 |
+
"Corporate - Treasury": client.corporate.treasury,
|
| 65 |
+
"Corporate - Treasury CashFlow": client.corporate.treasury.cash_flow,
|
| 66 |
+
"Corporate - Treasury Liquidity": client.corporate.treasury.liquidity,
|
| 67 |
+
"Corporate - Treasury Sweeping": client.corporate.treasury.sweeping,
|
| 68 |
"Investments": client.investments,
|
|
|
|
| 69 |
"Investments - Assets": client.investments.assets,
|
| 70 |
"Investments - Performance": client.investments.performance,
|
| 71 |
+
"Investments - Portfolios": client.investments.portfolios,
|
| 72 |
"Lending": client.lending,
|
| 73 |
"Lending - Applications": client.lending.applications,
|
| 74 |
"Lending - Decisions": client.lending.decisions,
|
|
|
|
| 83 |
"Sustainability - Offsets": client.sustainability.offsets,
|
| 84 |
"System": client.system,
|
| 85 |
"System - Notifications": client.system.notifications,
|
| 86 |
+
"System - Sandbox": client.system.sandbox,
|
| 87 |
"System - Verification": client.system.verification,
|
| 88 |
"System - Webhooks": client.system.webhooks,
|
|
|
|
| 89 |
"Transactions": client.transactions,
|
|
|
|
| 90 |
"Transactions - Insights": client.transactions.insights,
|
| 91 |
+
"Transactions - Recurring": client.transactions.recurring,
|
| 92 |
"Users": client.users,
|
| 93 |
+
"Users - Password Reset": client.users.password_reset,
|
| 94 |
"Users - Me": client.users.me,
|
| 95 |
+
"Users - Me Biometrics": client.users.me.biometrics,
|
| 96 |
"Users - Me Devices": client.users.me.devices,
|
|
|
|
| 97 |
"Users - Me Preferences": client.users.me.preferences,
|
| 98 |
+
"Users - Me Security": client.users.me.security,
|
| 99 |
"Web3": client.web3,
|
|
|
|
|
|
|
| 100 |
"Web3 - Contracts": client.web3.contracts,
|
|
|
|
| 101 |
"Web3 - Network": client.web3.network,
|
| 102 |
+
"Web3 - NFTs": client.web3.nfts,
|
| 103 |
+
"Web3 - Transactions": client.web3.transactions,
|
| 104 |
+
"Web3 - Wallets": client.web3.wallets,
|
| 105 |
}
|
| 106 |
|
| 107 |
+
# --- Logic Handlers ---
|
| 108 |
+
|
| 109 |
def get_methods(res_name):
|
| 110 |
res = RESOURCES.get(res_name)
|
| 111 |
methods = [m for m, _ in inspect.getmembers(res, predicate=inspect.ismethod) if not m.startswith('_')]
|
| 112 |
return gr.Dropdown(choices=sorted(methods))
|
| 113 |
|
| 114 |
def generate_payload(res_name, method_name):
|
| 115 |
+
try:
|
| 116 |
+
res = RESOURCES.get(res_name)
|
| 117 |
+
method = getattr(res, method_name)
|
| 118 |
+
sig = inspect.signature(method)
|
| 119 |
+
payload = {}
|
| 120 |
+
for name, param in sig.parameters.items():
|
| 121 |
+
if name in ['extra_headers', 'extra_query', 'extra_body', 'timeout', 'self']: continue
|
| 122 |
+
if "amount" in name or "deposit" in name or "limit" in name: payload[name] = 1000.0
|
| 123 |
+
elif "id" in name or "token" in name or "iban" in name or "bic" in name: payload[name] = "string_id"
|
| 124 |
+
elif "bool" in str(param.annotation): payload[name] = True
|
| 125 |
+
else: payload[name] = "string"
|
| 126 |
+
return json.dumps(payload, indent=2)
|
| 127 |
+
except:
|
| 128 |
+
return "{}"
|
| 129 |
|
| 130 |
+
def run_api(res_name, method_name, params_json):
|
| 131 |
try:
|
| 132 |
res = RESOURCES.get(res_name)
|
| 133 |
method = getattr(res, method_name)
|
| 134 |
kwargs = json.loads(params_json) if params_json.strip() else {}
|
| 135 |
output = method(**kwargs)
|
| 136 |
if hasattr(output, 'to_dict'): return json.dumps(output.to_dict(), indent=2)
|
| 137 |
+
return json.dumps(output, indent=2) if output is not None else "β
Success: Command Processed"
|
| 138 |
except Exception as e:
|
| 139 |
return f"β Error: {str(e)}"
|
| 140 |
|
| 141 |
+
# --- UI Layout ---
|
| 142 |
with gr.Blocks(theme=gr.themes.Default(primary_hue="blue")) as demo:
|
| 143 |
+
gr.Markdown("# ποΈ Jocall3 SDK Ultimate Explorer")
|
| 144 |
+
gr.Markdown("Testing all 152 endpoints of the `aibanking` SDK via Prism Mocking.")
|
| 145 |
+
|
| 146 |
with gr.Row():
|
| 147 |
with gr.Column(scale=1):
|
| 148 |
+
res_choice = gr.Dropdown(sorted(list(RESOURCES.keys())), label="1. Resource Group")
|
| 149 |
+
method_choice = gr.Dropdown([], label="2. SDK Method")
|
| 150 |
+
params_input = gr.TextArea(label="3. Arguments (Auto-Generated JSON)", lines=12)
|
| 151 |
run_btn = gr.Button("π EXECUTE COMMAND", variant="primary")
|
| 152 |
+
|
| 153 |
with gr.Column(scale=2):
|
| 154 |
+
output_display = gr.Code(label="SDK Response", language="json", lines=30)
|
| 155 |
|
| 156 |
res_choice.change(get_methods, inputs=res_choice, outputs=method_choice)
|
| 157 |
method_choice.change(generate_payload, inputs=[res_choice, method_choice], outputs=params_input)
|
| 158 |
+
|
| 159 |
+
# We name the function run_api here to match the gradio_client requirements
|
| 160 |
run_btn.click(
|
| 161 |
+
run_api,
|
| 162 |
+
inputs=[res_choice, method_choice, params_input],
|
| 163 |
+
outputs=output_display,
|
| 164 |
+
api_name="run_api"
|
| 165 |
+
)
|
| 166 |
|
| 167 |
if __name__ == "__main__":
|
| 168 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|