Delete financial-advisor.py
Browse files- financial-advisor.py +0 -210
financial-advisor.py
DELETED
@@ -1,210 +0,0 @@
|
|
1 |
-
def render_ai_financial_advisor(startup_data):
|
2 |
-
"""
|
3 |
-
Render the AI financial advisor page with voice chat capabilities.
|
4 |
-
|
5 |
-
This feature provides conversational financial guidance to founders through a
|
6 |
-
natural chat interface with both text and voice responses.
|
7 |
-
"""
|
8 |
-
st.markdown("<h1 class='main-header'>AI Financial Advisor</h1>", unsafe_allow_html=True)
|
9 |
-
st.markdown("<p class='sub-header'>Get expert financial guidance through our AI-powered advisor</p>", unsafe_allow_html=True)
|
10 |
-
|
11 |
-
# How AI helps with financial advisory
|
12 |
-
with st.expander("ℹ️ How AI powers your financial advisor"):
|
13 |
-
st.markdown("""
|
14 |
-
### How AI Powers Your Financial Advisor
|
15 |
-
|
16 |
-
Our AI financial advisor combines advanced language models with financial expertise:
|
17 |
-
|
18 |
-
- **Natural Language Understanding**: The system interprets complex financial questions in plain English
|
19 |
-
- **Domain-Specific Knowledge**: Our AI is trained on startup finance, venture capital, and financial modeling
|
20 |
-
- **Context-Aware Responses**: The advisor takes into account your specific financial situation and history
|
21 |
-
- **Voice Synthesis**: ElevenLabs voice technology creates natural, high-quality voice responses
|
22 |
-
- **Customized Guidance**: AI tailors advice specifically to your stage, industry, and financial position
|
23 |
-
|
24 |
-
This gives founders 24/7 access to high-quality financial guidance without the high cost of consultants.
|
25 |
-
""")
|
26 |
-
|
27 |
-
# Chat container
|
28 |
-
st.markdown("<div style='background-color: #f8f9fa; padding: 20px; border-radius: 10px; margin-bottom: 20px;'>", unsafe_allow_html=True)
|
29 |
-
|
30 |
-
# Display chat history
|
31 |
-
st.subheader("Chat with your Financial Advisor")
|
32 |
-
|
33 |
-
# Initialize chat history if needed
|
34 |
-
if 'chat_history' not in st.session_state:
|
35 |
-
st.session_state.chat_history = [
|
36 |
-
{"role": "assistant", "content": "Hi there! I'm your AI financial advisor. How can I help with your startup's finances today?"}
|
37 |
-
]
|
38 |
-
|
39 |
-
# Display chat messages
|
40 |
-
for message in st.session_state.chat_history:
|
41 |
-
if message["role"] == "user":
|
42 |
-
st.markdown(f"<div style='background-color: #e6f7ff; padding: 10px; border-radius: 10px; margin-bottom: 10px;'><strong>You:</strong> {message['content']}</div>", unsafe_allow_html=True)
|
43 |
-
else:
|
44 |
-
st.markdown(f"<div style='background-color: #f0f7ff; padding: 10px; border-radius: 10px; margin-bottom: 10px;'><strong>Financial Advisor:</strong> {message['content']}</div>", unsafe_allow_html=True)
|
45 |
-
|
46 |
-
# Show play button for voice if it exists
|
47 |
-
if 'audio' in message and message['audio']:
|
48 |
-
st.audio(message['audio'], format='audio/mp3')
|
49 |
-
|
50 |
-
# Input for new message
|
51 |
-
col1, col2 = st.columns([5, 1])
|
52 |
-
|
53 |
-
with col1:
|
54 |
-
user_input = st.text_input("Ask a financial question", key="user_question")
|
55 |
-
|
56 |
-
with col2:
|
57 |
-
use_voice = st.checkbox("Enable voice", value=True)
|
58 |
-
|
59 |
-
# Common financial questions
|
60 |
-
st.markdown("### Common Questions")
|
61 |
-
question_cols = st.columns(3)
|
62 |
-
|
63 |
-
common_questions = [
|
64 |
-
"How much runway do we have at our current burn rate?",
|
65 |
-
"Should we increase our marketing spend given our growth rate?",
|
66 |
-
"When should we start preparing for our next fundraising round?",
|
67 |
-
"How can we optimize our burn rate without impacting growth?",
|
68 |
-
"What metrics should we focus on improving right now?",
|
69 |
-
"How do our unit economics compare to similar startups?"
|
70 |
-
]
|
71 |
-
|
72 |
-
selected_question = None
|
73 |
-
|
74 |
-
for i, question in enumerate(common_questions):
|
75 |
-
with question_cols[i % 3]:
|
76 |
-
if st.button(question, key=f"q_{i}"):
|
77 |
-
selected_question = question
|
78 |
-
|
79 |
-
# Process user input (either from text input or selected question)
|
80 |
-
if user_input or selected_question:
|
81 |
-
question = user_input or selected_question
|
82 |
-
|
83 |
-
# Add user message to chat history
|
84 |
-
st.session_state.chat_history.append({"role": "user", "content": question})
|
85 |
-
|
86 |
-
# Get AI response
|
87 |
-
response = get_advisory_guidance(question, startup_data)
|
88 |
-
|
89 |
-
# Generate voice response if enabled
|
90 |
-
audio_data = None
|
91 |
-
if use_voice:
|
92 |
-
audio_data = generate_voice_response(response)
|
93 |
-
|
94 |
-
# Add AI response to chat history
|
95 |
-
st.session_state.chat_history.append({
|
96 |
-
"role": "assistant",
|
97 |
-
"content": response,
|
98 |
-
"audio": audio_data
|
99 |
-
})
|
100 |
-
|
101 |
-
# Rerun to display updated chat
|
102 |
-
st.experimental_rerun()
|
103 |
-
|
104 |
-
st.markdown("</div>", unsafe_allow_html=True)
|
105 |
-
|
106 |
-
# Advanced options
|
107 |
-
st.subheader("Advanced Tools")
|
108 |
-
|
109 |
-
tool_cols = st.columns(3)
|
110 |
-
|
111 |
-
with tool_cols[0]:
|
112 |
-
st.markdown("""
|
113 |
-
<div style='background-color: white; padding: 15px; border-radius: 10px; height: 200px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);'>
|
114 |
-
<h4>Financial Model Review</h4>
|
115 |
-
<p>Upload your financial model for AI analysis and recommendations.</p>
|
116 |
-
<div style='position: absolute; bottom: 15px;'>
|
117 |
-
<input type='file' disabled/>
|
118 |
-
</div>
|
119 |
-
</div>
|
120 |
-
""", unsafe_allow_html=True)
|
121 |
-
|
122 |
-
with tool_cols[1]:
|
123 |
-
st.markdown("""
|
124 |
-
<div style='background-color: white; padding: 15px; border-radius: 10px; height: 200px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);'>
|
125 |
-
<h4>Investor Pitch Review</h4>
|
126 |
-
<p>Get AI feedback on your investor pitch deck and financial projections.</p>
|
127 |
-
<div style='position: absolute; bottom: 15px;'>
|
128 |
-
<input type='file' disabled/>
|
129 |
-
</div>
|
130 |
-
</div>
|
131 |
-
""", unsafe_allow_html=True)
|
132 |
-
|
133 |
-
with tool_cols[2]:
|
134 |
-
st.markdown("""
|
135 |
-
<div style='background-color: white; padding: 15px; border-radius: 10px; height: 200px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);'>
|
136 |
-
<h4>Fundraising Strategy</h4>
|
137 |
-
<p>Generate a customized fundraising strategy based on your metrics.</p>
|
138 |
-
<div style='position: absolute; bottom: 15px;'>
|
139 |
-
<button disabled>Generate Strategy</button>
|
140 |
-
</div>
|
141 |
-
</div>
|
142 |
-
""", unsafe_allow_html=True)
|
143 |
-
|
144 |
-
# Book a session CTA
|
145 |
-
st.markdown("""
|
146 |
-
<div style='background-color: #e6f7ff; padding: 20px; border-radius: 10px; margin-top: 30px;'>
|
147 |
-
<h3>Need more in-depth guidance?</h3>
|
148 |
-
<p>Book a dedicated session with our AI financial advisor for comprehensive analysis and personalized advice.</p>
|
149 |
-
<a href='#book-a-session'><button>Book a Session</button></a>
|
150 |
-
</div>
|
151 |
-
""", unsafe_allow_html=True)
|
152 |
-
|
153 |
-
def get_advisory_guidance(question, financial_data):
|
154 |
-
"""Get strategic guidance for a startup question."""
|
155 |
-
prompt = f"""
|
156 |
-
You are a strategic financial advisor for startups. A founder asks:
|
157 |
-
"{question}"
|
158 |
-
|
159 |
-
Here's their current financial situation:
|
160 |
-
- Stage: {financial_data['stage']}
|
161 |
-
- Current cash: ${financial_data['cash']}
|
162 |
-
- Monthly burn rate: ${financial_data['burn_rate']}
|
163 |
-
- Monthly revenue: ${financial_data['revenue']}
|
164 |
-
- Monthly growth rate: {financial_data['growth_rate'] * 100}%
|
165 |
-
- Last funding: {financial_data['last_funding']}
|
166 |
-
- Team size: {financial_data['employees']}
|
167 |
-
|
168 |
-
Provide detailed, actionable advice addressing their question. Include:
|
169 |
-
1. Clear assessment of their current situation
|
170 |
-
2. 3-5 specific, actionable recommendations with expected outcomes
|
171 |
-
3. Relevant metrics they should track
|
172 |
-
4. Industry benchmarks for comparison
|
173 |
-
5. Timeline for implementation and results
|
174 |
-
|
175 |
-
Be specific with numbers, timeframes, and expected outcomes.
|
176 |
-
"""
|
177 |
-
|
178 |
-
return generate_ai_response(prompt)
|
179 |
-
|
180 |
-
def generate_voice_response(text):
|
181 |
-
"""Generate voice response using ElevenLabs API (simulated)."""
|
182 |
-
try:
|
183 |
-
# In a real implementation, this would call the ElevenLabs API
|
184 |
-
# For demonstration, we'll simulate an audio response
|
185 |
-
|
186 |
-
# Simulated audio data (just an empty response)
|
187 |
-
audio_data = b''
|
188 |
-
|
189 |
-
# In a real implementation, you would do something like:
|
190 |
-
# url = "https://api.elevenlabs.io/v1/text-to-speech/{voice_id}"
|
191 |
-
# headers = {
|
192 |
-
# "Accept": "audio/mpeg",
|
193 |
-
# "Content-Type": "application/json",
|
194 |
-
# "xi-api-key": st.secrets["ELEVENLABS_API_KEY"]
|
195 |
-
# }
|
196 |
-
# data = {
|
197 |
-
# "text": text,
|
198 |
-
# "model_id": "eleven_monolingual_v1",
|
199 |
-
# "voice_settings": {
|
200 |
-
# "stability": 0.5,
|
201 |
-
# "similarity_boost": 0.5
|
202 |
-
# }
|
203 |
-
# }
|
204 |
-
# response = requests.post(url, json=data, headers=headers)
|
205 |
-
# audio_data = response.content
|
206 |
-
|
207 |
-
return audio_data
|
208 |
-
except Exception as e:
|
209 |
-
st.warning(f"Error generating voice response: {e}")
|
210 |
-
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|