Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import sqlite3
import os.path
import numpy as np
from flask import Flask, request, jsonify, render_template, session, flash
import pickle
from passlib.hash import sha256_crypt
app = Flask(__name__)
model = pickle.load(open('model.pkl', 'rb'))
BAIS_DIR = os.path.dirname((os.path.abspath(__file__)))
db_path = os.path.join(BAIS_DIR, "Login.db")
sqlite3Connection = sqlite3.connect(db_path, check_same_thread=False)
cursor = sqlite3Connection.cursor()
print("Successfully Connected to SQLite")
@app.route('/')
def home():
if not session.get('logged_in'):
return render_template('login.html')
else:
return render_template('index.html')
# C:\Users\user\OneDrive\Desktop\MuhammadWebApp\Login.db
@app.route('/login', methods=['POST'])
def do_admin_login():
sqlite3Connection = sqlite3.connect('C:\\Users\\user\\OneDrive\\Desktop\\MuhammadWebApp\\Login.db', check_same_thread=False)
cursor = sqlite3Connection.cursor()
login = request.form
userName = login['username']
password = login['password']
print("start")
sqlite_select_query = ("SELECT * FROM login WHERE username= '%s'" % userName + ';')
sqlite_select_query = str((sqlite_select_query))
print("End query:")
cursor.execute(sqlite_select_query)
print("execute query:")
data = cursor.fetchone()
print(data)
if sha256_crypt.verify(password, data):
account = True
if account:
session['logged_in'] = True
else:
flash('wrong password!')
cursor.close()
return home()
@app.route('/predict', methods=['POST'])
def predict():
int_features = [int(x) for x in request.form.values()]
final_features = [np.array(int_features)]
prediction = model.predict(final_features)
output = round(prediction[0], 2)
if (output == 0):
output = "Non Fradulent"
else:
output = "Fradulent"
return render_template('index.html', prediction_text='Transaction is {}'.format(output))
@app.route('/predict_api', methods=['POST'])
def predict_api():
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)