forked from levirdz/santander-transaction-predictor-heroku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
75 lines (61 loc) · 2.29 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
# Dependencies Setup
import pandas as pd
from flask import Flask, request, redirect, url_for, flash, jsonify, render_template
import requests
import numpy as np
import json
import sqlite3 as sql
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.models import load_model
#Set up data base
conn = sql.connect('data/test_final.db', check_same_thread=False)
# Create an instance of the Flask class
app = Flask(__name__)
@app.route("/")
def home():
return render_template("index.html")
@app.route("/historicaldata")
def historical():
return render_template("data.html")
@app.route("/dashboard")
def dashboard():
return render_template("dashboard.html")
@app.route("/models")
def getmodels():
return render_template("models.html")
# @app.route("/class/<test_id>")
# def test(test_id):
# return jsonify(result)
@app.route('/predict/', methods=["GET"])
def predict():
if request.method == 'GET':
conn = sql.connect('data/test_final.db', check_same_thread=False)
hour = request.args['id']
x = pd.read_sql(f'SELECT * FROM final WHERE ID_code == "test_{hour}"', conn)
x = x.drop("index", axis=1)
x= x.drop("ID_code", axis=1)
model = load_model("neuronal_network_07.h5", compile=False)
pred_class = model.predict_classes(x)
probability = model.predict(x)
no_transaction = probability[0][0]
transaction = probability[0][1]
result = []
pred_class = pred_class[0]
if pred_class == 0:
result_dict = {}
result_dict['prediction'] = 'NO Transaction'
result_dict['No transaction'] = str(no_transaction)
result_dict['transaction'] = str(transaction)
result.append(result_dict)
else:
result_dict = {}
result_dict['prediction'] = 'Transaction'
result_dict['No transaction'] = str(no_transaction)
result_dict['transaction'] = str(transaction)
result.append(result_dict)
return render_template("prediction.html", pred= result_dict['prediction'],
pred1 = result_dict["No transaction"],
pred2 = result_dict['transaction'])
if __name__ == '__main__':
app.run(debug=True)