Update app.py
Browse files
app.py
CHANGED
@@ -162,15 +162,72 @@ def calculate_runway(cash, burn_rate, revenue, growth_rate, months=24):
|
|
162 |
|
163 |
def simulate_decision(cash, burn_rate, revenue, growth_rate,
|
164 |
additional_expenses, new_hires, marketing_increase, growth_impact):
|
165 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
current_runway, current_df = calculate_runway(cash, burn_rate, revenue, growth_rate)
|
167 |
|
|
|
168 |
new_burn_rate = burn_rate + additional_expenses + (new_hires * ENGINEER_SALARY) + marketing_increase
|
169 |
new_growth_rate = growth_rate + growth_impact
|
170 |
|
|
|
171 |
new_runway, new_df = calculate_runway(cash, new_burn_rate, revenue, new_growth_rate)
|
172 |
|
173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
|
175 |
def detect_suspicious_transactions(transactions_df):
|
176 |
"""AI-enhanced suspicious transaction detection"""
|
@@ -480,15 +537,11 @@ def render_financial_dashboard():
|
|
480 |
else:
|
481 |
st.info("Upload cash flow data to see detailed financial charts")
|
482 |
|
483 |
-
|
|
|
|
|
|
|
484 |
"""Render the decision simulator page"""
|
485 |
-
if not st.session_state.current_startup or st.session_state.current_startup not in st.session_state.startups:
|
486 |
-
st.warning("No startup selected. Please upload data first.")
|
487 |
-
render_upload_page()
|
488 |
-
return
|
489 |
-
|
490 |
-
startup_data = st.session_state.startups[st.session_state.current_startup]['profile']
|
491 |
-
|
492 |
st.markdown("<h1 class='main-header'>Decision Simulator</h1>", unsafe_allow_html=True)
|
493 |
st.markdown("<p class='sub-header'>Test the financial impact of business decisions</p>", unsafe_allow_html=True)
|
494 |
|
@@ -528,8 +581,8 @@ def render_decision_simulator():
|
|
528 |
submitted = st.form_submit_button("Simulate Decision")
|
529 |
|
530 |
if submitted:
|
531 |
-
# Calculate current and new runway
|
532 |
-
current_runway, new_runway, current_df, new_df = simulate_decision(
|
533 |
startup_data['cash'],
|
534 |
startup_data['burn_rate'],
|
535 |
startup_data['revenue'],
|
@@ -543,7 +596,7 @@ def render_decision_simulator():
|
|
543 |
# Display results
|
544 |
st.markdown("<h3>Decision Impact Analysis</h3>", unsafe_allow_html=True)
|
545 |
|
546 |
-
# Summary metrics
|
547 |
col1, col2, col3 = st.columns(3)
|
548 |
|
549 |
with col1:
|
@@ -561,7 +614,7 @@ def render_decision_simulator():
|
|
561 |
delta=f"${burn_change:,} ({burn_percentage:.1f}%)",
|
562 |
delta_color="inverse")
|
563 |
|
564 |
-
# Cash projection comparison
|
565 |
st.subheader("Cash Projection Comparison")
|
566 |
|
567 |
# Combine dataframes for comparison
|
@@ -583,40 +636,12 @@ def render_decision_simulator():
|
|
583 |
|
584 |
st.plotly_chart(fig, use_container_width=True)
|
585 |
|
586 |
-
#
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
"{question}"
|
593 |
-
|
594 |
-
Here's their current financial situation:
|
595 |
-
- Current cash: ${startup_data['cash']}
|
596 |
-
- Monthly burn rate: ${startup_data['burn_rate']}
|
597 |
-
- Monthly revenue: ${startup_data['revenue']}
|
598 |
-
- Monthly growth rate: {startup_data['growth_rate'] * 100}%
|
599 |
-
|
600 |
-
They're considering these changes:
|
601 |
-
- Adding {new_hires} new engineers (${ENGINEER_SALARY}/month each)
|
602 |
-
- Increasing marketing budget by ${new_marketing}/month
|
603 |
-
- Adding ${other_expenses}/month in other expenses
|
604 |
-
- Expecting {growth_impact * 100}% additional monthly growth
|
605 |
-
|
606 |
-
Analyze this decision thoroughly:
|
607 |
-
1. Quantify the impact on runway
|
608 |
-
2. Assess the risk level (low, medium, high)
|
609 |
-
3. Compare the ROI potential
|
610 |
-
4. Provide recommendations
|
611 |
-
|
612 |
-
Be direct and specific with numbers and timeframes.
|
613 |
-
""")
|
614 |
-
st.session_state.insights_cache[analysis_key] = analysis
|
615 |
-
|
616 |
-
st.markdown("<div class='advisor-card'>", unsafe_allow_html=True)
|
617 |
-
st.markdown("<span class='ai-badge'>AI Decision Analysis</span>", unsafe_allow_html=True)
|
618 |
-
st.markdown(f"<p class='advice-text'>{st.session_state.insights_cache[analysis_key]}</p>", unsafe_allow_html=True)
|
619 |
-
st.markdown("</div>", unsafe_allow_html=True)
|
620 |
|
621 |
def render_fund_monitoring():
|
622 |
"""Render the fund monitoring page"""
|
|
|
162 |
|
163 |
def simulate_decision(cash, burn_rate, revenue, growth_rate,
|
164 |
additional_expenses, new_hires, marketing_increase, growth_impact):
|
165 |
+
"""
|
166 |
+
Simulate the financial impact of a business decision with AI-powered insights
|
167 |
+
|
168 |
+
Args:
|
169 |
+
- cash: Current cash balance
|
170 |
+
- burn_rate: Current monthly burn rate
|
171 |
+
- revenue: Current monthly revenue
|
172 |
+
- growth_rate: Current monthly growth rate
|
173 |
+
- additional_expenses: Proposed additional monthly expenses
|
174 |
+
- new_hires: Number of new hires
|
175 |
+
- marketing_increase: Proposed marketing budget increase
|
176 |
+
- growth_impact: Expected growth rate impact
|
177 |
+
|
178 |
+
Returns:
|
179 |
+
- current_runway: Current financial runway in months
|
180 |
+
- new_runway: Projected runway after proposed changes
|
181 |
+
- current_df: DataFrame with current financial projection
|
182 |
+
- new_df: DataFrame with projected financial scenario
|
183 |
+
- ai_analysis: AI-generated insights about the decision
|
184 |
+
"""
|
185 |
+
# Calculate current runway
|
186 |
current_runway, current_df = calculate_runway(cash, burn_rate, revenue, growth_rate)
|
187 |
|
188 |
+
# Calculate new financial parameters
|
189 |
new_burn_rate = burn_rate + additional_expenses + (new_hires * ENGINEER_SALARY) + marketing_increase
|
190 |
new_growth_rate = growth_rate + growth_impact
|
191 |
|
192 |
+
# Calculate new runway
|
193 |
new_runway, new_df = calculate_runway(cash, new_burn_rate, revenue, new_growth_rate)
|
194 |
|
195 |
+
# Generate AI analysis of the decision
|
196 |
+
try:
|
197 |
+
ai_analysis = generate_ai_response(f"""
|
198 |
+
You are a strategic financial advisor for startups. Analyze this potential business decision:
|
199 |
+
|
200 |
+
Current Financial Situation:
|
201 |
+
- Cash Balance: ${cash:,}
|
202 |
+
- Monthly Burn Rate: ${burn_rate:,}
|
203 |
+
- Monthly Revenue: ${revenue:,}
|
204 |
+
- Current Growth Rate: {growth_rate * 100:.1f}%
|
205 |
+
- Current Runway: {current_runway} months
|
206 |
+
|
207 |
+
Proposed Changes:
|
208 |
+
- Additional Expenses: ${additional_expenses:,}/month
|
209 |
+
- New Hires: {new_hires} engineers (${new_hires * ENGINEER_SALARY:,}/month)
|
210 |
+
- Marketing Budget Increase: ${marketing_increase:,}/month
|
211 |
+
- Expected Growth Impact: +{growth_impact * 100:.1f}%
|
212 |
+
|
213 |
+
Projected Outcome:
|
214 |
+
- New Burn Rate: ${new_burn_rate:,}/month
|
215 |
+
- New Growth Rate: {new_growth_rate * 100:.1f}%
|
216 |
+
- Projected Runway: {new_runway} months
|
217 |
+
|
218 |
+
Provide a comprehensive analysis addressing:
|
219 |
+
1. Financial feasibility of the proposed changes
|
220 |
+
2. Risk assessment
|
221 |
+
3. Potential strategic benefits
|
222 |
+
4. Recommendations for optimization
|
223 |
+
5. Key metrics to monitor
|
224 |
+
|
225 |
+
Be direct, specific, and provide actionable insights.
|
226 |
+
""", simulate=False)
|
227 |
+
except Exception as e:
|
228 |
+
ai_analysis = f"AI analysis unavailable. Error: {str(e)}"
|
229 |
+
|
230 |
+
return current_runway, new_runway, current_df, new_df, ai_analysis
|
231 |
|
232 |
def detect_suspicious_transactions(transactions_df):
|
233 |
"""AI-enhanced suspicious transaction detection"""
|
|
|
537 |
else:
|
538 |
st.info("Upload cash flow data to see detailed financial charts")
|
539 |
|
540 |
+
|
541 |
+
|
542 |
+
|
543 |
+
def render_decision_simulator(startup_data):
|
544 |
"""Render the decision simulator page"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
545 |
st.markdown("<h1 class='main-header'>Decision Simulator</h1>", unsafe_allow_html=True)
|
546 |
st.markdown("<p class='sub-header'>Test the financial impact of business decisions</p>", unsafe_allow_html=True)
|
547 |
|
|
|
581 |
submitted = st.form_submit_button("Simulate Decision")
|
582 |
|
583 |
if submitted:
|
584 |
+
# Calculate current and new runway with AI analysis
|
585 |
+
current_runway, new_runway, current_df, new_df, ai_analysis = simulate_decision(
|
586 |
startup_data['cash'],
|
587 |
startup_data['burn_rate'],
|
588 |
startup_data['revenue'],
|
|
|
596 |
# Display results
|
597 |
st.markdown("<h3>Decision Impact Analysis</h3>", unsafe_allow_html=True)
|
598 |
|
599 |
+
# Summary metrics (existing code remains the same)
|
600 |
col1, col2, col3 = st.columns(3)
|
601 |
|
602 |
with col1:
|
|
|
614 |
delta=f"${burn_change:,} ({burn_percentage:.1f}%)",
|
615 |
delta_color="inverse")
|
616 |
|
617 |
+
# Cash projection comparison (existing code remains the same)
|
618 |
st.subheader("Cash Projection Comparison")
|
619 |
|
620 |
# Combine dataframes for comparison
|
|
|
636 |
|
637 |
st.plotly_chart(fig, use_container_width=True)
|
638 |
|
639 |
+
# Display AI Analysis (New section)
|
640 |
+
st.markdown("<div class='advisor-card'>", unsafe_allow_html=True)
|
641 |
+
st.markdown("<span class='ai-badge'>AI Decision Analysis</span>", unsafe_allow_html=True)
|
642 |
+
st.markdown(f"<p class='advice-text'>{ai_analysis}</p>", unsafe_allow_html=True)
|
643 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
644 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
645 |
|
646 |
def render_fund_monitoring():
|
647 |
"""Render the fund monitoring page"""
|