Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -259,24 +259,40 @@ def detect_escalation(user_query: str) -> str:
|
|
| 259 |
|
| 260 |
# Cancellation handler
|
| 261 |
def handle_cancellation(user_query: str, raw_orders: str, order_status: str) -> str:
|
| 262 |
-
"""
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
return (
|
| 268 |
-
f"Your order
|
| 269 |
-
"
|
|
|
|
| 270 |
)
|
| 271 |
-
|
| 272 |
-
elif
|
| 273 |
return (
|
| 274 |
-
|
| 275 |
-
"
|
|
|
|
| 276 |
)
|
| 277 |
-
|
| 278 |
else:
|
| 279 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
#________________________________________________________________________________________________________________________
|
| 281 |
# --- TOOL 1: Order Query Tool ---
|
| 282 |
def order_chatbot(input_string: str) -> str:
|
|
|
|
| 259 |
|
| 260 |
# Cancellation handler
|
| 261 |
def handle_cancellation(user_query: str, raw_orders: str, order_status: str) -> str:
|
| 262 |
+
"""
|
| 263 |
+
Handles order cancellation logic based on order status.
|
| 264 |
+
Returns a customer-friendly message.
|
| 265 |
+
"""
|
| 266 |
+
# CRITICAL FIX: Check if order_status is None first
|
| 267 |
+
if order_status is None or order_status == "":
|
| 268 |
+
return "⚠️ I couldn't retrieve the order status. Please ensure you have an active order and try again."
|
| 269 |
+
|
| 270 |
+
# Now safe to call .lower()
|
| 271 |
+
status_lower = order_status.lower()
|
| 272 |
+
|
| 273 |
+
if status_lower in ["delivered", "canceled"]:
|
| 274 |
+
return f"❌ Sorry, your order cannot be canceled as it is already **{order_status}**."
|
| 275 |
+
|
| 276 |
+
elif status_lower in ["preparing food", "picked up"]:
|
| 277 |
return (
|
| 278 |
+
f"⏳ Your order is currently **{order_status}**. "
|
| 279 |
+
"Unfortunately, we cannot cancel it at this stage. "
|
| 280 |
+
"Please contact our support team for urgent assistance."
|
| 281 |
)
|
| 282 |
+
|
| 283 |
+
elif status_lower == "placed":
|
| 284 |
return (
|
| 285 |
+
"✅ Your order has been successfully **canceled**! "
|
| 286 |
+
"Your refund will be processed within 5-7 business days. "
|
| 287 |
+
"We hope to serve you again soon! 🙏"
|
| 288 |
)
|
| 289 |
+
|
| 290 |
else:
|
| 291 |
+
return (
|
| 292 |
+
f"🔍 Your order status is **{order_status}**. "
|
| 293 |
+
"Please contact our customer support for cancellation assistance."
|
| 294 |
+
)
|
| 295 |
+
|
| 296 |
#________________________________________________________________________________________________________________________
|
| 297 |
# --- TOOL 1: Order Query Tool ---
|
| 298 |
def order_chatbot(input_string: str) -> str:
|