arun-gharami's picture
Upload app.py with huggingface_hub
d245a81 verified
Raw
History Blame Contribute Delete
10.8 kB
"""
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("""
---
<div class="footer">
🌐 <a href="https://www.lead-ai.us">www.lead-ai.us</a> &nbsp;|&nbsp;
πŸ’» <a href="https://github.com/Lead-AI-US/lead-ai-chatbot-platform">GitHub</a> &nbsp;|&nbsp;
πŸ€— <a href="https://huggingface.co/lead-ai-labs">Hugging Face</a>
<br><br>
<strong>Need this chatbot trained on your business?</strong>
<a href="https://www.lead-ai.us">Request a Custom Lead.AI Setup β†’</a>
</div>
""")
if __name__ == "__main__":
demo.launch()