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 """)