Download app_working.py from VAH6002/CBMB: direct link, hf CLI and curl.
- Browser
- Download file 2.63 kB
-
https://huggingface.co/spaces/VAH6002/CBMB/resolve/main/app_working.py
- Command line
-
hf download hf://spaces/VAH6002/CBMB/app_working.py
-
curl -L -o app_working.py https://huggingface.co/spaces/VAH6002/CBMB/resolve/main/app_working.py
2.63 kB
| import streamlit as st | |
| from backend import generate_response | |
| # Streamlit Page Configuration | |
| st.set_page_config(page_title="Mobile Accessories Chat-Bot", layout="centered") | |
| st.markdown( | |
| """ | |
| <style> | |
| .stApp { | |
| background-color: #1a1a2e; | |
| color: #e0e0e0; | |
| } | |
| .stTextInput > div > div > input { | |
| background-color: #2e2e4a; | |
| color: #e0e0e0; | |
| border: 1px solid #4a4a6e; | |
| border-radius: 8px; | |
| padding: 10px; | |
| } | |
| .stButton > button { | |
| background-color: #0f3460; | |
| color: #e0e0e0; | |
| border-radius: 8px; | |
| padding: 10px 20px; | |
| border: none; | |
| cursor: pointer; | |
| } | |
| .stButton > button:hover { | |
| background-color: #16213e; | |
| } | |
| .stChatMessage { | |
| background-color: #2e2e4a; | |
| border-radius: 10px; | |
| padding: 15px; | |
| margin-bottom: 10px; | |
| } | |
| .stChatMessage.user { | |
| background-color: #0f3460; | |
| text-align: right; | |
| } | |
| .stChatMessage.assistant { | |
| background-color: #2e2e4a; | |
| text-align: left; | |
| } | |
| h1, h2, h3, h4, h5, h6 { | |
| color: #e0e0e0; | |
| } | |
| </style> | |
| """, | |
| unsafe_allow_html=True | |
| ) | |
| st.title("📱 Mobile Accessories Chat-Bot") | |
| # Initialize Chat History and session state variables | |
| if "chat_history" not in st.session_state: | |
| st.session_state.chat_history = [] | |
| if "user_input" not in st.session_state: | |
| st.session_state.user_input = "" | |
| if "should_clear_input" not in st.session_state: | |
| st.session_state.should_clear_input = False | |
| # Clear input if flag is set | |
| if st.session_state.should_clear_input: | |
| st.session_state.user_input = "" | |
| st.session_state.should_clear_input = False | |
| # Form for handling input submission | |
| with st.form(key="chat_form"): | |
| user_query = st.text_input( | |
| "Ask me anything about mobile accessories...", | |
| value=st.session_state.user_input, | |
| key="user_input" | |
| ) | |
| submit_button = st.form_submit_button("Send") | |
| if submit_button and user_query: | |
| # Generate Response | |
| bot_response = generate_response(user_query) | |
| # Store chat history | |
| st.session_state.chat_history.append(("You", user_query)) | |
| st.session_state.chat_history.append(("Chatbot", bot_response)) | |
| # Set flag to clear input and rerun | |
| st.session_state.should_clear_input = True | |
| st.rerun() | |
| # Display Chat History in Reverse Order | |
| st.subheader("Chat History") | |
| for role, message in reversed(st.session_state.chat_history): | |
| with st.chat_message(role): | |
| st.markdown(message) |