File size: 4,290 Bytes
46d2b0a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3d46b9a
46d2b0a
3d46b9a
 
46d2b0a
3d46b9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46d2b0a
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# 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)

from flask import Flask, render_template, request, jsonify
from flask_cors import CORS  # Importing CORS for handling cross-origin requests

app = Flask(__name__)
CORS(app)  # Enabling CORS for the entire app

# 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)