Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import gradio as gr
|
2 |
-
import random
|
3 |
import time
|
4 |
|
5 |
# Business information - customize this for your business
|
@@ -34,7 +33,7 @@ def get_business_response(intent):
|
|
34 |
"contact": f"You can reach us at {BUSINESS_INFO['phone']} or email {BUSINESS_INFO['email']}.",
|
35 |
"products": f"We offer a wide range of {BUSINESS_INFO['products']}. What specifically are you interested in?",
|
36 |
"returns": f"Our return policy: {BUSINESS_INFO['return_policy']}.",
|
37 |
-
"shipping": f"
|
38 |
"greeting": "Hello! Welcome to TechGadget Store. How can I help you today?",
|
39 |
"thanks": "You're welcome! Is there anything else I can help you with?",
|
40 |
"goodbye": "Thank you for contacting TechGadget Store. Have a great day!",
|
@@ -66,46 +65,46 @@ def chat_with_bot(message, chat_history):
|
|
66 |
user_message = message.lower()
|
67 |
bot_response = ""
|
68 |
|
69 |
-
# Check for greetings
|
70 |
-
if any(word in user_message for word in ["
|
71 |
-
bot_response = get_business_response("
|
72 |
-
|
73 |
-
# Check for thanks
|
74 |
-
elif any(word in user_message for word in ["thank", "appreciate", "thanks"]):
|
75 |
-
bot_response = get_business_response("thanks")
|
76 |
-
|
77 |
-
# Check for goodbye
|
78 |
-
elif any(word in user_message for word in ["bye", "goodbye", "see you"]):
|
79 |
-
bot_response = get_business_response("goodbye")
|
80 |
|
81 |
-
# Check for
|
82 |
-
elif any(word in user_message for word in ["
|
83 |
-
bot_response = get_business_response("
|
84 |
|
85 |
-
# Check for
|
86 |
-
elif any(word in user_message for word in ["
|
87 |
-
bot_response = get_business_response("
|
88 |
|
89 |
# Check for contact info
|
90 |
elif any(word in user_message for word in ["contact", "phone", "call", "email"]):
|
91 |
bot_response = get_business_response("contact")
|
92 |
|
93 |
-
# Check for
|
94 |
-
elif any(word in user_message for word in ["
|
95 |
-
bot_response = get_business_response("
|
96 |
-
|
97 |
-
# Check for returns
|
98 |
-
elif any(word in user_message for word in ["return", "exchange", "refund"]):
|
99 |
-
bot_response = get_business_response("returns")
|
100 |
|
101 |
-
# Check for
|
102 |
-
elif any(word in user_message for word in ["
|
103 |
-
bot_response = get_business_response("
|
104 |
|
105 |
# Check for help or capabilities
|
106 |
elif any(word in user_message for word in ["help", "what can you do", "how can you help", "capabilities", "what do you know"]):
|
107 |
bot_response = get_business_response("capabilities")
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
# Handle product inquiries
|
110 |
elif any(word in user_message for word in ["smartphone", "phone"]):
|
111 |
if "pro" in user_message or "premium" in user_message:
|
@@ -128,7 +127,7 @@ def chat_with_bot(message, chat_history):
|
|
128 |
bot_response = "I'm here to help with information about our products, store hours, location, and policies. How can I assist you today?"
|
129 |
|
130 |
# Add a small delay to make it feel more natural
|
131 |
-
time.sleep(0.
|
132 |
|
133 |
# Append to chat history using the new Messages format
|
134 |
chat_history.append({"role": "user", "content": message})
|
@@ -171,17 +170,6 @@ h1 {
|
|
171 |
margin: auto;
|
172 |
padding: 20px;
|
173 |
}
|
174 |
-
.example-btn {
|
175 |
-
margin: 5px;
|
176 |
-
padding: 8px 12px;
|
177 |
-
border-radius: 5px;
|
178 |
-
background-color: #f0f0f0;
|
179 |
-
border: 1px solid #ddd;
|
180 |
-
cursor: pointer;
|
181 |
-
}
|
182 |
-
.example-btn:hover {
|
183 |
-
background-color: #e0e0e0;
|
184 |
-
}
|
185 |
"""
|
186 |
|
187 |
# Create the Gradio interface
|
@@ -215,11 +203,11 @@ with gr.Blocks(css=custom_css, title="TechGadget Store Support") as demo:
|
|
215 |
# Create example buttons with correct parameters
|
216 |
examples = gr.Examples(
|
217 |
examples=[
|
|
|
218 |
["What are your store hours?"],
|
219 |
["Where are you located?"],
|
220 |
["What smartphones do you sell?"],
|
221 |
["What is your return policy?"],
|
222 |
-
["Do you offer free shipping?"],
|
223 |
["What can you help with?"],
|
224 |
["Tell me about your laptops"]
|
225 |
],
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import time
|
3 |
|
4 |
# Business information - customize this for your business
|
|
|
33 |
"contact": f"You can reach us at {BUSINESS_INFO['phone']} or email {BUSINESS_INFO['email']}.",
|
34 |
"products": f"We offer a wide range of {BUSINESS_INFO['products']}. What specifically are you interested in?",
|
35 |
"returns": f"Our return policy: {BUSINESS_INFO['return_policy']}.",
|
36 |
+
"shipping": f"Yes! We offer {BUSINESS_INFO['shipping'].lower()}",
|
37 |
"greeting": "Hello! Welcome to TechGadget Store. How can I help you today?",
|
38 |
"thanks": "You're welcome! Is there anything else I can help you with?",
|
39 |
"goodbye": "Thank you for contacting TechGadget Store. Have a great day!",
|
|
|
65 |
user_message = message.lower()
|
66 |
bot_response = ""
|
67 |
|
68 |
+
# Check for shipping first (before greetings to avoid "hi" in "shipping" triggering greeting)
|
69 |
+
if any(word in user_message for word in ["ship", "delivery", "deliver", "shipping", "free shipping"]):
|
70 |
+
bot_response = get_business_response("shipping")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
+
# Check for returns
|
73 |
+
elif any(word in user_message for word in ["return", "exchange", "refund"]):
|
74 |
+
bot_response = get_business_response("returns")
|
75 |
|
76 |
+
# Check for products
|
77 |
+
elif any(word in user_message for word in ["product", "sell", "offer", "item"]):
|
78 |
+
bot_response = get_business_response("products")
|
79 |
|
80 |
# Check for contact info
|
81 |
elif any(word in user_message for word in ["contact", "phone", "call", "email"]):
|
82 |
bot_response = get_business_response("contact")
|
83 |
|
84 |
+
# Check for location
|
85 |
+
elif any(word in user_message for word in ["where", "location", "address", "find"]):
|
86 |
+
bot_response = get_business_response("location")
|
|
|
|
|
|
|
|
|
87 |
|
88 |
+
# Check for business hours
|
89 |
+
elif any(word in user_message for word in ["hour", "time", "open", "close"]):
|
90 |
+
bot_response = get_business_response("hours")
|
91 |
|
92 |
# Check for help or capabilities
|
93 |
elif any(word in user_message for word in ["help", "what can you do", "how can you help", "capabilities", "what do you know"]):
|
94 |
bot_response = get_business_response("capabilities")
|
95 |
|
96 |
+
# Check for thanks
|
97 |
+
elif any(word in user_message for word in ["thank", "appreciate", "thanks"]):
|
98 |
+
bot_response = get_business_response("thanks")
|
99 |
+
|
100 |
+
# Check for goodbye
|
101 |
+
elif any(word in user_message for word in ["bye", "goodbye", "see you"]):
|
102 |
+
bot_response = get_business_response("goodbye")
|
103 |
+
|
104 |
+
# Check for greetings (moved to end to avoid conflicts)
|
105 |
+
elif any(word in user_message for word in ["hi", "hello", "hey", "greetings"]):
|
106 |
+
bot_response = get_business_response("greeting")
|
107 |
+
|
108 |
# Handle product inquiries
|
109 |
elif any(word in user_message for word in ["smartphone", "phone"]):
|
110 |
if "pro" in user_message or "premium" in user_message:
|
|
|
127 |
bot_response = "I'm here to help with information about our products, store hours, location, and policies. How can I assist you today?"
|
128 |
|
129 |
# Add a small delay to make it feel more natural
|
130 |
+
time.sleep(0.3)
|
131 |
|
132 |
# Append to chat history using the new Messages format
|
133 |
chat_history.append({"role": "user", "content": message})
|
|
|
170 |
margin: auto;
|
171 |
padding: 20px;
|
172 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
"""
|
174 |
|
175 |
# Create the Gradio interface
|
|
|
203 |
# Create example buttons with correct parameters
|
204 |
examples = gr.Examples(
|
205 |
examples=[
|
206 |
+
["Do you offer free shipping?"],
|
207 |
["What are your store hours?"],
|
208 |
["Where are you located?"],
|
209 |
["What smartphones do you sell?"],
|
210 |
["What is your return policy?"],
|
|
|
211 |
["What can you help with?"],
|
212 |
["Tell me about your laptops"]
|
213 |
],
|