# 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 | |
def index(): | |
return render_template('index.html') | |
# API route for handling user input and getting the bot's response | |
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) | |