|
|
|
""" |
|
Created on Fri May 19 01:25:27 2023 |
|
|
|
@author: ME |
|
""" |
|
|
|
import streamlit as st |
|
import json |
|
import pickle |
|
import numpy as np |
|
import os |
|
import itertools |
|
from src.preprocessor import transform_single_data_point |
|
import joblib |
|
import xgboost as xgb |
|
|
|
v = st.__version__ |
|
|
|
print(v) |
|
""" |
|
STREAMLIT INTERFACE |
|
""" |
|
|
|
|
|
model_path = "Artifacts/xgboost_model.model" |
|
|
|
loaded_model = xgb.XGBClassifier() |
|
loaded_model.load_model(model_path) |
|
|
|
|
|
preprocessor_path = "Artifacts/preprocessor.pkl" |
|
preprocessor_obj = joblib.load(preprocessor_path) |
|
|
|
def main(): |
|
|
|
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 = st.number_input('Enter the amount of transaction made in local currency :') |
|
|
|
|
|
oldbalanceOrg = st.number_input('Enter the initial balance of customer before transaction :') |
|
|
|
|
|
|
|
newbalanceOrig = st.number_input('Enter the new balance of customer after transaction :') |
|
|
|
|
|
|
|
oldbalanceDest = st.number_input('Enter the initial balance of recipient before transaction :') |
|
|
|
|
|
|
|
newbalanceDest = st.number_input('Enter the new balance of recipient after transaction :') |
|
|
|
|
|
transferAmt = st.number_input('Enter difference between old and new balance :') |
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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() |