dschandra commited on
Commit
f73965a
·
verified ·
1 Parent(s): 646145e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -11
app.py CHANGED
@@ -12,6 +12,10 @@ app = Flask(__name__)
12
  # Set up logging
13
  logging.basicConfig(level=logging.INFO)
14
 
 
 
 
 
15
  # HTML Template for Frontend
16
  html_code = """
17
  <!DOCTYPE html>
@@ -156,6 +160,7 @@ def index():
156
 
157
  @app.route('/process-audio', methods=['POST'])
158
  def process_audio():
 
159
  try:
160
  # Validate audio file
161
  audio_file = request.files.get('audio')
@@ -217,20 +222,34 @@ def process_audio():
217
  logging.error(f"Error cleaning up files: {cleanup_error}")
218
 
219
  def process_command(command):
220
- """Process the user's voice command and return a response."""
 
221
  command = command.lower()
222
- if "menu" in command:
223
  return (
224
- "Here is our menu: "
225
- "South Indian dishes include Idli, Dosa, Vada, Pongal, Biryani, and Sambar Rice. "
226
- "North Indian dishes include Butter Chicken, Paneer Butter Masala, Naan, Dal Makhani, Chole Bhature, and Rajma Chawal. "
227
- "What would you like to order?"
228
  )
229
- elif "order" in command:
230
- return "Your order has been placed. Would you like anything else?"
231
- elif "no" in command or "nothing" in command:
232
- return "Goodbye! Thank you for using AI Dining Assistant."
233
- return "Sorry, I didn't understand your request. Please ask about the menu or place an order."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
234
 
235
  if __name__ == "__main__":
236
  app.run(host="0.0.0.0", port=7860)
 
12
  # Set up logging
13
  logging.basicConfig(level=logging.INFO)
14
 
15
+ # Initialize conversation state
16
+ user_order = [] # Stores the current order
17
+ user_preferences = {} # Stores the customer's preferences
18
+
19
  # HTML Template for Frontend
20
  html_code = """
21
  <!DOCTYPE html>
 
160
 
161
  @app.route('/process-audio', methods=['POST'])
162
  def process_audio():
163
+ global user_order, user_preferences
164
  try:
165
  # Validate audio file
166
  audio_file = request.files.get('audio')
 
222
  logging.error(f"Error cleaning up files: {cleanup_error}")
223
 
224
  def process_command(command):
225
+ global user_order, user_preferences
226
+
227
  command = command.lower()
228
+ if "hello" in command or "hi" in command or "hey" in command:
229
  return (
230
+ "Welcome! How can I assist you with your meal today? "
231
+ "Please let me know your preferences."
 
 
232
  )
233
+ elif "reset preferences" in command:
234
+ user_order = [] # Reset the order
235
+ user_preferences = {} # Reset preferences
236
+ return "Your preferences have been reset. What would you like to order?"
237
+ elif "show my order" in command or "what's my order" in command:
238
+ if user_order:
239
+ return "Your current order includes: " + ", ".join(user_order)
240
+ else:
241
+ return "You haven't added anything to your order yet."
242
+ elif "place order" in command or "confirm order" in command:
243
+ if user_order:
244
+ return (
245
+ "You have the following items in your order: " + ", ".join(user_order) +
246
+ ". Would you like to confirm your order?"
247
+ )
248
+ else:
249
+ return "You haven't added anything to your order yet. Please add some items."
250
+ elif "yes" in command or "place order" in command:
251
+ return "Your order has been confirmed and sent to the kitchen. Thank you for ordering!"
252
+ return "Sorry, I didn't understand your request. You can ask to view your order, reset preferences, or place an order."
253
 
254
  if __name__ == "__main__":
255
  app.run(host="0.0.0.0", port=7860)