Spaces:
Runtime error
Runtime error
File size: 4,155 Bytes
5a61a47 |
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# -*- coding: utf-8 -*-
"""
Created on Fri May 19 01:25:27 2023
@author: ME
"""
import streamlit as st
import numpy as np
from src.preprocessor import transform_single_data_point
import joblib
import xgboost as xgb
"""
STREAMLIT INTERFACE
"""
#load model
model_path = "Artifacts/xgboost_model.model"
# Load the model
loaded_model = xgb.XGBClassifier()
loaded_model.load_model(model_path)
#load preprocessor object
preprocessor_path = "Artifacts/preprocessor.pkl"
preprocessor_obj = joblib.load(preprocessor_path)
def main():
# Face Analysis Application #
st.title("Credit card fraud detector : Predicting fraudlent transactions by customers")
activities = ["Home","Predict Transaction"]
choice = st.sidebar.selectbox("Select Activity", activities)
st.sidebar.markdown(
""" Developed by as a project
Email me @ :
""")
if choice == "Home":
html_temp_home1 = """<div style="background-color:#6D7B8D;padding:10px">
<h4 style="color:white;text-align:center;">
Definition:Detecting fraud early is vital to prevent financial losses and protect businesses and individuals by addressing fraudulent activities promptly..</h4>
</div>
</br>"""
st.markdown(html_temp_home1, unsafe_allow_html=True)
st.write("""The main function of this application is to predict the likelihood of a transaction being fraudlent with few questions""")
elif choice == "Predict Transaction":
#amount
amount = st.number_input('Enter the amount of transaction made in local currency :')
#olf balance
oldbalanceOrg = st.number_input('Enter the initial balance of customer before transaction :')
#new balance of customer
newbalanceOrig = st.number_input('Enter the new balance of customer after transaction :')
#old balance of recippient
oldbalanceDest = st.number_input('Enter the initial balance of recipient before transaction :')
#new balance of customer
newbalanceDest = st.number_input('Enter the new balance of recipient after transaction :')
#new balance of customer
transferAmt = st.number_input('Enter difference between old and new balance :')
#select type of transaction
t_type = st.selectbox("Select transaction type?",tuple(["CASH_IN",
"CASH_OUT",
"PAYMENT",
"DEBIT",
"TRANSFER"
]))
single_data_point = {"amount":amount,
"oldbalanceOrg":oldbalanceOrg,
"newbalanceOrig":newbalanceOrig,
"oldbalanceDest":oldbalanceDest,
"newbalanceDest":newbalanceDest,
"transferAmt":transferAmt,
"type":t_type}
tranformed_single_data = transform_single_data_point(single_data = single_data_point,preprocessing_obj = preprocessor_obj)
#Prediction button
if st.button("Predict"):
output = loaded_model.predict(tranformed_single_data)
if output == 0:
st.write("This is a normal transaction")
else:
st.write("A likelihood of this transaction being fraudlent is detected -- More investigations should be done")
if __name__ == "__main__":
main() |