Created
October 12, 2020 11:00
-
-
Save Abhayparashar31/edc79e1d5f9ff9ba97e1e50218ce142a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from flask import Flask,render_template,request | |
import pickle | |
import re | |
import nltk | |
nltk.download('stopwords') | |
from nltk.corpus import stopwords | |
from nltk.stem.porter import PorterStemmer | |
import pickle | |
###Loading model and cv | |
cv = pickle.load(open('cv.pkl','rb')) | |
model = pickle.load(open('review.pkl','rb')) | |
app = Flask(__name__) | |
@app.route('/') | |
def home(): | |
return render_template('index.html') | |
@app.route('/predict',methods=['POST']) | |
def predict(): | |
if request.method=='POST': | |
new_review = request.form['review'] ##requesting new review from the input field | |
new_review = re.sub('[^a-zA-Z]', ' ', new_review) | |
new_review = new_review.lower() | |
new_review = new_review.split() | |
ps = PorterStemmer() | |
all_stopwords = stopwords.words('english') | |
all_stopwords.remove('not') | |
new_review = [ps.stem(word) for word in new_review if not word in set(all_stopwords)] | |
new_review = ' '.join(new_review) | |
new_corpus = [new_review] | |
new_X_test = cv.transform(new_corpus).toarray() | |
pred = model.predict(new_X_test) | |
return render_template('result.html',prediction=pred) | |
if __name__ == "__main__": | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment