-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
33 lines (24 loc) · 934 Bytes
/
app.py
File metadata and controls
33 lines (24 loc) · 934 Bytes
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
from flask import Flask, request, render_template
import pandas as pd
import pickle
with open("/Users/ivyadiele/Desktop/FraudDetection/model/fraud_model.pkl", "rb") as f:
model = pickle.load(f)
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def index():
prediction_result = None
if request.method == "POST":
file = request.files["/Users/ivyadiele/Desktop/FraudDetection/data/creditcard.csv"]
if file:
data = pd.read_csv(file)
prediction = model.predict(data)
frauds = sum(prediction == -1)
total = len(prediction)
prediction_result = {
"frauds": frauds,
"total": total,
"message": f"Detected {frauds} fraudulent out of {total} transactions."
}
return render_template("index.html", result=prediction_result)
if __name__ == "__main__":
app.run(debug=True)