-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
40 lines (27 loc) · 985 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from flask import Flask, request, render_template
from sklearn.feature_extraction.text import TfidfVectorizer
import pickle
import catboost
app = Flask(__name__, '/static')
model = pickle.load(open('models/mylatestmodel.pkl', 'rb'))
vectorizer = pickle.load(open('models/vectorizer.pkl', 'rb'))
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict', methods=['POST'])
def predict():
email = request.form.values()
alphabet = '''abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'''
text = ""
for element in email:
if element in alphabet:
text += element
text = vectorizer.transform([text])
prediction = model.predict(text)
if prediction == 0:
return render_template('index.html', prediction_text='This email is a HAM!')
else:
return render_template('index.html', prediction_text='This email is a SPAM!')
if __name__ == '__main__':
app.debug = True
app.run()