DSatishchandra commited on
Commit
051e661
·
verified ·
1 Parent(s): edcd49c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -1
app.py CHANGED
@@ -11,6 +11,9 @@ menu = {
11
  "Desserts": ["Gulab Jamun", "Ice Cream"]
12
  }
13
 
 
 
 
14
  # Text-to-Speech Function
15
  def speak_and_save(text, filename="response.mp3"):
16
  tts = gTTS(text=text, lang='en')
@@ -36,6 +39,9 @@ def process_order(audio_file_path):
36
  if user_input.startswith("Sorry") or user_input.startswith("I didn't"):
37
  return user_input, None
38
 
 
 
 
39
  response = f"You said: {user_input}\n"
40
 
41
  # Process the user input
@@ -43,8 +49,31 @@ def process_order(audio_file_path):
43
  response += "Here is our menu:\n"
44
  for category, items in menu.items():
45
  response += f"{category}: {', '.join(items)}\n"
 
 
46
  elif "order" in user_input.lower():
47
- response += "Let me confirm your order."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  else:
49
  response += "I'm not sure what you meant. Could you clarify?"
50
 
 
11
  "Desserts": ["Gulab Jamun", "Ice Cream"]
12
  }
13
 
14
+ # Context to track ongoing conversation
15
+ context = {"last_action": None, "order": []}
16
+
17
  # Text-to-Speech Function
18
  def speak_and_save(text, filename="response.mp3"):
19
  tts = gTTS(text=text, lang='en')
 
39
  if user_input.startswith("Sorry") or user_input.startswith("I didn't"):
40
  return user_input, None
41
 
42
+ global context
43
+
44
+ # Default response
45
  response = f"You said: {user_input}\n"
46
 
47
  # Process the user input
 
49
  response += "Here is our menu:\n"
50
  for category, items in menu.items():
51
  response += f"{category}: {', '.join(items)}\n"
52
+ context["last_action"] = "show_menu"
53
+
54
  elif "order" in user_input.lower():
55
+ if context["last_action"] == "show_menu":
56
+ response += "What would you like to order?"
57
+ else:
58
+ response += "Please let me know what you'd like to order. We have starters, main course, breads, and desserts."
59
+ context["last_action"] = "place_order"
60
+
61
+ elif any(item.lower() in user_input.lower() for item in sum(menu.values(), [])):
62
+ # Add the ordered item to the context
63
+ for category, items in menu.items():
64
+ for item in items:
65
+ if item.lower() in user_input.lower():
66
+ context["order"].append(item)
67
+ response += f"I've added {item} to your order. Would you like anything else?"
68
+ break
69
+
70
+ elif "no" in user_input.lower() or "done" in user_input.lower():
71
+ if context["order"]:
72
+ response += f"Your final order is: {', '.join(context['order'])}. Thank you for ordering!"
73
+ context["order"] = []
74
+ else:
75
+ response += "It seems you haven't ordered anything yet."
76
+
77
  else:
78
  response += "I'm not sure what you meant. Could you clarify?"
79