File size: 5,605 Bytes
59e2ce6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
import streamlit as st
import os
from dotenv import load_dotenv
# Import local modules
from src.pages import dashboard, decision_simulator, fund_monitoring, financial_advisor
from src.utils.data_processing import (
generate_sample_startup_data,
generate_sample_cash_flow_data,
generate_sample_transactions_data
)
# Load environment variables
load_dotenv()
# Constants
DEFAULT_GROWTH_RATE = 0.08 # 8% monthly growth
DEFAULT_BURN_RATE = 85000 # $85,000 monthly burn
ENGINEER_SALARY = 10000 # $10,000 monthly cost per engineer ($120K/year)
def main():
"""
Main application entry point for Startup Finance Pilot
"""
# App configuration
st.set_page_config(
page_title="StartupFinancePilot",
page_icon="๐ฐ",
layout="wide",
initial_sidebar_state="expanded"
)
# Custom CSS (you might want to move this to a separate file in a larger project)
st.markdown("""
<style>
/* Your existing CSS styles from previous implementation */
.main-header { font-size: 2.5rem; color: #0066cc; }
.sub-header { font-size: 1.5rem; color: #5c5c5c; }
/* Add more styles as needed */
</style>
""", unsafe_allow_html=True)
# Initialize session state
if 'startups' not in st.session_state:
st.session_state.startups = {}
if 'current_startup' not in st.session_state:
st.session_state.current_startup = None
if 'current_page' not in st.session_state:
st.session_state.current_page = 'upload'
if 'insights_cache' not in st.session_state:
st.session_state.insights_cache = {}
# Add sample data for demonstration
sample_startup = generate_sample_startup_data()
st.session_state.startups[sample_startup['name']] = {
'profile': sample_startup,
'cash_flow': generate_sample_cash_flow_data(),
'transactions': generate_sample_transactions_data()
}
st.session_state.current_startup = sample_startup['name']
# Sidebar navigation
with st.sidebar:
st.title("๐ฐ StartupFinancePilot")
st.write("AI-powered financial assistant for startups")
# Startup selector
if st.session_state.startups:
startup_names = list(st.session_state.startups.keys())
selected_startup = st.selectbox(
"Choose Startup",
startup_names,
index=startup_names.index(st.session_state.current_startup)
)
st.session_state.current_startup = selected_startup
# Show basic startup info
startup_data = st.session_state.startups[selected_startup]['profile']
st.markdown(f"""
**Stage:** {startup_data['stage']}
**Cash:** ${startup_data['cash']:,}
**Monthly Burn:** ${startup_data['burn_rate']:,}
**Monthly Revenue:** ${startup_data['revenue']:,}
""")
# Navigation buttons
st.markdown("<hr>", unsafe_allow_html=True)
page_options = {
"๐ Financial Dashboard": "dashboard",
"๐ฎ Decision Simulator": "simulator",
"๐ต๏ธ Fund Monitoring": "monitoring",
"๐ค AI Financial Advisor": "advisor"
}
for label, page_key in page_options.items():
if st.button(label, use_container_width=True):
st.session_state.current_page = page_key
st.experimental_rerun()
# Render the correct page
if st.session_state.current_page == 'dashboard':
dashboard.render_financial_dashboard(
st.session_state.startups[st.session_state.current_startup]['profile'],
st.session_state.startups[st.session_state.current_startup]['cash_flow']
)
elif st.session_state.current_page == 'simulator':
decision_simulator.render_decision_simulator(
st.session_state.startups[st.session_state.current_startup]['profile']
)
elif st.session_state.current_page == 'monitoring':
fund_monitoring.render_fund_monitoring(
st.session_state.startups[st.session_state.current_startup]['transactions']
)
elif st.session_state.current_page == 'advisor':
financial_advisor.render_ai_financial_advisor(
st.session_state.startups[st.session_state.current_startup]['profile']
)
def validate_gemini_api_key():
"""
Validate the Google Generative AI API key
Returns:
bool: True if API key is valid, False otherwise
"""
try:
import google.generativeai as genai
api_key = os.getenv('GOOGLE_API_KEY')
if not api_key:
st.error("๐จ Google API Key not found. Please set GOOGLE_API_KEY in your .env file.")
return False
genai.configure(api_key=api_key)
model = genai.GenerativeModel('gemini-pro')
# Try a simple test generation
test_response = model.generate_content("Hello, can you confirm the API is working?")
return True
except Exception as e:
st.error(f"๐จ Error validating API key: {e}")
return False
if __name__ == "__main__":
# Check API key before running
if validate_gemini_api_key():
main()
else:
st.warning("Please set up your Google Generative AI API key to use the application.")
|