()
| 269 | st.markdown('<hr style="margin: 2rem 0;">', unsafe_allow_html=True) |
| 270 | |
| 271 | def chat_page(): |
| 272 | # Initialize session state |
| 273 | if "messages" not in st.session_state: |
| 274 | st.session_state.messages = [] |
| 275 | if "query" not in st.session_state: |
| 276 | st.session_state.query = "" |
| 277 | |
| 278 | st.markdown(""" |
| 279 | <div style="text-align: center; padding: 2rem 0;"> |
| 280 | <h1 style="color: #81E831; font-size: 3em; font-weight: 800;">🤵♂️ Fashion AI Assistant</h1> |
| 281 | <p style="color: #666; font-size: 1.2em;">Your personal style advisor powered by AI</p> |
| 282 | </div> |
| 283 | """, unsafe_allow_html=True) |
| 284 | |
| 285 | # Navigation buttons |
| 286 | st.markdown(""" |
| 287 | <div class="nav-container"> |
| 288 | <a href="add_product_page" class="nav-button">Add Product Data</a> |
| 289 | <a href="visual_search" class="nav-button">Visual Search</a> |
| 290 | </div> |
| 291 | """, unsafe_allow_html=True) |
| 292 | |
| 293 | # Show suggestions if no messages yet |
| 294 | if not st.session_state.messages: |
| 295 | render_suggestions() |
| 296 | |
| 297 | # Chat messages display |
| 298 | for message in st.session_state.messages: |
| 299 | with st.chat_message(message["role"], avatar="👤" if message["role"] == "user" else "👗"): |
| 300 | if message["role"] == "assistant": |
| 301 | st.markdown(message["content"]["response"]) |
| 302 | if message["content"].get("metadata") and message["content"]["metadata"].get("sources"): |
| 303 | render_results_section(message["content"]) |
| 304 | else: |
| 305 | st.markdown(message["content"]) |
| 306 | |
| 307 | # Handle query from suggestion buttons |
| 308 | if st.session_state.query: |
| 309 | query = st.session_state.query |
| 310 | st.session_state.query = "" # Clear the query |
| 311 | |
| 312 | # Add user message |
| 313 | st.session_state.messages.append({ |
| 314 | "role": "user", |
| 315 | "content": query |
| 316 | }) |
| 317 | |
| 318 | with st.chat_message("assistant", avatar="👗"): |
| 319 | with st.spinner("Finding perfect matches..."): |
| 320 | try: |
| 321 | response_data = get_rag_response(query) |
| 322 | st.markdown(response_data["response"]) |
| 323 | if response_data.get("metadata") and response_data["metadata"].get("sources"): |
| 324 | render_results_section(response_data) |
| 325 | except Exception as e: |
| 326 | st.error(f"An error occurred: {str(e)}") |
| 327 | response_data = { |
| 328 | "response": "I encountered an error while processing your request. Please try again.", |
no test coverage detected