-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
65 lines (55 loc) · 1.77 KB
/
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
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
from flask import Flask, render_template, request
from sklearn.externals import joblib
import re
from nltk.corpus import stopwords
from nltk.stem import WordNetLemmatizer
app = Flask(__name__)
@app.route('/', methods=['GET'])
def main():
try:
if request.method == 'GET':
return render_template('home.html')
except:
return render_template('404.html')
@app.route('/home', methods=['GET', 'POST'])
def home_page():
try:
if request.method == 'GET':
return render_template('home.html')
except:
return render_template('404.html')
@app.route('/home/result', methods=['GET'])
def result():
try:
if request.method == 'GET':
return render_template('result.html')
except:
return render_template('404.html')
@app.route('/demo', methods=['GET'])
def demo_page():
try:
if request.method == 'GET':
return render_template('demo.html')
except:
return render_template('404.html')
@app.route('/article_result', methods=['POST'])
def article_result():
if request.method == 'POST':
text = request.form['text']
corpus = []
text = re.sub('[^a-zA-Z]', ' ', text)
text = text.lower()
text = text.split()
lemmatizer = WordNetLemmatizer()
text = [lemmatizer.lemmatize(word) for word in text if not word in set(
stopwords.words('english'))]
text = ' '.join(text)
corpus.append(text)
tfidf = joblib.load('vectorizer.pkl')
tfidf_corpus = tfidf.transform(corpus)
classifier = joblib.load('classifier.pkl')
prob = classifier.predict_proba(tfidf_corpus)[:, 1]
prob = prob*100
prob = "%.2f" % prob
this = float(prob)
return render_template('result.html', value=prob, this=this)