Spaces:
Runtime error
Runtime error
# -*- 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() |