Skip to content

Instantly share code, notes, and snippets.

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
rive = os.getcwd()
bot = RiveScript()
bot.load_directory(brain)
bot.sort_replies()
+-----+-----+------+-----------+--------+-----+----------+
| The | Bot | will | recommend | pizzas | for | customer |
+-----+-----+------+-----------+--------+-----+----------+
| 2 | 1 | 1 | 1 | 1 | 1 | 1 |
+-----+-----+------+-----------+--------+-----+----------+
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
def getReply(ingredients):
ans = getMyPizza(ingredients)
if ans != 0:
return "You may like: "+ans
else:
return str(bot.reply('localuser',ingredients))
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)
+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) [*]
<!DOCTYPE html>
<html>
<head>
<title>Pizza Predicter</title>
<link
rel="shortcut icon"
type="image/x-icon"
href="../static/pizza.png"
/>
+-----+------------+
| Tid | Items |
+-----+------------+
| 10 | A, C, D |
| 20 | B, C, E |
| 30 | A, B, C, E |
| 40 | B, E |
+-----+------------+
+-----+------------+
| Tid | Items |
+-----+------------+
| 10 | A, C, D |
| 20 | B, C, E |
| 30 | A, B, C, E |
| 40 | B, E |
+-----+------------+