from flask import Flask, render_template_string, request, jsonify
from datetime import datetime
app = Flask(__name__)
# Initialize an empty list to store orders
orders = []
user_preferences = {"diet": "all"} # Default to all
# HTML code for the frontend
html_code = """
AI Dining Assistant
AI Dining Assistant
Press the mic button to start listening...
Response will appear here...
"""
@app.route('/')
def index():
return render_template_string(html_code)
@app.route('/process-audio', methods=['POST'])
def process_audio():
try:
audio_file = request.files['audio']
recognizer = sr.Recognizer()
with sr.AudioFile(audio_file) as source:
audio_data = recognizer.record(source)
command = recognizer.recognize_google(audio_data)
response = process_command(command)
return jsonify({"response": response})
except Exception as e:
return jsonify({"response": f"An error occurred: {str(e)}"})
def process_command(command):
"""Process the user's voice command and return a response."""
global orders
command = command.lower()
if "menu" in command:
return "Our menu includes paneer butter masala, fried rice, and cold coffee."
elif "order" in command:
return "Your order has been placed."
return "Sorry, I didn't understand your request."
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860)