File size: 8,975 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
def render_ai_financial_advisor(startup_data):
"""
Render the AI financial advisor page with voice chat capabilities.
This feature provides conversational financial guidance to founders through a
natural chat interface with both text and voice responses.
"""
st.markdown("<h1 class='main-header'>AI Financial Advisor</h1>", unsafe_allow_html=True)
st.markdown("<p class='sub-header'>Get expert financial guidance through our AI-powered advisor</p>", unsafe_allow_html=True)
# How AI helps with financial advisory
with st.expander("ℹ️ How AI powers your financial advisor"):
st.markdown("""
### How AI Powers Your Financial Advisor
Our AI financial advisor combines advanced language models with financial expertise:
- **Natural Language Understanding**: The system interprets complex financial questions in plain English
- **Domain-Specific Knowledge**: Our AI is trained on startup finance, venture capital, and financial modeling
- **Context-Aware Responses**: The advisor takes into account your specific financial situation and history
- **Voice Synthesis**: ElevenLabs voice technology creates natural, high-quality voice responses
- **Customized Guidance**: AI tailors advice specifically to your stage, industry, and financial position
This gives founders 24/7 access to high-quality financial guidance without the high cost of consultants.
""")
# Chat container
st.markdown("<div style='background-color: #f8f9fa; padding: 20px; border-radius: 10px; margin-bottom: 20px;'>", unsafe_allow_html=True)
# Display chat history
st.subheader("Chat with your Financial Advisor")
# Initialize chat history if needed
if 'chat_history' not in st.session_state:
st.session_state.chat_history = [
{"role": "assistant", "content": "Hi there! I'm your AI financial advisor. How can I help with your startup's finances today?"}
]
# Display chat messages
for message in st.session_state.chat_history:
if message["role"] == "user":
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)
else:
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)
# Show play button for voice if it exists
if 'audio' in message and message['audio']:
st.audio(message['audio'], format='audio/mp3')
# Input for new message
col1, col2 = st.columns([5, 1])
with col1:
user_input = st.text_input("Ask a financial question", key="user_question")
with col2:
use_voice = st.checkbox("Enable voice", value=True)
# Common financial questions
st.markdown("### Common Questions")
question_cols = st.columns(3)
common_questions = [
"How much runway do we have at our current burn rate?",
"Should we increase our marketing spend given our growth rate?",
"When should we start preparing for our next fundraising round?",
"How can we optimize our burn rate without impacting growth?",
"What metrics should we focus on improving right now?",
"How do our unit economics compare to similar startups?"
]
selected_question = None
for i, question in enumerate(common_questions):
with question_cols[i % 3]:
if st.button(question, key=f"q_{i}"):
selected_question = question
# Process user input (either from text input or selected question)
if user_input or selected_question:
question = user_input or selected_question
# Add user message to chat history
st.session_state.chat_history.append({"role": "user", "content": question})
# Get AI response
response = get_advisory_guidance(question, startup_data)
# Generate voice response if enabled
audio_data = None
if use_voice:
audio_data = generate_voice_response(response)
# Add AI response to chat history
st.session_state.chat_history.append({
"role": "assistant",
"content": response,
"audio": audio_data
})
# Rerun to display updated chat
st.experimental_rerun()
st.markdown("</div>", unsafe_allow_html=True)
# Advanced options
st.subheader("Advanced Tools")
tool_cols = st.columns(3)
with tool_cols[0]:
st.markdown("""
<div style='background-color: white; padding: 15px; border-radius: 10px; height: 200px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);'>
<h4>Financial Model Review</h4>
<p>Upload your financial model for AI analysis and recommendations.</p>
<div style='position: absolute; bottom: 15px;'>
<input type='file' disabled/>
</div>
</div>
""", unsafe_allow_html=True)
with tool_cols[1]:
st.markdown("""
<div style='background-color: white; padding: 15px; border-radius: 10px; height: 200px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);'>
<h4>Investor Pitch Review</h4>
<p>Get AI feedback on your investor pitch deck and financial projections.</p>
<div style='position: absolute; bottom: 15px;'>
<input type='file' disabled/>
</div>
</div>
""", unsafe_allow_html=True)
with tool_cols[2]:
st.markdown("""
<div style='background-color: white; padding: 15px; border-radius: 10px; height: 200px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);'>
<h4>Fundraising Strategy</h4>
<p>Generate a customized fundraising strategy based on your metrics.</p>
<div style='position: absolute; bottom: 15px;'>
<button disabled>Generate Strategy</button>
</div>
</div>
""", unsafe_allow_html=True)
# Book a session CTA
st.markdown("""
<div style='background-color: #e6f7ff; padding: 20px; border-radius: 10px; margin-top: 30px;'>
<h3>Need more in-depth guidance?</h3>
<p>Book a dedicated session with our AI financial advisor for comprehensive analysis and personalized advice.</p>
<a href='#book-a-session'><button>Book a Session</button></a>
</div>
""", unsafe_allow_html=True)
def get_advisory_guidance(question, financial_data):
"""Get strategic guidance for a startup question."""
prompt = f"""
You are a strategic financial advisor for startups. A founder asks:
"{question}"
Here's their current financial situation:
- Stage: {financial_data['stage']}
- 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['last_funding']}
- Team size: {financial_data['employees']}
Provide detailed, actionable advice addressing their question. Include:
1. Clear assessment of their current situation
2. 3-5 specific, actionable recommendations with expected outcomes
3. Relevant metrics they should track
4. Industry benchmarks for comparison
5. Timeline for implementation and results
Be specific with numbers, timeframes, and expected outcomes.
"""
return generate_ai_response(prompt)
def generate_voice_response(text):
"""Generate voice response using ElevenLabs API (simulated)."""
try:
# In a real implementation, this would call the ElevenLabs API
# For demonstration, we'll simulate an audio response
# Simulated audio data (just an empty response)
audio_data = b''
# In a real implementation, you would do something like:
# url = "https://api.elevenlabs.io/v1/text-to-speech/{voice_id}"
# headers = {
# "Accept": "audio/mpeg",
# "Content-Type": "application/json",
# "xi-api-key": st.secrets["ELEVENLABS_API_KEY"]
# }
# data = {
# "text": text,
# "model_id": "eleven_monolingual_v1",
# "voice_settings": {
# "stability": 0.5,
# "similarity_boost": 0.5
# }
# }
# response = requests.post(url, json=data, headers=headers)
# audio_data = response.content
return audio_data
except Exception as e:
st.warning(f"Error generating voice response: {e}")
return None
|