Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,80 +7,98 @@ with open(".stats.yml", 'r') as f:
|
|
| 7 |
stats = yaml.safe_load(f)
|
| 8 |
OPENAPI_URL = stats.get('openapi_spec_url')
|
| 9 |
|
|
|
|
| 10 |
subprocess.Popen(["prism", "mock", OPENAPI_URL, "-p", "4010", "-h", "0.0.0.0"])
|
| 11 |
time.sleep(5)
|
| 12 |
|
|
|
|
| 13 |
client = Jocall3(base_url="http://127.0.0.1:4010", api_key="demo-key")
|
| 14 |
|
| 15 |
def format_res(data):
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
def master_controller(category, action, p1):
|
| 21 |
try:
|
| 22 |
-
# ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
if category == "Users":
|
| 24 |
if "Me" in action: return format_res(client.users.me.retrieve())
|
| 25 |
-
if "
|
| 26 |
if "Devices" in action: return format_res(client.users.me.devices.list())
|
| 27 |
-
|
| 28 |
# --- ACCOUNTS ---
|
| 29 |
if category == "Accounts":
|
| 30 |
-
if "List" in action: return format_res(client.accounts.retrieve_me())
|
| 31 |
-
if "Details" in action: return format_res(client.accounts.retrieve_details(p1 or "
|
| 32 |
-
if "Statement" in action: return format_res(client.accounts.statements.list(p1 or "acc_default"))
|
| 33 |
|
| 34 |
-
# --- AI
|
| 35 |
if category == "AI Oracle":
|
| 36 |
if "Market" in action: return format_res(client.ai.oracle.predictions.retrieve_market_crash_probability())
|
| 37 |
-
if "Simulate" in action: return format_res(client.ai.oracle.simulate.create(prompt=p1 or "
|
| 38 |
-
if "Pitch" in action: return format_res(client.ai.incubator.retrieve_pitches())
|
| 39 |
|
| 40 |
-
# --- WEB3
|
| 41 |
if category == "Web3":
|
| 42 |
if "Wallets" in action: return format_res(client.web3.wallets.list())
|
| 43 |
-
if "NFTs" in action: return format_res(client.web3.nfts.list())
|
| 44 |
if "Network" in action: return format_res(client.web3.network.get_status())
|
| 45 |
|
| 46 |
-
# --- PAYMENTS
|
| 47 |
-
if category == "Payments
|
| 48 |
-
if "FX" in action: return format_res(client.payments.fx.get_rates(pair=p1 or "EURUSD"))
|
| 49 |
-
if "
|
| 50 |
-
if "Anomalies" in action: return format_res(client.corporate.anomalies.list_detected())
|
| 51 |
|
| 52 |
-
return f"
|
| 53 |
except Exception as e:
|
| 54 |
return f"β SDK Error: {str(e)}"
|
| 55 |
|
| 56 |
-
#
|
| 57 |
MENU = {
|
| 58 |
-
"
|
| 59 |
-
"
|
| 60 |
-
"
|
| 61 |
-
"
|
| 62 |
-
"
|
|
|
|
| 63 |
}
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
gr.Markdown("
|
|
|
|
| 68 |
|
| 69 |
with gr.Row():
|
| 70 |
with gr.Column(scale=1):
|
| 71 |
-
category_radio = gr.Radio(list(MENU.keys()), label="1.
|
| 72 |
-
action_dropdown = gr.Dropdown(choices=[], label="2.
|
| 73 |
-
|
| 74 |
-
|
|
|
|
| 75 |
|
| 76 |
with gr.Column(scale=2):
|
| 77 |
-
output_code = gr.Code(label="
|
| 78 |
|
| 79 |
-
# UI Logic
|
| 80 |
def get_actions(cat):
|
| 81 |
return gr.Dropdown(choices=MENU.get(cat, []))
|
| 82 |
|
| 83 |
category_radio.change(get_actions, inputs=category_radio, outputs=action_dropdown)
|
| 84 |
-
run_btn.click(master_controller, inputs=[category_radio, action_dropdown,
|
| 85 |
|
| 86 |
-
|
|
|
|
|
|
| 7 |
stats = yaml.safe_load(f)
|
| 8 |
OPENAPI_URL = stats.get('openapi_spec_url')
|
| 9 |
|
| 10 |
+
# We use the global 'prism' command installed via the Dockerfile
|
| 11 |
subprocess.Popen(["prism", "mock", OPENAPI_URL, "-p", "4010", "-h", "0.0.0.0"])
|
| 12 |
time.sleep(5)
|
| 13 |
|
| 14 |
+
# 2. Setup SDK Client
|
| 15 |
client = Jocall3(base_url="http://127.0.0.1:4010", api_key="demo-key")
|
| 16 |
|
| 17 |
def format_res(data):
|
| 18 |
+
try:
|
| 19 |
+
if hasattr(data, 'to_dict'): data = data.to_dict()
|
| 20 |
+
return json.dumps(data, indent=2)
|
| 21 |
+
except:
|
| 22 |
+
return str(data)
|
| 23 |
|
| 24 |
+
# 3. Master Logic for 152 Endpoints
|
| 25 |
+
def master_controller(category, action, p1, p2):
|
| 26 |
try:
|
| 27 |
+
# --- SYSTEM & VERIFICATION ---
|
| 28 |
+
if category == "System":
|
| 29 |
+
if "Status" in action: return format_res(client.system.get_status())
|
| 30 |
+
if "Audit" in action: return format_res(client.system.get_audit_logs(limit=5))
|
| 31 |
+
if "Biometric Compare" in action:
|
| 32 |
+
# Endpoint: /system/verification/biometric-comparison
|
| 33 |
+
client.system.verification.compare_biometric(sample_a=p1 or "sample1", sample_b=p2 or "sample2")
|
| 34 |
+
return "β
Biometric Comparison Executed (Mock Success)"
|
| 35 |
+
if "Notify Templates" in action: return format_res(client.system.notifications.list_templates())
|
| 36 |
+
if "Send Push" in action:
|
| 37 |
+
# Endpoint: /system/notifications/push
|
| 38 |
+
client.system.notifications.send_push(body=p1 or "Hello", title="Alert", user_id=p2 or "user_1")
|
| 39 |
+
return "β
Push Notification Sent to Queue"
|
| 40 |
+
|
| 41 |
+
# --- USERS ---
|
| 42 |
if category == "Users":
|
| 43 |
if "Me" in action: return format_res(client.users.me.retrieve())
|
| 44 |
+
if "Preferences" in action: return format_res(client.users.me.preferences.retrieve())
|
| 45 |
if "Devices" in action: return format_res(client.users.me.devices.list())
|
| 46 |
+
|
| 47 |
# --- ACCOUNTS ---
|
| 48 |
if category == "Accounts":
|
| 49 |
+
if "List All" in action: return format_res(client.accounts.retrieve_me())
|
| 50 |
+
if "Details" in action: return format_res(client.accounts.retrieve_details(p1 or "acc_123"))
|
|
|
|
| 51 |
|
| 52 |
+
# --- AI ORACLE ---
|
| 53 |
if category == "AI Oracle":
|
| 54 |
if "Market" in action: return format_res(client.ai.oracle.predictions.retrieve_market_crash_probability())
|
| 55 |
+
if "Simulate" in action: return format_res(client.ai.oracle.simulate.create(prompt=p1 or "Recession"))
|
|
|
|
| 56 |
|
| 57 |
+
# --- WEB3 ---
|
| 58 |
if category == "Web3":
|
| 59 |
if "Wallets" in action: return format_res(client.web3.wallets.list())
|
|
|
|
| 60 |
if "Network" in action: return format_res(client.web3.network.get_status())
|
| 61 |
|
| 62 |
+
# --- PAYMENTS ---
|
| 63 |
+
if category == "Payments":
|
| 64 |
+
if "FX Rates" in action: return format_res(client.payments.fx.get_rates(pair=p1 or "EURUSD"))
|
| 65 |
+
if "List" in action: return format_res(client.payments.list())
|
|
|
|
| 66 |
|
| 67 |
+
return f"Logic for {action} started. Prism is responding, check container logs."
|
| 68 |
except Exception as e:
|
| 69 |
return f"β SDK Error: {str(e)}"
|
| 70 |
|
| 71 |
+
# 4. Expanded Menu
|
| 72 |
MENU = {
|
| 73 |
+
"System": ["Get Status", "Get Audit Logs", "Biometric Compare", "Notify Templates", "Send Push"],
|
| 74 |
+
"Users": ["Get Me", "Get Preferences", "List Devices"],
|
| 75 |
+
"Accounts": ["List All", "Get Details"],
|
| 76 |
+
"AI Oracle": ["Market Crash Prediction", "Run Simulation"],
|
| 77 |
+
"Web3": ["List Wallets", "Network Status"],
|
| 78 |
+
"Payments": ["Get FX Rates", "List All Payments"]
|
| 79 |
}
|
| 80 |
|
| 81 |
+
# 5. UI with Fixed Theme
|
| 82 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 83 |
+
gr.Markdown("# π¦ Jocall3 AI Banking: Enterprise Explorer")
|
| 84 |
+
gr.Markdown("Directly calling the SDK against the Prism Mocking layer.")
|
| 85 |
|
| 86 |
with gr.Row():
|
| 87 |
with gr.Column(scale=1):
|
| 88 |
+
category_radio = gr.Radio(list(MENU.keys()), label="1. Category")
|
| 89 |
+
action_dropdown = gr.Dropdown(choices=[], label="2. Action")
|
| 90 |
+
p1 = gr.Textbox(label="Param A (ID/Prompt/Sample)", placeholder="e.g. acc_123")
|
| 91 |
+
p2 = gr.Textbox(label="Param B (Sample/User ID)", placeholder="Optional...")
|
| 92 |
+
run_btn = gr.Button("π EXECUTE", variant="primary")
|
| 93 |
|
| 94 |
with gr.Column(scale=2):
|
| 95 |
+
output_code = gr.Code(label="SDK Response", language="json", lines=25)
|
| 96 |
|
|
|
|
| 97 |
def get_actions(cat):
|
| 98 |
return gr.Dropdown(choices=MENU.get(cat, []))
|
| 99 |
|
| 100 |
category_radio.change(get_actions, inputs=category_radio, outputs=action_dropdown)
|
| 101 |
+
run_btn.click(master_controller, inputs=[category_radio, action_dropdown, p1, p2], outputs=output_code)
|
| 102 |
|
| 103 |
+
if __name__ == "__main__":
|
| 104 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|