Spaces:
Sleeping
Sleeping
File size: 2,718 Bytes
ce79acb d4568b9 a582b21 d4568b9 a582b21 ce79acb d4568b9 ce79acb d4568b9 a582b21 d4568b9 a582b21 d4568b9 a582b21 d4568b9 a582b21 d4568b9 a582b21 d4568b9 b881633 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
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
|