-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
47 lines (35 loc) · 1.34 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
from flask import Flask, redirect, url_for, request, render_template, jsonify
import pandas as pd
from joblib import dump, load
import sklearn
import json
#Model
with open(f'model/FBRandomForest_model_vf.joblib', 'rb') as f:
model = load(f)
app = Flask(__name__, template_folder='templates')
@app.route('/')
def index():
return render_template('index.html')
@app.route('/postmeter', methods=['POST'])
def modelP():
avgpagelikes = request.json['avgpagelikes']
posttype = request.json['posttype']
postcategory = request.json['postcategory']
month = request.json['month']
weekday = request.json['weekday']
hour = request.json['hour']
paid = request.json['paid']
unique = request.json['unique']
input_variables = pd.DataFrame([[avgpagelikes, posttype, postcategory, month, weekday, hour, paid, unique]],
columns=['avgpagelikes','posttype','postcategory', 'month', 'weekday', 'hour','paid', 'unique'],
dtype='float',
index=['input'])
predictions = model.predict(input_variables)[0]
#if predictions == 0:
# result = 'unsuccessful'
#else:
# result = 'successful'
#print(predictions)
return jsonify(result = int(predictions))
if __name__ == '__main__':
app.run(debug=True)