Fraud-Detection / app.py
JohnAlexander23's picture
Create app.py
b7b8737 verified
raw
history blame
3.14 kB
import streamlit as st
import pandas as pd
import joblib
def app():
st.title('Fraud Prediction')
st.header("Transaction Data Input")
st.write("Choose to upload a CSV file or manually input transaction data.")
# Load pre-trained model
with open('model.pkl', 'rb') as file_1:
model = joblib.load(file_1)
# Option to choose upload or manual input
option = st.radio("Select input method:", ("Upload CSV", "Manual Input"))
if option == "Upload CSV":
# Option to upload a CSV file
file_upload = st.file_uploader("Upload CSV", type=["csv"])
if file_upload is not None:
data = pd.read_csv(file_upload)
st.write("Uploaded Data Preview:")
st.write(data.head())
if st.button("Submit CSV"):
# Predict using the uploaded CSV data
predictions = model.predict(data)
data['prediction'] = predictions
data['prediction'] = data['prediction'].map({1: 'Fraud Transactions', 0: 'Not Fraud Transactions'})
st.write("Predictions:")
st.write(data[['type','nameOrig', 'nameDest', 'prediction']])
elif option == "Manual Input":
st.write("Manually input data:")
# Manual input of data
step = st.number_input("Step", min_value=0)
type = st.selectbox("Type", ["TRANSFER", "PAYMENT", "DEBIT", "CASH_OUT", "CASH_IN"])
amount = st.number_input("Amount", min_value=0.0)
nameOrig = st.text_input("Origin Account Name")
oldbalanceOrg = st.number_input("Old Balance (Origin)", min_value=0.0)
newbalanceOrig = st.number_input("New Balance (Origin)", min_value=0.0)
nameDest = st.text_input("Destination Account Name")
oldbalanceDest = st.number_input("Old Balance (Destination)", min_value=0.0)
newbalanceDest = st.number_input("New Balance (Destination)", min_value=0.0)
isFlaggedFraud = st.selectbox("Is Flagged Fraud?", [0, 1])
if st.button("Submit"):
# Create a DataFrame from manual input
manual_data = pd.DataFrame({
"step": [step],
"type": [type],
"amount": [amount],
"nameOrig": [nameOrig],
"oldbalanceOrg": [oldbalanceOrg],
"newbalanceOrig": [newbalanceOrig],
"nameDest": [nameDest],
"oldbalanceDest": [oldbalanceDest],
"newbalanceDest": [newbalanceDest],
"isFlaggedFraud": [isFlaggedFraud]
})
st.write("Manual Input Data:")
st.write(manual_data)
# Predict using the manually input data
manual_predictions = model.predict(manual_data)
manual_data['prediction'] = manual_predictions
manual_data['prediction'] = manual_data['prediction'].map({1: 'Fraud Transactions', 0: 'Not Fraud Transactions'})
st.write("Predictions:")
st.write(manual_data[['type','nameOrig', 'nameDest', 'prediction']])
if __name__ == "__main__":
app()