Spaces:
Sleeping
Sleeping
Update app (1).py
Browse files- app (1).py +42 -45
app (1).py
CHANGED
@@ -1,25 +1,26 @@
|
|
1 |
import streamlit as st
|
2 |
-
import numpy as np
|
3 |
import pickle
|
4 |
import streamlit.components.v1 as components
|
5 |
-
from sklearn.preprocessing import LabelEncoder
|
6 |
-
le = LabelEncoder()
|
7 |
|
8 |
# Load the pickled model
|
9 |
def load_model():
|
10 |
return pickle.load(open('Online_payment_fraud_detection_randomforest.pkl', 'rb'))
|
11 |
|
|
|
|
|
|
|
|
|
|
|
12 |
# Function for model prediction
|
13 |
def model_prediction(model, features):
|
14 |
predicted = str(model.predict(features)[0])
|
15 |
return predicted
|
16 |
|
17 |
-
def transform(text):
|
18 |
-
text = le.
|
19 |
return text[0]
|
20 |
|
21 |
-
|
22 |
-
def app_design():
|
23 |
# Add input fields for High, Open, and Low values
|
24 |
image = 'Ramdevs3'
|
25 |
st.image(image, use_column_width=True)
|
@@ -28,20 +29,21 @@ def app_design():
|
|
28 |
|
29 |
step = st.number_input("Step: represents a unit of time where 1 step equals 1 hour")
|
30 |
typeup = st.selectbox('Type of online transaction',('PAYMENT', 'TRANSFER', 'CASH_OUT', 'DEBIT', 'CASH_IN'))
|
31 |
-
typeup = transform([typeup])
|
32 |
amount = st.number_input("The amount of the transaction")
|
33 |
nameOrig = st.text_input("Transaction ID")
|
34 |
-
nameOrig = transform([nameOrig])
|
35 |
oldbalanceOrg = st.number_input("Balance before the transaction")
|
36 |
newbalanceOrig = st.number_input("Balance after the transaction")
|
37 |
nameDest = st.text_input("Recipient ID")
|
38 |
-
nameDest = transform([nameDest])
|
39 |
oldbalanceDest = st.number_input("Initial balance of recipient before the transaction")
|
40 |
newbalanceDest = st.number_input("The new balance of recipient after the transaction")
|
41 |
isFlaggedFraud = st.selectbox('IsFlaggedFraud',('Yes','No'))
|
42 |
-
isFlaggedFraud = transform([isFlaggedFraud])
|
|
|
43 |
# Create a feature list from the user inputs
|
44 |
-
features = [[step,typeup,amount,nameOrig,oldbalanceOrg,newbalanceOrig,nameDest,oldbalanceDest,newbalanceDest,isFlaggedFraud]]
|
45 |
|
46 |
# Load the model
|
47 |
model = load_model()
|
@@ -49,45 +51,40 @@ def app_design():
|
|
49 |
# Make a prediction when the user clicks the "Predict" button
|
50 |
if st.button('Predict Online Payment Fraud'):
|
51 |
predicted_value = model_prediction(model, features)
|
52 |
-
if predicted_value=='1':
|
53 |
st.success("Online payment fraud not happened")
|
54 |
else:
|
55 |
st.success("Online payment fraud happened")
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
|
78 |
def main():
|
|
|
|
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
)
|
85 |
-
|
86 |
-
st.title("Welcome to our Online Payment Fraud Detection App!")
|
87 |
-
|
88 |
-
# app_design()
|
89 |
-
# st.header("About RamDevs Community")
|
90 |
-
# about_RamDevs()
|
91 |
|
92 |
if __name__ == '__main__':
|
93 |
-
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import pickle
|
3 |
import streamlit.components.v1 as components
|
|
|
|
|
4 |
|
5 |
# Load the pickled model
|
6 |
def load_model():
|
7 |
return pickle.load(open('Online_payment_fraud_detection_randomforest.pkl', 'rb'))
|
8 |
|
9 |
+
# Load the LabelEncoder
|
10 |
+
def load_label_encoder():
|
11 |
+
with open('label_encoder.pkl', 'rb') as f:
|
12 |
+
return pickle.load(f)
|
13 |
+
|
14 |
# Function for model prediction
|
15 |
def model_prediction(model, features):
|
16 |
predicted = str(model.predict(features)[0])
|
17 |
return predicted
|
18 |
|
19 |
+
def transform(le, text):
|
20 |
+
text = le.transform(text)
|
21 |
return text[0]
|
22 |
|
23 |
+
def app_design(le):
|
|
|
24 |
# Add input fields for High, Open, and Low values
|
25 |
image = 'Ramdevs3'
|
26 |
st.image(image, use_column_width=True)
|
|
|
29 |
|
30 |
step = st.number_input("Step: represents a unit of time where 1 step equals 1 hour")
|
31 |
typeup = st.selectbox('Type of online transaction',('PAYMENT', 'TRANSFER', 'CASH_OUT', 'DEBIT', 'CASH_IN'))
|
32 |
+
typeup = transform(le, [typeup])
|
33 |
amount = st.number_input("The amount of the transaction")
|
34 |
nameOrig = st.text_input("Transaction ID")
|
35 |
+
nameOrig = transform(le, [nameOrig])
|
36 |
oldbalanceOrg = st.number_input("Balance before the transaction")
|
37 |
newbalanceOrig = st.number_input("Balance after the transaction")
|
38 |
nameDest = st.text_input("Recipient ID")
|
39 |
+
nameDest = transform(le, [nameDest])
|
40 |
oldbalanceDest = st.number_input("Initial balance of recipient before the transaction")
|
41 |
newbalanceDest = st.number_input("The new balance of recipient after the transaction")
|
42 |
isFlaggedFraud = st.selectbox('IsFlaggedFraud',('Yes','No'))
|
43 |
+
isFlaggedFraud = transform(le, [isFlaggedFraud])
|
44 |
+
|
45 |
# Create a feature list from the user inputs
|
46 |
+
features = [[step, typeup, amount, nameOrig, oldbalanceOrg, newbalanceOrig, nameDest, oldbalanceDest, newbalanceDest, isFlaggedFraud]]
|
47 |
|
48 |
# Load the model
|
49 |
model = load_model()
|
|
|
51 |
# Make a prediction when the user clicks the "Predict" button
|
52 |
if st.button('Predict Online Payment Fraud'):
|
53 |
predicted_value = model_prediction(model, features)
|
54 |
+
if predicted_value == '1':
|
55 |
st.success("Online payment fraud not happened")
|
56 |
else:
|
57 |
st.success("Online payment fraud happened")
|
58 |
|
59 |
+
def about_RamDevs():
|
60 |
+
components.html("""
|
61 |
+
<div>
|
62 |
+
<h4>🚀 Unlock Your Dream Job with RamDevs Community!</h4>
|
63 |
+
<p class="subtitle">🔍 Seeking the perfect job? RamDevs Community is your gateway to career success in the tech industry. Explore free expert courses, job-seeking support, and career transformation tips.</p>
|
64 |
+
<p class="subtitle">💼 We offer an upskill program in <b>Gen AI, Data Science, Machine Learning</b>, and assist startups in adopting <b>Gen AI</b> at minimal development costs.</p>
|
65 |
+
<p class="subtitle">🆓 Best of all, everything we offer is <b>completely free</b>! We are dedicated to helping society.</p>
|
66 |
+
<p class="subtitle">Book free of cost 1:1 mentorship on any topic of your choice — <a class="link" href="https://topmate.io/deepakchawla1307">topmate</a></p>
|
67 |
+
<p class="subtitle">✨ We dedicate over 30 minutes to each applicant’s resume, LinkedIn profile, mock interview, and upskill program. If you’d like our guidance, check out our services <a class="link" href="https://RamDevscommunity.wixsite.com/RamDevs">here</a></p>
|
68 |
+
<p class="subtitle">💡 Join us now, and turbocharge your career!</p>
|
69 |
+
<p class="subtitle">
|
70 |
+
<a class="link" href="https://RamDevscommunity.wixsite.com/RamDevs" target="__blank">Website</a>
|
71 |
+
<a class="link" href="https://www.youtube.com/@RamDevsCommunity1307/" target="__blank">YouTube</a>
|
72 |
+
<a class="link" href="https://www.instagram.com/RamDevs_community/" target="__blank">Instagram</a>
|
73 |
+
<a class="link" href="https://medium.com/@RamDevscommunity" target="__blank">Medium</a>
|
74 |
+
<a class="link" href="https://www.linkedin.com/company/RamDevs-community/" target="__blank">LinkedIn</a>
|
75 |
+
<a class="link" href="https://github.com/RamDevscommunity" target="__blank">GitHub</a>
|
76 |
+
</p>
|
77 |
+
</div>
|
78 |
+
""", height=600)
|
79 |
|
80 |
def main():
|
81 |
+
st.set_page_config(page_title="Online Payment Fraud Detection", page_icon=":chart_with_upwards_trend:")
|
82 |
+
st.title("Welcome to our Online Payment Fraud Detection App!")
|
83 |
|
84 |
+
le = load_label_encoder()
|
85 |
+
app_design(le)
|
86 |
+
st.header("About RamDevs Community")
|
87 |
+
about_RamDevs()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
if __name__ == '__main__':
|
90 |
+
main()
|