admin08077 commited on
Commit
946ca42
·
verified ·
1 Parent(s): 3e1c9a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -57
app.py CHANGED
@@ -1,87 +1,65 @@
1
  import os
2
- import sys
3
  import subprocess
4
  import time
5
- import urllib.request
6
- import stat
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
- # --- 3. START THE MOCK SERVER ---
29
- # We use the OpenAPI spec URL found in your repo's .stats.yml
30
- SPEC_URL = "https://storage.googleapis.com/stainless-sdk-openapi-specs/citibank-demo-business-inc-diplomat-bit%2Fjocall3-d15e79b0c3e75e676b0109861fa8142f5121cc917e95d056c3ee9f41f9d803dc.yml"
 
31
 
32
- print("Starting Mock Server on port 4010...")
33
- subprocess.Popen([PRISM_BIN, "mock", SPEC_URL, "-p", "4010", "-h", "0.0.0.0"])
34
- time.sleep(5) # Wait for server to start
 
 
 
 
35
 
36
- # --- 4. IMPORT YOUR SDK AND SETUP GRADIO ---
37
- # Now that the path is set, we can import from your 'aibanking' package
38
- from aibanking import Jocall3
39
- import gradio as gr
40
 
41
- # Initialize client to talk to the local Prism mock
42
- # Your SDK is already hardcoded to send 'x-api-key' automatically
43
  client = Jocall3(
44
  base_url="http://127.0.0.1:4010",
45
- api_key="hf_mock_token_123"
46
  )
47
 
48
- def check_api():
 
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 open_account_demo():
61
  try:
62
  acc = client.accounts.open(
63
  currency="USD",
64
- initial_deposit=5000.0,
65
  product_type="high_yield_vault"
66
  )
67
- return f"Account Created!\nID: {acc.id}\nBalance: {acc.current_balance}"
68
  except Exception as e:
69
- return f"Error: {str(e)}"
70
 
71
- # --- 5. THE UI ---
72
- with gr.Blocks(title="Jocall3 AI Banking Demo") as demo:
73
  gr.Markdown("# 🏦 Jocall3 AI Banking SDK Demo")
74
- gr.Markdown(f"Automatically pulling code from: `{REPO_URL}`")
75
 
76
  with gr.Row():
77
- btn_status = gr.Button("Check System Health")
78
- btn_acc = gr.Button("Test Account Opening")
79
 
80
- output = gr.JSON(label="Response Data")
81
 
82
- btn_status.click(check_api, outputs=output)
83
- btn_acc.click(open_account_demo, outputs=output)
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)