Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,10 +5,13 @@ import streamlit.components.v1 as components
|
|
5 |
from sklearn.preprocessing import LabelEncoder
|
6 |
|
7 |
# Load the pickled model
|
|
|
8 |
def load_model():
|
9 |
-
|
|
|
10 |
|
11 |
# Load the LabelEncoder
|
|
|
12 |
def load_label_encoder():
|
13 |
with open('label_encoder.pkl', 'rb') as f:
|
14 |
return pickle.load(f)
|
@@ -25,38 +28,40 @@ def transform(le, text):
|
|
25 |
def app_design(le):
|
26 |
st.subheader("Enter the following values:")
|
27 |
|
28 |
-
step = st.number_input("Step: represents a unit of time where 1 step equals 1 hour")
|
29 |
-
|
30 |
typeup = st.selectbox('Type of online transaction', ('PAYMENT', 'TRANSFER', 'CASH_OUT', 'DEBIT', 'CASH_IN'))
|
31 |
typeup = transform(le, [typeup])
|
32 |
|
33 |
-
amount = st.number_input("The amount of the transaction")
|
34 |
|
35 |
-
nameOrig = st.text_input("Transaction ID")
|
36 |
-
|
37 |
-
newbalanceOrig = st.number_input("Balance after the transaction")
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
newbalanceDest = st.number_input("The new balance of recipient after the transaction")
|
42 |
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
45 |
|
|
|
|
|
|
|
46 |
# Create a feature list from the user inputs
|
47 |
-
|
48 |
-
features = [[step, typeup, amount, 0, oldbalanceOrg, newbalanceOrig, 0, oldbalanceDest, newbalanceDest, isFlaggedFraud]]
|
49 |
|
50 |
# Load the model
|
51 |
model = load_model()
|
52 |
-
|
53 |
# Make a prediction when the user clicks the "Predict" button
|
54 |
if st.button('Predict Online Payment Fraud'):
|
55 |
predicted_value = model_prediction(model, features)
|
56 |
if predicted_value == '1':
|
57 |
-
st.success("
|
58 |
else:
|
59 |
-
st.success("✅ No online payment fraud detected")
|
60 |
|
61 |
def about_RamDevs():
|
62 |
components.html("""
|
@@ -81,7 +86,7 @@ def about_RamDevs():
|
|
81 |
|
82 |
def main():
|
83 |
st.set_page_config(page_title="Online Payment Fraud Detection", page_icon=":chart_with_upwards_trend:")
|
84 |
-
st.title("Welcome to our Online Payment Fraud Detection App!")
|
85 |
|
86 |
le = load_label_encoder()
|
87 |
app_design(le)
|
|
|
5 |
from sklearn.preprocessing import LabelEncoder
|
6 |
|
7 |
# Load the pickled model
|
8 |
+
@st.cache_resource
|
9 |
def load_model():
|
10 |
+
with open('online_payment_fraud_detection_randomforest.pkl', 'rb') as f:
|
11 |
+
return pickle.load(f)
|
12 |
|
13 |
# Load the LabelEncoder
|
14 |
+
@st.cache_resource
|
15 |
def load_label_encoder():
|
16 |
with open('label_encoder.pkl', 'rb') as f:
|
17 |
return pickle.load(f)
|
|
|
28 |
def app_design(le):
|
29 |
st.subheader("Enter the following values:")
|
30 |
|
31 |
+
step = st.number_input("Step: represents a unit of time where 1 step equals 1 hour", min_value=0)
|
|
|
32 |
typeup = st.selectbox('Type of online transaction', ('PAYMENT', 'TRANSFER', 'CASH_OUT', 'DEBIT', 'CASH_IN'))
|
33 |
typeup = transform(le, [typeup])
|
34 |
|
35 |
+
amount = st.number_input("The amount of the transaction", min_value=0.0)
|
36 |
|
37 |
+
nameOrig = st.text_input("Transaction ID (any ID)").strip()
|
38 |
+
nameOrig_transformed = transform(le, ['No']) # Dummy fallback for ID field
|
|
|
39 |
|
40 |
+
oldbalanceOrg = st.number_input("Balance before the transaction", min_value=0.0)
|
41 |
+
newbalanceOrig = st.number_input("Balance after the transaction", min_value=0.0)
|
|
|
42 |
|
43 |
+
nameDest = st.text_input("Recipient ID (any ID)").strip()
|
44 |
+
nameDest_transformed = transform(le, ['No']) # Dummy fallback for ID field
|
45 |
+
|
46 |
+
oldbalanceDest = st.number_input("Initial balance of recipient before the transaction", min_value=0.0)
|
47 |
+
newbalanceDest = st.number_input("The new balance of recipient after the transaction", min_value=0.0)
|
48 |
|
49 |
+
isFlaggedFraud = st.selectbox('Is this transaction flagged as fraud?', ('Yes', 'No'))
|
50 |
+
isFlaggedFraud = transform(le, [isFlaggedFraud])
|
51 |
+
|
52 |
# Create a feature list from the user inputs
|
53 |
+
features = np.array([[step, typeup, amount, nameOrig_transformed, oldbalanceOrg, newbalanceOrig, nameDest_transformed, oldbalanceDest, newbalanceDest, isFlaggedFraud]])
|
|
|
54 |
|
55 |
# Load the model
|
56 |
model = load_model()
|
57 |
+
|
58 |
# Make a prediction when the user clicks the "Predict" button
|
59 |
if st.button('Predict Online Payment Fraud'):
|
60 |
predicted_value = model_prediction(model, features)
|
61 |
if predicted_value == '1':
|
62 |
+
st.success("🚨 Online payment fraud detected!")
|
63 |
else:
|
64 |
+
st.success("✅ No online payment fraud detected.")
|
65 |
|
66 |
def about_RamDevs():
|
67 |
components.html("""
|
|
|
86 |
|
87 |
def main():
|
88 |
st.set_page_config(page_title="Online Payment Fraud Detection", page_icon=":chart_with_upwards_trend:")
|
89 |
+
st.title("Welcome to our Online Payment Fraud Detection App! 🚀")
|
90 |
|
91 |
le = load_label_encoder()
|
92 |
app_design(le)
|