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