File size: 3,141 Bytes
b7b8737
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()