Spaces:
Build error
Build error
Update components/chat.py
Browse files4 unmodified lines56789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354554 unmodified linesdef display_chat_interface():"""Display chat interface component"""st.markdown("### 💬 RFP Analysis Chat")# Initialize chat history if not existsif 'messages' not in st.session_state:st.session_state.messages = []# Display chat historyfor message in st.session_state.messages:if isinstance(message, HumanMessage):st.markdown(f"🧑💼 **You**: {message.content}")elif isinstance(message, AIMessage):st.markdown(f"🤖 **Assistant**: {message.content}")# Chat inputif prompt := st.chat_input("Ask about the RFPs..."):try:with st.spinner("Analyzing documents..."):# Create message objectshuman_message = HumanMessage(content=prompt)# Add to chat historyst.session_state.messages.append(human_message)# Get response from QA systemresponse = st.session_state.qa_system.invoke({"input": prompt,"chat_history": st.session_state.messages})if response:# Create AI messageai_message = AIMessage(content=str(response))# Add to chat historyst.session_state.messages.append(ai_message)# Force refresh to show new messagesst.rerun()else:st.error("No valid response received")except Exception as e:st.error(f"Error: {e}")st.error(f"Error type: {type(e)}")import tracebackst.error(traceback.format_exc())4 unmodified lines567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111124 unmodified linesdef display_chat_interface():"""Display modern chat interface with clean formatting."""# Add custom CSS for modern chat stylingst.markdown("""<style>/* Clean, modern chat container */.chat-container {max-width: 800px;margin: auto;}/* Message styling */.user-message {background-color: #f0f2f6;padding: 1rem;border-radius: 10px;margin: 1rem 0;}.assistant-message {background-color: #ffffff;border: 1px solid #e0e0e0;padding: 1.5rem;border-radius: 10px;margin: 1rem 0;}/* Section styling */.section-header {font-weight: bold;color: #0f52ba;margin-top: 1rem;}.source-info {background-color: #f8f9fa;padding: 0.5rem;border-left: 3px solid #0f52ba;margin-top: 1rem;font-size: 0.9rem;}/* Headers and content */.content-section {margin: 0.5rem 0;}/* Clean bullets */.clean-bullet {margin: 0.3rem 0;}</style>""", unsafe_allow_html=True)# Initialize chat historyif 'messages' not in st.session_state:st.session_state.messages = []# Display chat historyfor message in st.session_state.messages:if isinstance(message, HumanMessage):st.markdown(f"""<div class="user-message">🧑💼 <strong>You:</strong><br>{message.content}</div>""", unsafe_allow_html=True)elif isinstance(message, AIMessage):# Clean and structure the responseresponse_content = message.contentif hasattr(message, 'additional_kwargs'):response_content = response_content.replace('additional_kwargs={}', '').replace('response_metadata={}', '')st.markdown(f"""<div class="assistant-message">🤖 <strong>Assistant:</strong><br>{response_content}</div>""", unsafe_allow_html=True)# Chat input at the bottomif prompt := st.chat_input("Ask about your documents..."):try:with st.spinner("Analyzing..."):# Create message objectshuman_message = HumanMessage(content=prompt)st.session_state.messages.append(human_message)# Get responseresponse = st.session_state.qa_system.invoke({"input": prompt,"chat_history": st.session_state.messages})if response:ai_message = AIMessage(content=str(response))st.session_state.messages.append(ai_message)st.rerun()else:st.error("No valid response received")except Exception as e:st.error(f"Error: {e}")import tracebackst.error(traceback.format_exc())
components/chat.py+75-18