Update app.py
Browse files
app.py
CHANGED
@@ -707,7 +707,6 @@ def render_ai_financial_advisor():
|
|
707 |
"""Render the AI financial advisor page with voice chat"""
|
708 |
if not st.session_state.current_startup or st.session_state.current_startup not in st.session_state.startups:
|
709 |
st.warning("No startup selected. Please upload data first.")
|
710 |
-
render_upload_page()
|
711 |
return
|
712 |
|
713 |
startup_data = st.session_state.startups[st.session_state.current_startup]['profile']
|
@@ -726,7 +725,10 @@ def render_ai_financial_advisor():
|
|
726 |
|
727 |
# Show play button for voice if it exists
|
728 |
if 'audio' in message and message['audio']:
|
729 |
-
|
|
|
|
|
|
|
730 |
|
731 |
# Input for new message
|
732 |
col1, col2 = st.columns([5, 1])
|
@@ -735,7 +737,7 @@ def render_ai_financial_advisor():
|
|
735 |
user_input = st.text_input("Ask a financial question", key="user_question")
|
736 |
|
737 |
with col2:
|
738 |
-
use_voice = st.checkbox("
|
739 |
|
740 |
# Common financial questions
|
741 |
st.markdown("### Common Questions")
|
@@ -752,6 +754,15 @@ def render_ai_financial_advisor():
|
|
752 |
if st.button(question, key=f"q_{i}"):
|
753 |
user_input = question
|
754 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
755 |
# Process user input
|
756 |
if user_input:
|
757 |
# Add user message to chat history
|
@@ -776,7 +787,8 @@ def render_ai_financial_advisor():
|
|
776 |
# Generate voice response if enabled
|
777 |
audio_data = None
|
778 |
if use_voice:
|
779 |
-
|
|
|
780 |
|
781 |
# Add AI response to chat history
|
782 |
st.session_state.chat_history.append({
|
@@ -789,6 +801,7 @@ def render_ai_financial_advisor():
|
|
789 |
st.rerun()
|
790 |
|
791 |
st.markdown("</div>", unsafe_allow_html=True)
|
|
|
792 |
|
793 |
# Main function
|
794 |
def main():
|
|
|
707 |
"""Render the AI financial advisor page with voice chat"""
|
708 |
if not st.session_state.current_startup or st.session_state.current_startup not in st.session_state.startups:
|
709 |
st.warning("No startup selected. Please upload data first.")
|
|
|
710 |
return
|
711 |
|
712 |
startup_data = st.session_state.startups[st.session_state.current_startup]['profile']
|
|
|
725 |
|
726 |
# Show play button for voice if it exists
|
727 |
if 'audio' in message and message['audio']:
|
728 |
+
try:
|
729 |
+
st.audio(message['audio'], format='audio/mp3')
|
730 |
+
except Exception as e:
|
731 |
+
st.error(f"Error playing audio: {e}")
|
732 |
|
733 |
# Input for new message
|
734 |
col1, col2 = st.columns([5, 1])
|
|
|
737 |
user_input = st.text_input("Ask a financial question", key="user_question")
|
738 |
|
739 |
with col2:
|
740 |
+
use_voice = st.checkbox("Voice", value=True)
|
741 |
|
742 |
# Common financial questions
|
743 |
st.markdown("### Common Questions")
|
|
|
754 |
if st.button(question, key=f"q_{i}"):
|
755 |
user_input = question
|
756 |
|
757 |
+
# Test voice directly
|
758 |
+
if st.button("🔊 Test Voice Generation"):
|
759 |
+
test_audio = generate_voice_response("This is a test of the ElevenLabs voice generation system.")
|
760 |
+
if test_audio:
|
761 |
+
st.audio(test_audio, format='audio/mp3')
|
762 |
+
st.success("Voice generation is working! If you can't hear anything, check your audio settings.")
|
763 |
+
else:
|
764 |
+
st.error("Voice generation failed. Please check the error messages above.")
|
765 |
+
|
766 |
# Process user input
|
767 |
if user_input:
|
768 |
# Add user message to chat history
|
|
|
787 |
# Generate voice response if enabled
|
788 |
audio_data = None
|
789 |
if use_voice:
|
790 |
+
with st.spinner("Generating voice response..."):
|
791 |
+
audio_data = generate_voice_response(response)
|
792 |
|
793 |
# Add AI response to chat history
|
794 |
st.session_state.chat_history.append({
|
|
|
801 |
st.rerun()
|
802 |
|
803 |
st.markdown("</div>", unsafe_allow_html=True)
|
804 |
+
|
805 |
|
806 |
# Main function
|
807 |
def main():
|