arun-gharami commited on
Commit
d245a81
Β·
verified Β·
1 Parent(s): ff1e28a

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +283 -0
app.py ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Lead.AI Business Chatbot Demo β€” Live Demo
3
+ AI customer service chatbot trained for small business use cases.
4
+ Visit https://www.lead-ai.us for a custom deployment on your business data.
5
+ """
6
+
7
+ import gradio as gr
8
+ import json
9
+ import re
10
+ from datetime import datetime
11
+
12
+ # ── Demo knowledge base (replace with real business data in production) ───────
13
+ DEMO_BUSINESS = {
14
+ "name": "Lead.AI Demo Business",
15
+ "type": "AI Automation Services",
16
+ "hours": "Monday–Friday, 9am–6pm EST",
17
+ "phone": "+1 (555) 000-0000",
18
+ "email": "hello@lead-ai.us",
19
+ "website": "https://www.lead-ai.us",
20
+ "location": "Remote β€” serving businesses worldwide",
21
+ }
22
+
23
+ FAQ_DATABASE = {
24
+ "hours": {
25
+ "triggers": ["hours", "open", "close", "when", "schedule", "available", "time"],
26
+ "response": f"We're open **{DEMO_BUSINESS['hours']}**. Outside those hours, leave a message and we'll reply the next business day."
27
+ },
28
+ "pricing": {
29
+ "triggers": ["price", "cost", "pricing", "how much", "fee", "charge", "rate", "pay", "package"],
30
+ "response": """Here are our main service packages:
31
+
32
+ πŸ’° **Starter β€” $499** (one-time)
33
+ Website chatbot + lead capture + 30-day support
34
+
35
+ πŸ’° **Business β€” $999** (one-time)
36
+ Chatbot + WhatsApp + appointment booking + dashboard
37
+
38
+ πŸ’° **Advanced AI β€” $1,999+**
39
+ Predictive analytics + fraud detection + custom deployment
40
+
41
+ πŸ“… **Monthly Support β€” $99–$499/month**
42
+
43
+ Want a personalized quote? **[Book a free consultation β†’](https://www.lead-ai.us)**"""
44
+ },
45
+ "services": {
46
+ "triggers": ["service", "offer", "provide", "build", "create", "help", "do", "what"],
47
+ "response": """We build AI automation systems for small businesses:
48
+
49
+ πŸ€– **Website AI Chatbot** β€” captures leads 24/7
50
+ πŸ“± **WhatsApp Lead Assistant** β€” qualifies prospects automatically
51
+ πŸ“… **AI Appointment Booking** β€” no more scheduling back-and-forth
52
+ πŸ›‘ **Fraud Detection Dashboard** β€” flags risky transactions with explanations
53
+ πŸ“Š **Customer Predictor** β€” identifies who's about to leave
54
+ ⭐ **Review Sentinel** β€” monitors your reputation in real time
55
+
56
+ Which one are you most interested in?"""
57
+ },
58
+ "demo": {
59
+ "triggers": ["demo", "try", "see", "example", "test", "sample", "show"],
60
+ "response": """You can try our AI systems live right now β€” no signup needed:
61
+
62
+ πŸ›‘ [Fraud Shield Demo](https://huggingface.co/spaces/lead-ai-labs/fraud-shield)
63
+ 🎯 [Customer Predictor Demo](https://huggingface.co/spaces/lead-ai-labs/customer-predictor)
64
+ ⭐ [Review Sentinel Demo](https://huggingface.co/spaces/lead-ai-labs/review-sentinel)
65
+
66
+ Or you're already talking to a chatbot demo! πŸ‘‹"""
67
+ },
68
+ "contact": {
69
+ "triggers": ["contact", "reach", "call", "email", "talk", "speak", "human", "person", "agent"],
70
+ "response": f"""Here's how to reach a real person:
71
+
72
+ πŸ“§ **Email:** {DEMO_BUSINESS['email']}
73
+ 🌐 **Website:** {DEMO_BUSINESS['website']}
74
+ πŸ“ž **Phone:** {DEMO_BUSINESS['phone']}
75
+
76
+ Or **[book a free 30-minute consultation](https://www.lead-ai.us)** β€” we'll call you."""
77
+ },
78
+ "consultation": {
79
+ "triggers": ["book", "appointment", "consultation", "meeting", "call", "schedule", "chat"],
80
+ "response": """I'd love to connect you with our team!
81
+
82
+ **[πŸ“… Book a Free 30-Minute AI Consultation](https://www.lead-ai.us)**
83
+
84
+ During the call, we'll:
85
+ βœ“ Review your business needs
86
+ βœ“ Show you what AI can automate
87
+ βœ“ Give you a no-pressure recommendation and quote
88
+
89
+ What type of business do you run?"""
90
+ },
91
+ "setup_time": {
92
+ "triggers": ["long", "fast", "quick", "days", "weeks", "timeline", "when", "ready", "live"],
93
+ "response": """**Setup timelines:**
94
+
95
+ πŸš€ Basic chatbot: **48–72 hours**
96
+ πŸ“¦ Business package: **5–7 business days**
97
+ 🧠 Advanced AI systems: **10–14 business days**
98
+
99
+ All systems include testing and a walkthrough before handoff.
100
+
101
+ Want to get started? **[Book a consultation β†’](https://www.lead-ai.us)**"""
102
+ },
103
+ "custom": {
104
+ "triggers": ["custom", "specific", "my business", "tailored", "personalized", "train", "data"],
105
+ "response": """Yes, every Lead.AI system is custom-built for your business:
106
+
107
+ βœ“ Trained on **your** FAQs, products, and policies
108
+ βœ“ Integrated with **your** existing tools
109
+ βœ“ Deployed on **your** website or platform
110
+ βœ“ Supported by Lead.AI on an ongoing basis
111
+
112
+ We don't use generic bots. Every system learns your business.
113
+
114
+ **[Request a Custom Setup β†’](https://www.lead-ai.us)**"""
115
+ },
116
+ "refund": {
117
+ "triggers": ["refund", "guarantee", "money back", "cancel", "return"],
118
+ "response": """We stand behind our work:
119
+
120
+ βœ“ If a deliverable doesn't match what was agreed, we fix it β€” no charge
121
+ βœ“ Digital products: 7-day refund if the product doesn't open or run as documented
122
+ βœ“ Custom setups: milestone-based payment β€” you approve each stage before we continue
123
+
124
+ Questions? Email **hello@lead-ai.us** β€” we respond within 24 hours."""
125
+ },
126
+ }
127
+
128
+ LEAD_CAPTURE_STAGE = {}
129
+ CONVERSATION_LOG = []
130
+
131
+ def capture_lead_info(message: str, stage: dict) -> tuple[str, dict]:
132
+ if "name" not in stage:
133
+ return "Great! What's your name?", {**stage, "name": None, "awaiting": "name"}
134
+ if stage.get("awaiting") == "name":
135
+ stage["name"] = message.strip().title()
136
+ stage["awaiting"] = "email"
137
+ return f"Nice to meet you, {stage['name']}! What's your email address?", stage
138
+ if stage.get("awaiting") == "email":
139
+ if "@" not in message:
140
+ return "That doesn't look like an email. Could you try again?", stage
141
+ stage["email"] = message.strip().lower()
142
+ stage["awaiting"] = "business"
143
+ return "Perfect! And what type of business do you run?", stage
144
+ if stage.get("awaiting") == "business":
145
+ stage["business"] = message.strip()
146
+ stage["awaiting"] = "done"
147
+ name = stage.get("name", "there")
148
+ email = stage.get("email", "")
149
+ biz = stage.get("business", "your business")
150
+ return (
151
+ f"Thank you, {name}! We'll be in touch at **{email}** within 24 hours.\n\n"
152
+ f"A Lead.AI specialist will reach out to discuss AI automation options for **{biz}**.\n\n"
153
+ f"In the meantime, [book a free consultation](https://www.lead-ai.us) if you'd like to connect sooner. πŸš€"
154
+ ), stage
155
+ return None, stage
156
+
157
+ def get_faq_response(message: str) -> str | None:
158
+ lower = message.lower()
159
+ for faq_key, faq in FAQ_DATABASE.items():
160
+ if any(trigger in lower for trigger in faq["triggers"]):
161
+ return faq["response"]
162
+ return None
163
+
164
+ def chatbot_response(message: str, history: list, lead_stage: dict):
165
+ if not message.strip():
166
+ return history, lead_stage
167
+
168
+ lower = message.lower()
169
+ response = None
170
+
171
+ # Lead capture flow
172
+ if lead_stage.get("awaiting") in ("name", "email", "business"):
173
+ response, lead_stage = capture_lead_info(message, lead_stage)
174
+
175
+ # Greetings
176
+ elif any(g in lower for g in ["hello", "hi", "hey", "good morning", "good afternoon"]):
177
+ hour = datetime.now().hour
178
+ greeting = "Good morning" if hour < 12 else ("Good afternoon" if hour < 17 else "Good evening")
179
+ response = (
180
+ f"{greeting}! πŸ‘‹ I'm the Lead.AI assistant.\n\n"
181
+ "I can help you with:\n"
182
+ "β€’ **Our services and pricing**\n"
183
+ "β€’ **Live AI demos**\n"
184
+ "β€’ **Booking a consultation**\n"
185
+ "β€’ **Getting a quote for your business**\n\n"
186
+ "What brings you here today?"
187
+ )
188
+
189
+ # Lead capture trigger
190
+ elif any(kw in lower for kw in ["interested", "get started", "sign up", "quote", "start"]):
191
+ response, lead_stage = capture_lead_info(message, lead_stage)
192
+
193
+ # FAQ match
194
+ else:
195
+ response = get_faq_response(message)
196
+
197
+ # Fallback
198
+ if not response:
199
+ response = (
200
+ "That's a great question! Let me connect you with a specialist who can give you "
201
+ "a proper answer.\n\n"
202
+ "πŸ“§ **Email:** hello@lead-ai.us\n"
203
+ "🌐 **Or book a free call:** [www.lead-ai.us](https://www.lead-ai.us)\n\n"
204
+ "Is there anything else I can help you with β€” services, pricing, or demos?"
205
+ )
206
+
207
+ history.append((message, response))
208
+ return history, lead_stage
209
+
210
+
211
+ with gr.Blocks(
212
+ title="Lead.AI Business Chatbot",
213
+ theme=gr.themes.Soft(primary_hue="violet"),
214
+ css="""
215
+ .chatbot-container { max-height: 500px; }
216
+ .footer { text-align:center; margin-top:20px; color:#666; }
217
+ """
218
+ ) as demo:
219
+
220
+ gr.Markdown("""
221
+ # πŸ’¬ Lead.AI Business Chatbot Demo
222
+ ### AI Customer Service That Captures Leads While You Sleep
223
+
224
+ This is a live demo of the Lead.AI chatbot engine.
225
+ In production, it's trained on **your** business: your FAQs, services, hours, and pricing.
226
+
227
+ Try asking: *"What are your prices?"* or *"Can I see a demo?"* or *"I'm interested"*
228
+
229
+ > πŸ’Ό This is a proof-of-concept demo. [Get this for your business β†’](https://www.lead-ai.us)
230
+ """)
231
+
232
+ chatbot = gr.Chatbot(height=400, label="Lead.AI Assistant", bubble_full_width=False)
233
+ lead_state = gr.State({})
234
+
235
+ with gr.Row():
236
+ msg_box = gr.Textbox(
237
+ placeholder="Type your question here... (e.g. 'What services do you offer?')",
238
+ label="",
239
+ scale=4,
240
+ container=False,
241
+ )
242
+ send_btn = gr.Button("Send β†’", variant="primary", scale=1)
243
+
244
+ with gr.Row():
245
+ gr.Examples(
246
+ examples=[
247
+ ["What services do you offer?"],
248
+ ["How much does it cost?"],
249
+ ["Can I see a live demo?"],
250
+ ["How long does setup take?"],
251
+ ["I'm interested in getting started"],
252
+ ["How do I contact a real person?"],
253
+ ],
254
+ inputs=msg_box,
255
+ label="Quick Questions",
256
+ )
257
+
258
+ send_btn.click(
259
+ fn=chatbot_response,
260
+ inputs=[msg_box, chatbot, lead_state],
261
+ outputs=[chatbot, lead_state],
262
+ ).then(fn=lambda: "", outputs=msg_box)
263
+
264
+ msg_box.submit(
265
+ fn=chatbot_response,
266
+ inputs=[msg_box, chatbot, lead_state],
267
+ outputs=[chatbot, lead_state],
268
+ ).then(fn=lambda: "", outputs=msg_box)
269
+
270
+ gr.Markdown("""
271
+ ---
272
+ <div class="footer">
273
+ 🌐 <a href="https://www.lead-ai.us">www.lead-ai.us</a> &nbsp;|&nbsp;
274
+ πŸ’» <a href="https://github.com/Lead-AI-US/lead-ai-chatbot-platform">GitHub</a> &nbsp;|&nbsp;
275
+ πŸ€— <a href="https://huggingface.co/lead-ai-labs">Hugging Face</a>
276
+ <br><br>
277
+ <strong>Need this chatbot trained on your business?</strong>
278
+ <a href="https://www.lead-ai.us">Request a Custom Lead.AI Setup β†’</a>
279
+ </div>
280
+ """)
281
+
282
+ if __name__ == "__main__":
283
+ demo.launch()