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("

AI Financial Advisor

", unsafe_allow_html=True) st.markdown("

Get expert financial guidance through our AI-powered advisor

", 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("
", 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"
You: {message['content']}
", unsafe_allow_html=True) else: st.markdown(f"
Financial Advisor: {message['content']}
", 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("
", unsafe_allow_html=True) # Advanced options st.subheader("Advanced Tools") tool_cols = st.columns(3) with tool_cols[0]: st.markdown("""

Financial Model Review

Upload your financial model for AI analysis and recommendations.

""", unsafe_allow_html=True) with tool_cols[1]: st.markdown("""

Investor Pitch Review

Get AI feedback on your investor pitch deck and financial projections.

""", unsafe_allow_html=True) with tool_cols[2]: st.markdown("""

Fundraising Strategy

Generate a customized fundraising strategy based on your metrics.

""", unsafe_allow_html=True) # Book a session CTA st.markdown("""

Need more in-depth guidance?

Book a dedicated session with our AI financial advisor for comprehensive analysis and personalized advice.

""", 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