Shanmuganathan75 commited on
Commit
16a6b08
·
verified ·
1 Parent(s): 69ef626

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +29 -13
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
- """Handle order cancellation requests based on order status"""
263
- if "cancel" not in user_query.lower():
264
- return ""
265
-
266
- if order_status and order_status.lower() in ["delivered", "canceled"]:
 
 
 
 
 
 
 
 
 
 
267
  return (
268
- f"Your order has already been {order_status.lower()}, "
269
- "so cancellation is not possible. Thank you for understanding!"
 
270
  )
271
-
272
- elif order_status.lower() in ["preparing food", "picked up"]:
273
  return (
274
- f"Present status of your order is : {order_status.lower()}. "
275
- "Cancellation is not possible at this stage. Thank you for understanding!"
 
276
  )
277
-
278
  else:
279
- return "Your order cannot be canceled. We hope to serve you again!"
 
 
 
 
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: