-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
68 lines (33 loc) · 1.19 KB
/
Copy pathapp.py
File metadata and controls
68 lines (33 loc) · 1.19 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import numpy as np
from flask import Flask, request, jsonify, render_template
import joblib
from sklearn.feature_extraction.text import CountVectorizer
import sklearn.metrics as metrics
import re
import os
app = Flask(__name__)
def clean_article(article):
art = re.sub("[^A-Za-z0-9' ]", '', str(article))
art2 = re.sub("[( ' )(' )( ')]", ' ', str(art))
art3 = re.sub("\s[A-Za-z]\s", ' ', str(art2))
return art3.lower()
model = joblib.load(open('model.pkl', 'rb'))
cv = joblib.load(open('cv.pkl', 'rb'))
tfidfv = joblib.load(open('tfidfv.pkl', 'rb'))
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict',methods=['POST'])
def predict():
'''
For rendering results on HTML GUI
'''
comment = request.form['news']
list_comment = [comment]
list_comment = clean_article(list_comment)
list_comment = [list_comment]
prediction = model.predict(tfidfv.transform(list_comment))
output = prediction[0]
return render_template('index.html', prediction_text='The news is more likely to be as a {} news'.format(output))
if __name__ == "__main__":
app.run(debug=True)