Last active
October 5, 2020 11:19
-
-
Save Abhayparashar31/aae39aa340a8624bc6612de809c593df 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 | |
###Loading model and cv | |
cv = pickle.load(open('cv.pkl','rb')) ##loading cv | |
model = pickle.load(open('spam.pkl','rb')) ##loading model | |
app = Flask(__name__) ## defining flask name | |
@app.route('/') ## home route | |
def home(): | |
return render_template('index.html') ##at home route returning index.html to show | |
@app.route('/predict',methods=['POST']) ## on post request /predict | |
def predict(): | |
if request.method=='POST': | |
mail = request.form['email'] ## requesting the content of the text field | |
data = [mail] ## converting text into a list | |
vect = cv.transform(data).toarray() ## transforming the list of sentence into vecotor form | |
pred = model.predict(vect) ## predicting the class(1=spam,0=ham) | |
return render_template('result.html',prediction=pred) ## returning result.html with prediction var value as class value(0,1) | |
if __name__ == "__main__": | |
app.run(debug=True) ## running the flask app as debug==True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment