import os import subprocess import time import yaml import gradio as gr from aibanking import Jocall3 # 1. Dynamically get the OpenAPI spec from the cloned .stats.yml with open(".stats.yml", 'r') as f: stats = yaml.safe_load(f) OPENAPI_URL = stats.get('openapi_spec_url') # 2. Start Prism in the background on port 4010 print(f"Starting Prism Mock Server...") subprocess.Popen([ "prism", "mock", OPENAPI_URL, "-p", "4010", "-h", "0.0.0.0" ]) # Give Prism time to boot time.sleep(5) # 3. Setup the SDK Client # It handles the 'x-api-key' header automatically client = Jocall3( base_url="http://127.0.0.1:4010", api_key="mock-key-123" ) # 4. App Functions def check_status(): try: status = client.system.get_status() return f"✅ API Status: {status.api_status}\nGemini Uptime: {status.gemini_uptime}" except Exception as e: return f"❌ SDK Error: {str(e)}" def create_demo_account(): try: acc = client.accounts.open( currency="USD", initial_deposit=1000.0, product_type="high_yield_vault" ) return f"Account ID: {acc.id}\nBalance: {acc.current_balance}\nBank: {acc.institution_name}" except Exception as e: return f"❌ Error: {str(e)}" # 5. UI Layout with gr.Blocks(theme=gr.themes.Soft()) as demo: gr.Markdown("# 🏦 Jocall3 AI Banking SDK Demo") gr.Markdown("Running a local **Prism Mock** server against the latest OpenAPI spec.") with gr.Row(): btn_status = gr.Button("Check System Health", variant="primary") btn_acc = gr.Button("Simulate Open Account") output = gr.Textbox(label="Response from SDK", lines=5) btn_status.click(check_status, outputs=output) btn_acc.click(create_demo_account, outputs=output) if __name__ == "__main__": demo.launch(server_name="0.0.0.0", server_port=7860)