|
import streamlit as st |
|
import plotly.express as px |
|
import pandas as pd |
|
import google.generativeai as genai |
|
|
|
def render_financial_dashboard(startup_data, cash_flow_df): |
|
"""Render financial dashboard page.""" |
|
st.title("Financial Dashboard") |
|
|
|
|
|
col1, col2, col3, col4 = st.columns(4) |
|
|
|
|
|
runway_months, runway_df = calculate_runway( |
|
startup_data['cash'], |
|
startup_data['burn_rate'], |
|
startup_data['revenue'], |
|
startup_data['growth_rate'] |
|
) |
|
|
|
with col1: |
|
st.metric("Current Cash", f"${startup_data['cash']:,}") |
|
with col2: |
|
st.metric("Monthly Burn", f"${startup_data['burn_rate']:,}") |
|
with col3: |
|
st.metric("Monthly Revenue", f"${startup_data['revenue']:,}") |
|
with col4: |
|
st.metric("Runway", f"{runway_months} months") |
|
|
|
|
|
st.subheader("Financial Overview") |
|
|
|
tab1, tab2, tab3 = st.tabs(["Runway Projection", "Revenue vs. Expenses", "Burn Rate Trend"]) |
|
|
|
with tab1: |
|
|
|
fig = px.line(runway_df.reset_index(), x='index', y='Cumulative_Cash', |
|
title="Cash Runway Projection", |
|
labels={'index': 'Date', 'Cumulative_Cash': 'Remaining Cash'}) |
|
fig.add_hline(y=0, line_dash="dash", line_color="red") |
|
fig.update_layout(height=400) |
|
st.plotly_chart(fig, use_container_width=True) |
|
|
|
|
|
try: |
|
if setup_genai(): |
|
with st.expander("AI Financial Analysis"): |
|
analysis = get_runway_analysis(startup_data) |
|
st.write(analysis) |
|
except Exception as e: |
|
st.error(f"Error generating AI analysis: {e}") |
|
|
|
with tab2: |
|
|
|
rev_exp_df = cash_flow_df.copy() |
|
fig = px.bar(rev_exp_df, x='Month', y=['Revenue', 'Total_Expenses'], |
|
title="Revenue vs. Expenses", |
|
barmode='group', |
|
labels={'value': 'Amount ($)', 'variable': 'Category'}) |
|
fig.update_layout(height=400) |
|
st.plotly_chart(fig, use_container_width=True) |
|
|
|
with tab3: |
|
|
|
fig = px.line(cash_flow_df, x='Month', y='Net_Burn', |
|
title="Monthly Net Burn Trend", |
|
labels={'Net_Burn': 'Net Burn ($)'}) |
|
fig.update_layout(height=400) |
|
st.plotly_chart(fig, use_container_width=True) |
|
|
|
|
|
st.subheader("Expense Breakdown") |
|
|
|
|
|
last_month = cash_flow_df.iloc[-1] |
|
expense_categories = ['Payroll', 'Marketing', 'Office', 'Software', 'Travel', 'Legal', 'Misc'] |
|
expense_values = [last_month[cat] for cat in expense_categories] |
|
|
|
fig = px.pie(values=expense_values, names=expense_categories, |
|
title="Current Month Expense Breakdown") |
|
fig.update_layout(height=400) |
|
st.plotly_chart(fig, use_container_width=True) |
|
|
|
def calculate_runway(initial_cash, monthly_burn, monthly_revenue, growth_rate, months=24): |
|
"""Calculate runway based on current burn rate and revenue growth.""" |
|
from datetime import datetime, timedelta |
|
import pandas as pd |
|
|
|
dates = [datetime.now() + timedelta(days=30*i) for i in range(months)] |
|
df = pd.DataFrame(index=dates, columns=['Cash', 'Revenue', 'Expenses', 'Net_Burn', 'Cumulative_Cash']) |
|
|
|
current_cash = initial_cash |
|
current_revenue = monthly_revenue |
|
df.iloc[0, df.columns.get_loc('Cash')] = current_cash |
|
df.iloc[0, df.columns.get_loc('Revenue')] = current_revenue |
|
df.iloc[0, df.columns.get_loc('Expenses')] = monthly_burn |
|
df.iloc[0, df.columns.get_loc('Net_Burn')] = monthly_burn - current_revenue |
|
df.iloc[0, df.columns.get_loc('Cumulative_Cash')] = current_cash |
|
|
|
runway_months = months |
|
for i in range(1, months): |
|
current_revenue = current_revenue * (1 + growth_rate) |
|
net_burn = monthly_burn - current_revenue |
|
current_cash = current_cash - net_burn |
|
|
|
df.iloc[i, df.columns.get_loc('Cash')] = current_cash |
|
df.iloc[i, df.columns.get_loc('Revenue')] = current_revenue |
|
df.iloc[i, df.columns.get_loc('Expenses')] = monthly_burn |
|
df.iloc[i, df.columns.get_loc('Net_Burn')] = net_burn |
|
df.iloc[i, df.columns.get_loc('Cumulative_Cash')] = current_cash |
|
|
|
if current_cash <= 0: |
|
runway_months = i |
|
break |
|
|
|
return runway_months, df |
|
|
|
def get_runway_analysis(financial_data): |
|
"""Get runway analysis using Gemini.""" |
|
try: |
|
prompt = f""" |
|
You are a financial advisor for startups. Analyze this startup's financial data: |
|
- Current cash: ${financial_data['cash']} |
|
- Monthly burn rate: ${financial_data['burn_rate']} |
|
- Monthly revenue: ${financial_data['revenue']} |
|
- Monthly growth rate: {financial_data['growth_rate'] * 100}% |
|
|
|
Calculate and explain their runway, financial health, and recommendations in a concise paragraph. |
|
""" |
|
|
|
model = genai.GenerativeModel('gemini-pro') |
|
response = model.generate_content(prompt) |
|
|
|
return response.text |
|
except Exception as e: |
|
return f"Error generating runway analysis: {e}" |
|
|
|
def get_fundraising_readiness_analysis(financial_data): |
|
"""Analyze startup's readiness for fundraising.""" |
|
try: |
|
prompt = f""" |
|
You are a fundraising advisor for startups. Evaluate this startup's fundraising readiness: |
|
- Current cash: ${financial_data['cash']} |
|
- Monthly burn rate: ${financial_data['burn_rate']} |
|
- Monthly revenue: ${financial_data['revenue']} |
|
- Monthly growth rate: {financial_data['growth_rate'] * 100}% |
|
- Last funding: {financial_data.get('last_funding', 'Not specified')} |
|
- Company stage: {financial_data.get('stage', 'Not specified')} |
|
|
|
Provide insights on: |
|
1. Current runway and funding needs |
|
2. Attractiveness to potential investors |
|
3. Recommended fundraising strategy |
|
4. Key metrics to improve before fundraising |
|
|
|
Respond in a concise, actionable paragraph. |
|
""" |
|
|
|
model = genai.GenerativeModel('gemini-pro') |
|
response = model.generate_content(prompt) |
|
|
|
return response.text |
|
except Exception as e: |
|
return f"Error generating fundraising readiness analysis: {e}" |
|
|
|
def setup_genai(): |
|
"""Setup Google Generative AI""" |
|
try: |
|
import os |
|
import streamlit as st |
|
|
|
|
|
if 'GOOGLE_API_KEY' in st.secrets: |
|
api_key = st.secrets['GOOGLE_API_KEY'] |
|
|
|
elif 'GOOGLE_API_KEY' in os.environ: |
|
api_key = os.environ['GOOGLE_API_KEY'] |
|
else: |
|
st.warning("Google API key not found. Using simulated AI responses.") |
|
return False |
|
|
|
genai.configure(api_key=api_key) |
|
return True |
|
except Exception as e: |
|
st.error(f"Error setting up Generative AI: {e}") |
|
return False |