Download app.py from VAH6002/CBMB: direct link, hf CLI and curl.
- Browser
- Download file 4.28 kB
-
https://huggingface.co/spaces/VAH6002/CBMB/resolve/main/app.py
- Command line
-
hf download hf://spaces/VAH6002/CBMB/app.py
-
curl -L -o app.py https://huggingface.co/spaces/VAH6002/CBMB/resolve/main/app.py
4.28 kB
| 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( | |
| """ | |
| <style> | |
| .stApp { | |
| background-color: #343541; | |
| color: #e0e0e0; | |
| } | |
| .stTextInput input { | |
| background-color: #40414f; | |
| color: #fff; | |
| border-radius: 8px; | |
| padding: 12px; | |
| border: none; | |
| font-size: 16px; | |
| } | |
| .stButton>button { | |
| background-color: #19c37d; | |
| color: white; | |
| border-radius: 8px; | |
| padding: 10px 20px; | |
| border: none; | |
| font-weight: bold; | |
| margin-top: 10px; | |
| } | |
| .stButton>button:hover { | |
| background-color: #15a96e; | |
| } | |
| .chat-container { | |
| max-height: 75vh; | |
| overflow-y: auto; | |
| padding: 1rem; | |
| } | |
| .message { | |
| padding: 15px; | |
| border-radius: 12px; | |
| margin-bottom: 12px; | |
| line-height: 1.5; | |
| width: fit-content; | |
| max-width: 80%; | |
| } | |
| .user { | |
| background-color: #0e639c; | |
| align-self: flex-end; | |
| margin-left: auto; | |
| text-align: right; | |
| color: white; | |
| } | |
| .bot { | |
| background-color: #444654; | |
| align-self: flex-start; | |
| margin-right: auto; | |
| text-align: left; | |
| color: white; | |
| } | |
| .chat-wrapper { | |
| display: flex; | |
| flex-direction: column; | |
| } | |
| </style> | |
| """, | |
| 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('<div class="chat-container"><div class="chat-wrapper">', unsafe_allow_html=True) | |
| # for role, msg in st.session_state.chat_history: | |
| # css_class = "user" if role == "user" else "bot" | |
| # st.markdown(f'<div class="message {css_class}">{msg}</div>', unsafe_allow_html=True) | |
| # st.markdown('</div></div>', unsafe_allow_html=True) | |
| # --- Chat Display (on top) --- | |
| st.markdown('<div class="chat-container"><div class="chat-wrapper">', 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'<div class="message {css_class}">{msg}</div>', unsafe_allow_html=True) | |
| elif isinstance(msg, dict) and msg.get("type") == "products": | |
| st.markdown(f'<div class="message {css_class}"><div style="display: flex; overflow-x: auto; gap: 16px;">', unsafe_allow_html=True) | |
| for product in msg["items"]: | |
| st.markdown(f''' | |
| <div style="flex: 0 0 auto; width: 200px; background-color: #202123; padding: 12px; border-radius: 10px; text-align: center;"> | |
| <img src="{product['image_url']}" width="100%" style="border-radius: 8px;" /> | |
| <h4 style="color: #fff; margin-top: 10px;">{product['name']}</h4> | |
| <p style="color: #19c37d; font-weight: bold;">{product['price']}</p> | |
| <a href="{product['buy_link']}" target="_blank"> | |
| <button style="margin-top: 8px; background-color: #19c37d; color: white; border: none; padding: 6px 12px; border-radius: 5px;">Buy Now</button> | |
| </a> | |
| </div> | |
| ''', unsafe_allow_html=True) | |
| st.markdown('</div></div>', unsafe_allow_html=True) | |
| else: | |
| # Simple text reply | |
| content = msg["content"] if isinstance(msg, dict) else msg | |
| st.markdown(f'<div class="message {css_class}">{content}</div>', unsafe_allow_html=True) | |
| st.markdown('</div></div>', 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 | |