""" Lead.AI Business Chatbot Demo — Live Demo AI customer service chatbot trained for small business use cases. Visit https://www.lead-ai.us for a custom deployment on your business data. """ import gradio as gr import json import re from datetime import datetime # ── Demo knowledge base (replace with real business data in production) ─────── DEMO_BUSINESS = { "name": "Lead.AI Demo Business", "type": "AI Automation Services", "hours": "Monday–Friday, 9am–6pm EST", "phone": "+1 (555) 000-0000", "email": "hello@lead-ai.us", "website": "https://www.lead-ai.us", "location": "Remote — serving businesses worldwide", } FAQ_DATABASE = { "hours": { "triggers": ["hours", "open", "close", "when", "schedule", "available", "time"], "response": f"We're open **{DEMO_BUSINESS['hours']}**. Outside those hours, leave a message and we'll reply the next business day." }, "pricing": { "triggers": ["price", "cost", "pricing", "how much", "fee", "charge", "rate", "pay", "package"], "response": """Here are our main service packages: 💰 **Starter — $499** (one-time) Website chatbot + lead capture + 30-day support 💰 **Business — $999** (one-time) Chatbot + WhatsApp + appointment booking + dashboard 💰 **Advanced AI — $1,999+** Predictive analytics + fraud detection + custom deployment 📅 **Monthly Support — $99–$499/month** Want a personalized quote? **[Book a free consultation →](https://www.lead-ai.us)**""" }, "services": { "triggers": ["service", "offer", "provide", "build", "create", "help", "do", "what"], "response": """We build AI automation systems for small businesses: 🤖 **Website AI Chatbot** — captures leads 24/7 📱 **WhatsApp Lead Assistant** — qualifies prospects automatically 📅 **AI Appointment Booking** — no more scheduling back-and-forth 🛡 **Fraud Detection Dashboard** — flags risky transactions with explanations 📊 **Customer Predictor** — identifies who's about to leave ⭐ **Review Sentinel** — monitors your reputation in real time Which one are you most interested in?""" }, "demo": { "triggers": ["demo", "try", "see", "example", "test", "sample", "show"], "response": """You can try our AI systems live right now — no signup needed: 🛡 [Fraud Shield Demo](https://huggingface.co/spaces/lead-ai-labs/fraud-shield) 🎯 [Customer Predictor Demo](https://huggingface.co/spaces/lead-ai-labs/customer-predictor) ⭐ [Review Sentinel Demo](https://huggingface.co/spaces/lead-ai-labs/review-sentinel) Or you're already talking to a chatbot demo! 👋""" }, "contact": { "triggers": ["contact", "reach", "call", "email", "talk", "speak", "human", "person", "agent"], "response": f"""Here's how to reach a real person: 📧 **Email:** {DEMO_BUSINESS['email']} 🌐 **Website:** {DEMO_BUSINESS['website']} 📞 **Phone:** {DEMO_BUSINESS['phone']} Or **[book a free 30-minute consultation](https://www.lead-ai.us)** — we'll call you.""" }, "consultation": { "triggers": ["book", "appointment", "consultation", "meeting", "call", "schedule", "chat"], "response": """I'd love to connect you with our team! **[📅 Book a Free 30-Minute AI Consultation](https://www.lead-ai.us)** During the call, we'll: ✓ Review your business needs ✓ Show you what AI can automate ✓ Give you a no-pressure recommendation and quote What type of business do you run?""" }, "setup_time": { "triggers": ["long", "fast", "quick", "days", "weeks", "timeline", "when", "ready", "live"], "response": """**Setup timelines:** 🚀 Basic chatbot: **48–72 hours** 📦 Business package: **5–7 business days** 🧠 Advanced AI systems: **10–14 business days** All systems include testing and a walkthrough before handoff. Want to get started? **[Book a consultation →](https://www.lead-ai.us)**""" }, "custom": { "triggers": ["custom", "specific", "my business", "tailored", "personalized", "train", "data"], "response": """Yes, every Lead.AI system is custom-built for your business: ✓ Trained on **your** FAQs, products, and policies ✓ Integrated with **your** existing tools ✓ Deployed on **your** website or platform ✓ Supported by Lead.AI on an ongoing basis We don't use generic bots. Every system learns your business. **[Request a Custom Setup →](https://www.lead-ai.us)**""" }, "refund": { "triggers": ["refund", "guarantee", "money back", "cancel", "return"], "response": """We stand behind our work: ✓ If a deliverable doesn't match what was agreed, we fix it — no charge ✓ Digital products: 7-day refund if the product doesn't open or run as documented ✓ Custom setups: milestone-based payment — you approve each stage before we continue Questions? Email **hello@lead-ai.us** — we respond within 24 hours.""" }, } LEAD_CAPTURE_STAGE = {} CONVERSATION_LOG = [] def capture_lead_info(message: str, stage: dict) -> tuple[str, dict]: if "name" not in stage: return "Great! What's your name?", {**stage, "name": None, "awaiting": "name"} if stage.get("awaiting") == "name": stage["name"] = message.strip().title() stage["awaiting"] = "email" return f"Nice to meet you, {stage['name']}! What's your email address?", stage if stage.get("awaiting") == "email": if "@" not in message: return "That doesn't look like an email. Could you try again?", stage stage["email"] = message.strip().lower() stage["awaiting"] = "business" return "Perfect! And what type of business do you run?", stage if stage.get("awaiting") == "business": stage["business"] = message.strip() stage["awaiting"] = "done" name = stage.get("name", "there") email = stage.get("email", "") biz = stage.get("business", "your business") return ( f"Thank you, {name}! We'll be in touch at **{email}** within 24 hours.\n\n" f"A Lead.AI specialist will reach out to discuss AI automation options for **{biz}**.\n\n" f"In the meantime, [book a free consultation](https://www.lead-ai.us) if you'd like to connect sooner. 🚀" ), stage return None, stage def get_faq_response(message: str) -> str | None: lower = message.lower() for faq_key, faq in FAQ_DATABASE.items(): if any(trigger in lower for trigger in faq["triggers"]): return faq["response"] return None def chatbot_response(message: str, history: list, lead_stage: dict): if not message.strip(): return history, lead_stage lower = message.lower() response = None # Lead capture flow if lead_stage.get("awaiting") in ("name", "email", "business"): response, lead_stage = capture_lead_info(message, lead_stage) # Greetings elif any(g in lower for g in ["hello", "hi", "hey", "good morning", "good afternoon"]): hour = datetime.now().hour greeting = "Good morning" if hour < 12 else ("Good afternoon" if hour < 17 else "Good evening") response = ( f"{greeting}! 👋 I'm the Lead.AI assistant.\n\n" "I can help you with:\n" "• **Our services and pricing**\n" "• **Live AI demos**\n" "• **Booking a consultation**\n" "• **Getting a quote for your business**\n\n" "What brings you here today?" ) # Lead capture trigger elif any(kw in lower for kw in ["interested", "get started", "sign up", "quote", "start"]): response, lead_stage = capture_lead_info(message, lead_stage) # FAQ match else: response = get_faq_response(message) # Fallback if not response: response = ( "That's a great question! Let me connect you with a specialist who can give you " "a proper answer.\n\n" "📧 **Email:** hello@lead-ai.us\n" "🌐 **Or book a free call:** [www.lead-ai.us](https://www.lead-ai.us)\n\n" "Is there anything else I can help you with — services, pricing, or demos?" ) history.append((message, response)) return history, lead_stage with gr.Blocks( title="Lead.AI Business Chatbot", theme=gr.themes.Soft(primary_hue="violet"), css=""" .chatbot-container { max-height: 500px; } .footer { text-align:center; margin-top:20px; color:#666; } """ ) as demo: gr.Markdown(""" # 💬 Lead.AI Business Chatbot Demo ### AI Customer Service That Captures Leads While You Sleep This is a live demo of the Lead.AI chatbot engine. In production, it's trained on **your** business: your FAQs, services, hours, and pricing. Try asking: *"What are your prices?"* or *"Can I see a demo?"* or *"I'm interested"* > 💼 This is a proof-of-concept demo. [Get this for your business →](https://www.lead-ai.us) """) chatbot = gr.Chatbot(height=400, label="Lead.AI Assistant", bubble_full_width=False) lead_state = gr.State({}) with gr.Row(): msg_box = gr.Textbox( placeholder="Type your question here... (e.g. 'What services do you offer?')", label="", scale=4, container=False, ) send_btn = gr.Button("Send →", variant="primary", scale=1) with gr.Row(): gr.Examples( examples=[ ["What services do you offer?"], ["How much does it cost?"], ["Can I see a live demo?"], ["How long does setup take?"], ["I'm interested in getting started"], ["How do I contact a real person?"], ], inputs=msg_box, label="Quick Questions", ) send_btn.click( fn=chatbot_response, inputs=[msg_box, chatbot, lead_state], outputs=[chatbot, lead_state], ).then(fn=lambda: "", outputs=msg_box) msg_box.submit( fn=chatbot_response, inputs=[msg_box, chatbot, lead_state], outputs=[chatbot, lead_state], ).then(fn=lambda: "", outputs=msg_box) gr.Markdown(""" --- """) if __name__ == "__main__": demo.launch()