-
Notifications
You must be signed in to change notification settings - Fork 0
/
app1.py
49 lines (40 loc) · 1.48 KB
/
app1.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
import numpy as np
from flask import Flask, request, jsonify, render_template
from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer
import pickle
import pandas as pd
df=pd.read_csv("int.csv",encoding="ISO-8859-1")
app = Flask(__name__)
model = pickle.load(open('model1.pkl', 'rb'))
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict',methods=['GET','POST'])
def predict():
'''
For rendering results on HTML GUI
'''
int1=[x for x in request.form.values()]
def text_seperation (x):
return x.split()
bow_transformer = CountVectorizer(analyzer=text_seperation).fit(df['SKILL'])
messages_bowt = bow_transformer.transform(int1)
tfidf_transformert = TfidfTransformer().fit(messages_bowt)
messages_tfidft = tfidf_transformert.transform(messages_bowt)
predict= model.predict(messages_tfidft)
p=int(np.asarray(predict))
df1=df[df["JOBLABELS"]==p]
df2=df1.reset_index()
output=df2["INTERNSHIPS"].tolist()
return render_template('index.html', prediction_text='YOUR INTERNSHIPS {}'.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)