-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
48 lines (40 loc) · 1.37 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
from flask import Flask, request, jsonify, render_template
import numpy as np
import pickle
from dep import Lemmatizer
from bs4 import BeautifulSoup
import re
import string
from sklearn.feature_extraction.text import TfidfVectorizer
app = Flask(__name__)
model = pickle.load(open('model.pkl', 'rb'))
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict',methods=['POST'])
def predict():
'''
For rendering results on HTML GUI
'''
text=request.form.values()
regex = re.compile('[%s]' % re.escape('|'))
words = str(text).split()
words = [i.lower() + " " for i in words]
words = [i for i in words if not "http" in i]
words = " ".join(words)
words = words.translate(words.maketrans('', '', string.punctuation))
vectorizer=TfidfVectorizer(max_features=5000,stop_words='english',tokenizer=Lemmatizer())
raw=vectorizer.fit(words).toarray()
output=model.predict(raw)
return render_template('index.html', prediction_text='Your Personality Type is : {}'.format(output))
# @app.route('/predict_api',methods=['POST'])
# def predict_api():
# '''
# For direct API calls trought request
# '''
# data = request.get_json(force=True)
# prediction = model.predict([np.array(list(data.values()))])
# output = prediction[0]
# return jsonify(output)
if __name__ == "__main__":
app.run(debug=True)