File size: 3,356 Bytes
0e9a35a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import streamlit as st 
import pandas as pd
import joblib   

# heading 
html_temp = """

    <div style="background-color:black;padding:10px">

    <h2 style="color:white;text-align:center;">Fraud Detection APP </h2>

    </div>

    """
st.markdown(html_temp, unsafe_allow_html=True)

# image
url="https://tse2.mm.bing.net/th?id=OIP.ROc4vnkJBbKTf8uWRQpldAHaDt&pid=Api&P=0&h=180"
st.image(url, use_container_width=True)

@st.cache_data
def convert_df(df):
    return df.to_csv(index=False).encode("utf-8")


# loading model
model=joblib.load('iso_fraude_dection.joblib')

# Dataset preiction
def Dataset_prediction():
    
    # Required column in dataframe
    req_col= pd.DataFrame(columns=['step', 'type', 'amount'])

    # Download the template
    csv = convert_df(req_col)
    st.download_button(
    label="Download Template",
    data=csv,
    file_name="Template.csv",
    mime="text/csv")


    # uploading model
    file=st.file_uploader('Please Upload the CSV File', type=["csv"])
    col1, col2 = st.columns(2)
    if file is not None:
        with col1:
            df = pd.read_csv(file,encoding='ISO-8859-1')
            st.write("Uploaded File Preview:")
            st.dataframe(df.head()) 
            
        if st.button("Predict Outliers"):
            try:
                # Ensure required columns exist
                required_columns = req_col
                if not all(col in df.columns for col in required_columns):
                    st.error("Uploaded file does not match the required template structure.")
                else:
                    predictions = model.predict(df)
                    with col2:
                        df['Anomaly'] = ['Anomaly' if pred == -1 else 'Not Anomaly' for pred in predictions]
                        st.write("Anomaly Detection Results:")
                        st.dataframe(df.head())
                        result_csv = convert_df(df)
                        st.download_button(
                        label="Download Results",
                        data=result_csv,
                        file_name="Anomaly_Detection_Results.csv",
                        mime="text/csv")
                        
            except Exception as e:
                st.error(f"An error occurred while processing the file: {e}")
            
            
                

# value prediction
def values_prediction():
    
    step=st.slider("Slide the Step Value:",min_value=1,max_value=743,value=1)
    amount=st.slider('Slide the amount Value:',min_value=1,max_value=92445516,value=1)
    option_type=['CASH_IN','CASH_OUT','DEBIT','PAYMENT','TRANSFER']
    type=st.selectbox("Select the type of Transaction:",options=option_type)
    type_value=option_type.index(type)
    if st.button('Submit'):
        output=model.predict([[step,type_value,amount]])
        if output == -1:
            st.write('Its not a Anomaly')
        else:
            st.write("Its a Anomaly")
    



# main 
st.sidebar.title("Select your Choice ")
file_type = st.sidebar.radio("Choose your BOT", ("Dataset Prediction", "Values Prediction"))
# if st.sidebar.button("submit"):
if file_type =="Dataset Prediction":
    Dataset_prediction()
elif file_type== "Values Prediction":
    values_prediction()