Spaces:
Sleeping
Sleeping
File size: 9,840 Bytes
da8a5d3 | 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | import streamlit as st
from datetime import datetime
# Enhanced bot function with more responses
def ask_bot(question):
"""
Enhanced chatbot function with more comprehensive responses
"""
question_lower = question.lower()
if "return" in question_lower and "policy" in question_lower:
return """
**π Return Policy**
- 30-day hassle-free return policy
- Items must be in original condition with tags attached
- Free return shipping for orders over $50
- Start your return process in your account dashboard
"""
elif "track" in question_lower and "order" in question_lower:
return """
**π¦ Order Tracking**
You can track your order in several ways:
- Check your email for the tracking link sent after purchase
- Log into your account and visit 'My Orders'
- Use our tracking page with your order number
- Contact support for real-time updates
"""
elif "laptop" in question_lower or "computer" in question_lower:
return """
**π» Latest Laptops**
We have amazing deals on:
- **Dell XPS Series** - Premium ultrabooks starting at $899
- **HP Pavilion** - Great for students, from $649
- **MacBook Air M2** - Latest Apple technology, $1,199
- **Gaming Laptops** - ASUS ROG and MSI starting at $999
All laptops come with free shipping and setup support!
"""
elif "warranty" in question_lower:
return """
**π‘οΈ Warranty Information**
- **Standard**: 1-year manufacturer warranty on all products
- **Extended**: 2-3 year extended warranties available
- **Premium Care**: Includes accidental damage protection
- **On-site Support**: Available for electronics over $500
Warranty registration is automatic with purchase!
"""
elif "shipping" in question_lower or "delivery" in question_lower:
return """
**π Shipping & Delivery**
- **Free Standard Shipping** on orders over $35 (3-5 business days)
- **Express Delivery** $9.99 (1-2 business days)
- **Same Day** available in major cities for $19.99
- **International Shipping** to 50+ countries
All orders ship within 24 hours on business days!
"""
elif "payment" in question_lower or "pay" in question_lower:
return """
**π³ Payment Options**
We accept all major payment methods:
- Credit/Debit Cards (Visa, MasterCard, American Express)
- PayPal and PayPal Pay in 4
- Apple Pay and Google Pay
- Buy Now, Pay Later with Klarna
- Gift cards and store credit
All transactions are secured with 256-bit SSL encryption.
"""
elif "contact" in question_lower or "support" in question_lower:
return """
**π Contact Support**
Our customer service team is here to help!
- **Live Chat**: Available 24/7 on our website
- **Phone**: 1-800-SHOP-NOW (Mon-Fri 9AM-8PM EST)
- **Email**: support@ecommerce.com
- **Social Media**: @EcommerceStore on Twitter/Facebook
Average response time: Live Chat <2 minutes, Email <4 hours
"""
elif "price" in question_lower or "discount" in question_lower or "deal" in question_lower:
return """
**π·οΈ Current Deals**
Amazing offers available now!
- **Weekly Deals**: Up to 40% off selected items
- **Student Discount**: 10% off with valid student ID
- **Newsletter Signup**: Get 15% off your first order
- **Bulk Orders**: Special pricing for quantities over 10
Check our deals page for flash sales and limited-time offers!
"""
elif "hello" in question_lower or "hi" in question_lower or "hey" in question_lower:
return """
**π Hello there!**
Welcome to our E-commerce AI Assistant! I'm here to help you with:
- Product information and recommendations
- Order tracking and returns
- Shipping and payment questions
- Technical support
How can I assist you today?
"""
else:
return f"""
**π€ I'd love to help you!**
While I don't have specific information about '{question}' right now, I can definitely assist you with:
- **Product Info** - Laptops, electronics, and more
- **Orders** - Tracking, returns, and shipping
- **Support** - Payments, warranties, and general help
Try asking about any of these topics, or contact our live support for specialized assistance!
"""
# Page configuration
st.set_page_config(
page_title="ShopSmart AI Assistant",
page_icon="ποΈ",
layout="wide",
initial_sidebar_state="expanded"
)
# Initialize session state
if "conversation" not in st.session_state:
st.session_state.conversation = []
if "message_count" not in st.session_state:
st.session_state.message_count = 0
# Header
st.title("ποΈ ShopSmart AI Assistant")
st.subheader("Your intelligent shopping companion - Ask me anything!")
# Sidebar
with st.sidebar:
st.header("π Quick Questions")
st.divider()
recommended_questions = [
"What is the return policy?",
"How can I track my order?",
"Show me latest laptops",
"What are shipping options?",
"Any current deals or discounts?"
]
for i, question in enumerate(recommended_questions):
if st.button(f"π¬ {question}", key=f"quick_q_{i}", use_container_width=True):
response = ask_bot(question)
st.session_state.conversation.append({
"user": question,
"bot": response,
"timestamp": datetime.now().strftime("%H:%M")
})
st.session_state.message_count += 1
st.rerun()
st.divider()
# Stats section
st.header("π Chat Statistics")
col1, col2 = st.columns(2)
with col1:
st.metric("Messages Sent", st.session_state.message_count)
with col2:
st.metric("Conversations", len(st.session_state.conversation))
st.divider()
if st.button("ποΈ Clear Chat History", type="secondary", use_container_width=True):
st.session_state.conversation = []
st.session_state.message_count = 0
st.success("Chat history cleared!")
st.rerun()
# Main chat area
st.header("π¬ Chat")
# Display conversation or welcome message
if not st.session_state.conversation:
st.info("""
ποΈ **ShopSmart Assistant** - Your 24/7 shopping companion
Ready to help with orders, products, returns, and more!
β‘ **Quick Start:** Use sidebar buttons or ask directly below
""")
else:
# Create a container for chat messages
chat_container = st.container()
with chat_container:
for i, turn in enumerate(st.session_state.conversation):
# Display messages with proper formatting
with st.expander(f"π¬ Conversation #{i+1} - {turn.get('timestamp', '')}", expanded=True):
# User message
st.write(f"**You:** {turn['user']}")
# Bot response
st.success(turn['bot'])
st.divider()
# Input form
st.subheader("βοΈ Ask a Question")
with st.form(key="chat_form", clear_on_submit=True):
# Create columns for input and button
col1, col2 = st.columns([4, 1])
with col1:
user_input = st.text_input(
"Type your message here:",
placeholder="Ask about products, orders, returns, or anything else!",
label_visibility="collapsed"
)
with col2:
st.write("") # Add some spacing
send_button = st.form_submit_button(
"Send π€",
type="primary",
use_container_width=True
)
# Process user input
if send_button and user_input.strip():
# Get bot response
bot_response = ask_bot(user_input)
# Add to conversation
st.session_state.conversation.append({
"user": user_input,
"bot": bot_response,
"timestamp": datetime.now().strftime("%H:%M")
})
st.session_state.message_count += 1
# Show success message
st.success(f"Message sent: '{user_input}'")
# Rerun to update the display
st.rerun()
# Footer information
st.divider()
# Create columns for footer info
footer_col1, footer_col2, footer_col3 = st.columns(3)
with footer_col1:
st.info("""
**π Available 24/7**
Our AI assistant is always ready to help you with your shopping needs.
""")
with footer_col2:
st.info("""
**π Need Human Support?**
Contact us at support@shopmart.com or call 1-800-SHOP-NOW
""")
with footer_col3:
st.info("""
**π Secure & Private**
Your conversations are secure and we respect your privacy.
""")
# Additional help section
with st.expander("β Need Help Using This Assistant?"):
st.write("""
**How to use the ShopSmart AI Assistant:**
1. **Quick Questions**: Click any button in the sidebar for instant answers
2. **Custom Questions**: Type your own question in the input field below
3. **View History**: All conversations are saved and displayed above
4. **Clear History**: Use the sidebar button to clear all conversations
**What I can help with:**
- Product information and recommendations
- Order tracking and status updates
- Return and exchange policies
- Shipping and delivery options
- Payment methods and security
- Warranty and support information
- Current deals and promotions
**Tips for better responses:**
- Be specific in your questions
- Include relevant details (product names, order numbers, etc.)
- Ask one question at a time for clearer answers
""") |