Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,87 +1,65 @@
|
|
| 1 |
import os
|
| 2 |
-
import sys
|
| 3 |
import subprocess
|
| 4 |
import time
|
| 5 |
-
import
|
| 6 |
-
import
|
| 7 |
-
|
| 8 |
-
# --- 1. CLONE YOUR GITHUB REPO ---
|
| 9 |
-
REPO_URL = "https://github.com/diplomat-bit/aibank.git"
|
| 10 |
-
if not os.path.exists("aibank"):
|
| 11 |
-
print("Cloning repository...")
|
| 12 |
-
subprocess.run(["git", "clone", REPO_URL])
|
| 13 |
-
|
| 14 |
-
# Add your SDK source code to the Python path
|
| 15 |
-
sys.path.append(os.path.abspath("aibank/src"))
|
| 16 |
-
|
| 17 |
-
# --- 2. DOWNLOAD PRISM MOCK SERVER (Standalone Binary) ---
|
| 18 |
-
# Since we might not have NPM, we download the binary directly
|
| 19 |
-
PRISM_BIN = "./prism"
|
| 20 |
-
if not os.path.exists(PRISM_BIN):
|
| 21 |
-
print("Downloading Prism Mock Server binary...")
|
| 22 |
-
url = "https://github.com/stoplightio/prism/releases/download/v5.15.0/prism-linux-x64"
|
| 23 |
-
urllib.request.urlretrieve(url, PRISM_BIN)
|
| 24 |
-
# Make it executable
|
| 25 |
-
st = os.stat(PRISM_BIN)
|
| 26 |
-
os.chmod(PRISM_BIN, st.st_mode | stat.S_IEXEC)
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
from aibanking import Jocall3
|
| 39 |
-
import gradio as gr
|
| 40 |
|
| 41 |
-
#
|
| 42 |
-
#
|
| 43 |
client = Jocall3(
|
| 44 |
base_url="http://127.0.0.1:4010",
|
| 45 |
-
api_key="
|
| 46 |
)
|
| 47 |
|
| 48 |
-
|
|
|
|
| 49 |
try:
|
| 50 |
status = client.system.get_status()
|
| 51 |
-
return {
|
| 52 |
-
"API Status": status.api_status,
|
| 53 |
-
"Mock Server": "Online",
|
| 54 |
-
"Gemini Uptime": status.gemini_uptime,
|
| 55 |
-
"Header Sent": "x-api-key"
|
| 56 |
-
}
|
| 57 |
except Exception as e:
|
| 58 |
-
return f"Error: {str(e)}"
|
| 59 |
|
| 60 |
-
def
|
| 61 |
try:
|
| 62 |
acc = client.accounts.open(
|
| 63 |
currency="USD",
|
| 64 |
-
initial_deposit=
|
| 65 |
product_type="high_yield_vault"
|
| 66 |
)
|
| 67 |
-
return f"Account
|
| 68 |
except Exception as e:
|
| 69 |
-
return f"Error: {str(e)}"
|
| 70 |
|
| 71 |
-
#
|
| 72 |
-
with gr.Blocks(
|
| 73 |
gr.Markdown("# 🏦 Jocall3 AI Banking SDK Demo")
|
| 74 |
-
gr.Markdown(
|
| 75 |
|
| 76 |
with gr.Row():
|
| 77 |
-
btn_status = gr.Button("Check System Health")
|
| 78 |
-
btn_acc = gr.Button("
|
| 79 |
|
| 80 |
-
output = gr.
|
| 81 |
|
| 82 |
-
btn_status.click(
|
| 83 |
-
btn_acc.click(
|
| 84 |
|
| 85 |
if __name__ == "__main__":
|
| 86 |
-
# Hugging Face uses port 7860
|
| 87 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import subprocess
|
| 3 |
import time
|
| 4 |
+
import yaml
|
| 5 |
+
import gradio as gr
|
| 6 |
+
from aibanking import Jocall3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
# 1. Dynamically get the OpenAPI spec from the cloned .stats.yml
|
| 9 |
+
with open(".stats.yml", 'r') as f:
|
| 10 |
+
stats = yaml.safe_load(f)
|
| 11 |
+
OPENAPI_URL = stats.get('openapi_spec_url')
|
| 12 |
|
| 13 |
+
# 2. Start Prism in the background on port 4010
|
| 14 |
+
print(f"Starting Prism Mock Server...")
|
| 15 |
+
subprocess.Popen([
|
| 16 |
+
"prism", "mock", OPENAPI_URL,
|
| 17 |
+
"-p", "4010",
|
| 18 |
+
"-h", "0.0.0.0"
|
| 19 |
+
])
|
| 20 |
|
| 21 |
+
# Give Prism time to boot
|
| 22 |
+
time.sleep(5)
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
# 3. Setup the SDK Client
|
| 25 |
+
# It handles the 'x-api-key' header automatically
|
| 26 |
client = Jocall3(
|
| 27 |
base_url="http://127.0.0.1:4010",
|
| 28 |
+
api_key="mock-key-123"
|
| 29 |
)
|
| 30 |
|
| 31 |
+
# 4. App Functions
|
| 32 |
+
def check_status():
|
| 33 |
try:
|
| 34 |
status = client.system.get_status()
|
| 35 |
+
return f"✅ API Status: {status.api_status}\nGemini Uptime: {status.gemini_uptime}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
except Exception as e:
|
| 37 |
+
return f"❌ SDK Error: {str(e)}"
|
| 38 |
|
| 39 |
+
def create_demo_account():
|
| 40 |
try:
|
| 41 |
acc = client.accounts.open(
|
| 42 |
currency="USD",
|
| 43 |
+
initial_deposit=1000.0,
|
| 44 |
product_type="high_yield_vault"
|
| 45 |
)
|
| 46 |
+
return f"Account ID: {acc.id}\nBalance: {acc.current_balance}\nBank: {acc.institution_name}"
|
| 47 |
except Exception as e:
|
| 48 |
+
return f"❌ Error: {str(e)}"
|
| 49 |
|
| 50 |
+
# 5. UI Layout
|
| 51 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 52 |
gr.Markdown("# 🏦 Jocall3 AI Banking SDK Demo")
|
| 53 |
+
gr.Markdown("Running a local **Prism Mock** server against the latest OpenAPI spec.")
|
| 54 |
|
| 55 |
with gr.Row():
|
| 56 |
+
btn_status = gr.Button("Check System Health", variant="primary")
|
| 57 |
+
btn_acc = gr.Button("Simulate Open Account")
|
| 58 |
|
| 59 |
+
output = gr.Textbox(label="Response from SDK", lines=5)
|
| 60 |
|
| 61 |
+
btn_status.click(check_status, outputs=output)
|
| 62 |
+
btn_acc.click(create_demo_account, outputs=output)
|
| 63 |
|
| 64 |
if __name__ == "__main__":
|
|
|
|
| 65 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|