admin08077 commited on
Commit
7823edb
·
verified ·
1 Parent(s): 456ad0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -15
app.py CHANGED
@@ -3,15 +3,12 @@ import requests
3
  import base64
4
  import uuid
5
  import os
6
- from dotenv import load_dotenv
7
  from datetime import datetime, date
8
  import plaid
9
  from plaid import Client as PlaidClient
10
  import stripe
11
 
12
- # Load environment variables from .env file
13
- load_dotenv()
14
-
15
  # Set page config
16
  st.set_page_config(
17
  page_title="TransactPro: Unified Financial Platform",
@@ -26,26 +23,40 @@ st.subheader("Made by Citibank Demo Business Inc.")
26
  # Sidebar for API keys and configuration
27
  st.sidebar.header("API Configuration")
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  # Modern Treasury Configuration
30
  st.sidebar.subheader("Modern Treasury")
31
- mt_api_key = st.sidebar.text_input("Modern Treasury API Key", type="password", value=os.getenv('MT_API_KEY'))
32
- mt_organization_id = st.sidebar.text_input("Organization ID", value=os.getenv('MT_ORG_ID'))
33
 
34
  # Citibank API Configuration
35
  st.sidebar.subheader("Citibank API")
36
- citibank_client_id = st.sidebar.text_input("Citibank Client ID", value=os.getenv('CITIBANK_CLIENT_ID'))
37
- citibank_client_secret = st.sidebar.text_input("Citibank Client Secret", type="password", value=os.getenv('CITIBANK_CLIENT_SECRET'))
38
- citibank_api_key = st.sidebar.text_input("Citibank API Key", value=os.getenv('CITIBANK_API_KEY'))
39
 
40
  # Plaid API Configuration
41
  st.sidebar.subheader("Plaid API")
42
- plaid_client_id = st.sidebar.text_input("Plaid Client ID", value=os.getenv('PLAID_CLIENT_ID'))
43
- plaid_secret = st.sidebar.text_input("Plaid Secret", type="password", value=os.getenv('PLAID_SECRET'))
44
  plaid_env = st.sidebar.selectbox("Plaid Environment", ["sandbox", "development", "production"], index=0)
45
 
46
  # Stripe API Configuration
47
  st.sidebar.subheader("Stripe API")
48
- stripe_api_key = st.sidebar.text_input("Stripe API Key", type="password", value=os.getenv('STRIPE_API_KEY'))
49
  if stripe_api_key:
50
  stripe.api_key = stripe_api_key
51
 
@@ -60,11 +71,8 @@ endpoint_choice = st.selectbox("Choose Service", [
60
  # Helper functions
61
 
62
  def create_basic_auth_header(org_id, api_key):
63
- # Combine Organization ID and API Key, separated by a colon
64
  credentials = f"{org_id}:{api_key}"
65
- # Encode the credentials in base64
66
  base64_credentials = base64.b64encode(credentials.encode()).decode('utf-8')
67
- # Return the full Authorization header
68
  return f"Basic {base64_credentials}"
69
 
70
  def fetch_modern_treasury_data(api_key, org_id, endpoint):
 
3
  import base64
4
  import uuid
5
  import os
6
+ from dotenv import load_dotenv, dotenv_values
7
  from datetime import datetime, date
8
  import plaid
9
  from plaid import Client as PlaidClient
10
  import stripe
11
 
 
 
 
12
  # Set page config
13
  st.set_page_config(
14
  page_title="TransactPro: Unified Financial Platform",
 
23
  # Sidebar for API keys and configuration
24
  st.sidebar.header("API Configuration")
25
 
26
+ # File uploader for .env file
27
+ st.sidebar.subheader("Upload .env File")
28
+ uploaded_env = st.sidebar.file_uploader("Choose a .env file", type="env")
29
+
30
+ if uploaded_env:
31
+ env_data = dotenv_values(stream=uploaded_env)
32
+ st.sidebar.success("Environment variables loaded!")
33
+ else:
34
+ st.sidebar.info("You can upload your .env file to automatically load environment variables.")
35
+
36
+ # Load environment variables either from uploaded .env or default system
37
+ def get_env_var(key, default=""):
38
+ return env_data.get(key) if uploaded_env else os.getenv(key, default)
39
+
40
  # Modern Treasury Configuration
41
  st.sidebar.subheader("Modern Treasury")
42
+ mt_api_key = st.sidebar.text_input("Modern Treasury API Key", type="password", value=get_env_var('MT_API_KEY'))
43
+ mt_organization_id = st.sidebar.text_input("Organization ID", value=get_env_var('MT_ORG_ID'))
44
 
45
  # Citibank API Configuration
46
  st.sidebar.subheader("Citibank API")
47
+ citibank_client_id = st.sidebar.text_input("Citibank Client ID", value=get_env_var('CITIBANK_CLIENT_ID'))
48
+ citibank_client_secret = st.sidebar.text_input("Citibank Client Secret", type="password", value=get_env_var('CITIBANK_CLIENT_SECRET'))
49
+ citibank_api_key = st.sidebar.text_input("Citibank API Key", value=get_env_var('CITIBANK_API_KEY'))
50
 
51
  # Plaid API Configuration
52
  st.sidebar.subheader("Plaid API")
53
+ plaid_client_id = st.sidebar.text_input("Plaid Client ID", value=get_env_var('PLAID_CLIENT_ID'))
54
+ plaid_secret = st.sidebar.text_input("Plaid Secret", type="password", value=get_env_var('PLAID_SECRET'))
55
  plaid_env = st.sidebar.selectbox("Plaid Environment", ["sandbox", "development", "production"], index=0)
56
 
57
  # Stripe API Configuration
58
  st.sidebar.subheader("Stripe API")
59
+ stripe_api_key = st.sidebar.text_input("Stripe API Key", type="password", value=get_env_var('STRIPE_API_KEY'))
60
  if stripe_api_key:
61
  stripe.api_key = stripe_api_key
62
 
 
71
  # Helper functions
72
 
73
  def create_basic_auth_header(org_id, api_key):
 
74
  credentials = f"{org_id}:{api_key}"
 
75
  base64_credentials = base64.b64encode(credentials.encode()).decode('utf-8')
 
76
  return f"Basic {base64_credentials}"
77
 
78
  def fetch_modern_treasury_data(api_key, org_id, endpoint):