Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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"π
|
| 11 |
subprocess.Popen(["prism", "mock", OPENAPI_URL, "-p", "4010", "-h", "0.0.0.0"])
|
| 12 |
|
| 13 |
-
#
|
|
|
|
| 14 |
max_retries = 30
|
| 15 |
prism_ready = False
|
| 16 |
for i in range(max_retries):
|
| 17 |
try:
|
| 18 |
-
#
|
| 19 |
-
requests.get(
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
except:
|
| 24 |
-
print(f"β³ Waiting for Prism... ({i+1}/{max_retries})")
|
| 25 |
time.sleep(2)
|
| 26 |
|
| 27 |
-
#
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
-
#
|
| 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
|
| 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 |
-
|
| 87 |
-
|
| 88 |
-
payload[name] = "string"
|
| 89 |
return json.dumps(payload, indent=2)
|
| 90 |
|
| 91 |
-
def
|
| 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 "β
|
| 99 |
except Exception as e:
|
| 100 |
-
return f"β
|
| 101 |
|
| 102 |
-
#
|
| 103 |
-
with gr.Blocks(theme=gr.themes.Default(primary_hue="
|
| 104 |
-
gr.Markdown("# ποΈ Jocall3
|
| 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="
|
| 110 |
-
method_choice = gr.Dropdown([], label="
|
| 111 |
-
params_input = gr.TextArea(label="
|
| 112 |
-
run_btn = gr.Button("π EXECUTE
|
| 113 |
-
|
| 114 |
with gr.Column(scale=2):
|
| 115 |
-
output_display = gr.Code(label="
|
| 116 |
|
| 117 |
res_choice.change(get_methods, inputs=res_choice, outputs=method_choice)
|
| 118 |
-
method_choice.change(
|
| 119 |
-
run_btn.click(
|
| 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)
|