import streamlit as st from backend import generate_response st.set_page_config(page_title="Accessory Recommender Bot", layout="wide") st.markdown(""" """, unsafe_allow_html=True) if "chat_history" not in st.session_state: st.session_state.chat_history = [] # Chat history display st.markdown('
', unsafe_allow_html=True) for role, msg in st.session_state.chat_history: css_class = "user" if role == "user" else "bot" if role == "user": st.markdown(f'
{msg}
', unsafe_allow_html=True) elif isinstance(msg, dict) and msg.get("type") == "products": st.markdown(f'
', unsafe_allow_html=True) for product in msg["items"]: st.markdown(f'''

{product['name']}

{product['price']}

''', unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True) else: content = msg["content"] if isinstance(msg, dict) else msg st.markdown(f'
{content}
', unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True) # Chat form with st.form("chat_form", clear_on_submit=True): user_input = st.text_input("🧠 Your mobile accessories AI expert is ready. Ask anything!", key="input") send = st.form_submit_button("Send") if send and user_input: response = generate_response(user_input) st.session_state.chat_history.append(("user", user_input)) st.session_state.chat_history.append(("bot", response)) st.rerun()