-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
89 lines (74 loc) · 2.44 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import os
import pandas as pd
import numpy as np
import pickle
import sklearn
import flask
from flask import Flask, redirect, url_for, request, render_template, session, flash
from functools import wraps
app = Flask(__name__)
# config secret key
app.secret_key = 'capstone123'
def login_req(f):
@wraps(f)
def wrap(*args, **kwargs):
if 'logged_in' in session:
return f(*args, **kwargs)
else:
flash('Please log in with your username and password.')
return redirect(url_for('login'))
return wrap
@app.route('/')
@login_req
def index():
return flask.render_template('index.html')
@app.route('/login', methods=['GET', 'POST'])
def login():
error = None
if request.method == 'POST':
if request.form['username'] != 'admin' or request.form['password'] != 'password':
error = 'Invalid credentials. Please check your credentials and try again.'
else:
session['logged_in'] = True
return redirect(url_for('index'))
return render_template('login.html', error=error)
@app.route('/logout')
@login_req
def logout():
session.pop('logged_in', None)
flash('Logging out of session.')
return redirect(url_for('login'))
@app.route('/data')
def dataVisualization():
return render_template('data.html')
@app.route('/pca')
def pca():
return render_template('pca-visualization.html')
@app.route('/salesbygenre')
def salesbygenre():
return render_template('global_sales_by_genre.html')
@app.route('/salesbyrating')
def salesbyrating():
return render_template('global_sales_by_rating.html')
@app.route('/criticscore')
def criticscore():
return render_template('critic_score_scatter.html')
@app.route('/userscore')
def userscore():
return render_template('user_score_scatter.html')
def predictor(to_predict_list):
to_predict = np.array(to_predict_list).reshape(1, 4)
model = pickle.load(open('models/predictor.pkl','rb'))
result = model.predict(to_predict)
return result[0]
@app.route('/predict', methods=['POST'])
def result():
if request.method == 'POST':
to_predict_list = request.form.to_dict()
to_predict_list = list(to_predict_list.values())
to_predict_list = list(map(float, to_predict_list))
result = predictor(to_predict_list)
prediction = str(result)
return render_template('predict.html',prediction=prediction)
if __name__ == "__main__":
app.run(debug=True)