# -*- coding: utf-8 -*- """ 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 """ #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 = """

Definition:Detecting fraud early is vital to prevent financial losses and protect businesses and individuals by addressing fraudulent activities promptly..


""" 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()