import streamlit as st from backend import generate_response # --- Page Config --- st.set_page_config(page_title="Accesssories Mobile Bot", layout="wide") # --- Custom CSS for ChatGPT-like look --- st.markdown( """ """, unsafe_allow_html=True ) # st.title("🤖 ChatGPT-style Mobile Accessories Bot") # --- Session State --- if "chat_history" not in st.session_state: st.session_state.chat_history = [] # --- Chat Display (on top) --- # st.markdown('
', unsafe_allow_html=True) # for role, msg in st.session_state.chat_history: # css_class = "user" if role == "user" else "bot" # st.markdown(f'
{msg}
', unsafe_allow_html=True) # st.markdown('
', unsafe_allow_html=True) # --- Chat Display (on top) --- 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: # Simple text reply content = msg["content"] if isinstance(msg, dict) else msg st.markdown(f'
{content}
', unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True) # --- Chat Input (below) --- 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") st.title("🤖 Mobile Accessory AI-BoT") 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() # Optional: Keeps scroll to bottom after each input