File size: 2,040 Bytes
3d46b9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from flask import Flask, render_template, request, jsonify

app = Flask(__name__)

# Basic logic for chatbot responses
def bot_response(user_message):
    lower_case_message = user_message.lower()
    response = ""

    # Simple responses based on user input
    if "hello" in lower_case_message or "hi" in lower_case_message:
        response = "Hello! Welcome to our restaurant. How can I assist you today?"
    elif "menu" in lower_case_message:
        response = "Our menu includes: Pizza, Pasta, Burger, Salad, and Desserts. What would you like to order?"
    elif "order" in lower_case_message or "buy" in lower_case_message:
        response = "What would you like to order from the menu?"
    elif "pizza" in lower_case_message:
        response = "Great choice! Our pizzas are delicious. Would you like a small, medium, or large pizza?"
    elif "pasta" in lower_case_message:
        response = "Yum! Our pasta is freshly made. Would you like it with marinara sauce or Alfredo?"
    elif "burger" in lower_case_message:
        response = "Our burgers are served with fries. Would you like a vegetarian or beef burger?"
    elif "salad" in lower_case_message:
        response = "We have a variety of salads. Would you like a Caesar salad or a garden salad?"
    elif "dessert" in lower_case_message:
        response = "For dessert, we have cakes, ice cream, and pie. What would you like to try?"
    else:
        response = "I'm sorry, I didn't quite get that. Can you please repeat?"

    return response

# Home route to serve the chatbot's HTML page
@app.route('/')
def index():
    return render_template('index.html')

# API route for handling user input and getting the bot's response
@app.route('/chat', methods=['POST'])
def chat():
    user_message = request.json.get('message')
    if user_message:
        response = bot_response(user_message)
        return jsonify({'response': response})
    return jsonify({'response': 'Sorry, I could not understand that.'})

if __name__ == "__main__":
    app.run(debug=True)