Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from datetime import datetime | |
| from chatbot_backend import ask_bot | |
| # --- Page Configuration --- | |
| st.set_page_config( | |
| page_title="AI Customer Service Bot", | |
| page_icon="π€", | |
| layout="wide" | |
| ) | |
| # --- Initialize Session State --- | |
| if "messages" not in st.session_state: | |
| st.session_state.messages = [{ | |
| "role": "assistant", | |
| "content": "π Welcome! I'm your AI Customer Service Assistant. Ask me anything! π¬", | |
| "timestamp": datetime.now().strftime("%H:%M") | |
| }] | |
| if "input_counter" not in st.session_state: | |
| st.session_state.input_counter = 0 | |
| # --- Sidebar --- | |
| with st.sidebar: | |
| st.title("Controls") | |
| if st.button("ποΈ Clear Chat"): | |
| st.session_state.messages = [{ | |
| "role": "assistant", | |
| "content": "π Welcome! I'm your AI Customer Service Assistant. Ask me anything! π¬", | |
| "timestamp": datetime.now().strftime("%H:%M") | |
| }] | |
| st.session_state.input_counter = 0 | |
| st.markdown("---") | |
| st.subheader("Quick Questions") | |
| quick_questions = [ | |
| "What services do you provide?", | |
| "What are your pricing packages?", | |
| "What are your business hours?", | |
| "How can I contact support?", | |
| "What is your refund policy?" | |
| ] | |
| for question in quick_questions: | |
| if st.button(question): | |
| st.session_state.messages.append({ | |
| "role": "user", | |
| "content": question, | |
| "timestamp": datetime.now().strftime("%H:%M") | |
| }) | |
| response = ask_bot(question) | |
| st.session_state.messages.append({ | |
| "role": "assistant", | |
| "content": response, | |
| "timestamp": datetime.now().strftime("%H:%M") | |
| }) | |
| # --- Chat Display --- | |
| st.title("π€ AI Customer Service") | |
| for message in st.session_state.messages: | |
| if message["role"] == "user": | |
| st.info(f"**You:** {message['content']}\n*{message['timestamp']}*") | |
| else: | |
| st.success(f"**AI:** {message['content']}\n*{message['timestamp']}*") | |
| # --- Input --- | |
| user_input = st.text_input("Type your question here...", key=f"user_input_{st.session_state.input_counter}") | |
| send = st.button("Send") | |
| if send and user_input.strip(): | |
| st.session_state.messages.append({ | |
| "role": "user", | |
| "content": user_input.strip(), | |
| "timestamp": datetime.now().strftime("%H:%M") | |
| }) | |
| with st.spinner("AI is thinking..."): | |
| response = ask_bot(user_input.strip()) | |
| st.session_state.messages.append({ | |
| "role": "assistant", | |
| "content": response, | |
| "timestamp": datetime.now().strftime("%H:%M") | |
| }) | |
| st.session_state.input_counter += 1 | |