This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from sklearn.feature_extraction.text import CountVectorizer | |
from sklearn.metrics.pairwise import cosine_similarity | |
from flask import Flask, render_template, request | |
import os.path | |
from rivescript import RiveScript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rive = os.getcwd() | |
bot = RiveScript() | |
bot.load_directory(brain) | |
bot.sort_replies() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+-----+-----+------+-----------+--------+-----+----------+ | |
| The | Bot | will | recommend | pizzas | for | customer | | |
+-----+-----+------+-----------+--------+-----+----------+ | |
| 2 | 1 | 1 | 1 | 1 | 1 | 1 | | |
+-----+-----+------+-----------+--------+-----+----------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getMyPizza(ingredients): | |
# load the dataset and clean the text | |
pizza_df = pd.read_csv("PizzaIngredients.csv",na_values=['?'," ",""]) | |
pizza_df.Ingredients.replace(to_replace="[|]",value=" ",inplace=True,regex=True) | |
myRow = ['MyPizza'] #converting ingredients column to list | |
myRow.append(ingredients) | |
pizza_df.loc[len(pizza_df)] = myRow | |
cv=CountVectorizer() | |
cv_matrix=cv.fit_transform(pizza_df['Ingredients']) #gives the matrix of n*n with count of words matched |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getReply(ingredients): | |
ans = getMyPizza(ingredients) | |
if ans != 0: | |
return "You may like: "+ans | |
else: | |
return str(bot.reply('localuser',ingredients)) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app = Flask(__name__) | |
# render the home.html file | |
@app.route("/") | |
def home(): | |
return render_template("home.html") | |
@app.route("/get") | |
def get_bot_response(): | |
userText = request.args.get('msg') | |
return getReply(userText) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+hi | |
-Hi!, welcome to our Pizzeria! Please enter your preferred ingredients to help us recommend you the best pizza for your palate. | |
+hello | |
-Hello!, welcome to our Pizzeria! Please enter your preferred ingredients to help us recommend you the best pizza for your palate. | |
+ i want pizza | |
-Which pizza would you like to have? | |
+ [*] (farmhouse|tandoori chicken|tanddori paneer|margherita) [*] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Pizza Predicter</title> | |
<link | |
rel="shortcut icon" | |
type="image/x-icon" | |
href="../static/pizza.png" | |
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+-----+------------+ | |
| Tid | Items | | |
+-----+------------+ | |
| 10 | A, C, D | | |
| 20 | B, C, E | | |
| 30 | A, B, C, E | | |
| 40 | B, E | | |
+-----+------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+-----+------------+ | |
| Tid | Items | | |
+-----+------------+ | |
| 10 | A, C, D | | |
| 20 | B, C, E | | |
| 30 | A, B, C, E | | |
| 40 | B, E | | |
+-----+------------+ | |