Spaces:
Sleeping
Sleeping
File size: 4,874 Bytes
a4f14f7 6530b77 a4f14f7 6530b77 a4f14f7 6530b77 a4f14f7 6530b77 a4f14f7 6530b77 a4f14f7 6530b77 a4f14f7 6530b77 a4f14f7 6530b77 a4f14f7 6530b77 a4f14f7 6530b77 a4f14f7 6530b77 a4f14f7 6530b77 a4f14f7 6530b77 a4f14f7 6530b77 a4f14f7 |
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 |
import streamlit as st
import numpy as np
import pickle
import streamlit.components.v1 as components
from sklearn.preprocessing import LabelEncoder
# Load the pickled model
@st.cache_resource
def load_model():
with open('online_payment_fraud_detection_randomforest.pkl', 'rb') as f:
return pickle.load(f)
# Load the LabelEncoder
@st.cache_resource
def load_label_encoder():
with open('label_encoder.pkl', 'rb') as f:
return pickle.load(f)
# Function for model prediction
def model_prediction(model, features):
predicted = str(model.predict(features)[0])
return predicted
def transform(le, text):
text = le.transform(text)
return text[0]
def app_design(le):
st.subheader("Enter the following values:")
step = st.number_input("Step: represents a unit of time where 1 step equals 1 hour", min_value=0)
typeup = st.selectbox('Type of online transaction', ('PAYMENT', 'TRANSFER', 'CASH_OUT', 'DEBIT', 'CASH_IN'))
typeup = transform(le, [typeup])
amount = st.number_input("The amount of the transaction", min_value=0.0)
nameOrig = st.text_input("Transaction ID (any ID)").strip()
nameOrig_transformed = transform(le, ['No']) # Dummy fallback for ID field
oldbalanceOrg = st.number_input("Balance before the transaction", min_value=0.0)
newbalanceOrig = st.number_input("Balance after the transaction", min_value=0.0)
nameDest = st.text_input("Recipient ID (any ID)").strip()
nameDest_transformed = transform(le, ['No']) # Dummy fallback for ID field
oldbalanceDest = st.number_input("Initial balance of recipient before the transaction", min_value=0.0)
newbalanceDest = st.number_input("The new balance of recipient after the transaction", min_value=0.0)
isFlaggedFraud = st.selectbox('Is this transaction flagged as fraud?', ('Yes', 'No'))
isFlaggedFraud = transform(le, [isFlaggedFraud])
# Create a feature list from the user inputs
features = np.array([[step, typeup, amount, nameOrig_transformed, oldbalanceOrg, newbalanceOrig, nameDest_transformed, oldbalanceDest, newbalanceDest, isFlaggedFraud]])
# Load the model
model = load_model()
# Make a prediction when the user clicks the "Predict" button
if st.button('Predict Online Payment Fraud'):
predicted_value = model_prediction(model, features)
if predicted_value == '1':
st.success("🚨 Online payment fraud detected!")
else:
st.success("✅ No online payment fraud detected.")
def about_RamDevs():
components.html("""
<div>
<h4>🚀 Unlock Your Easy Safety with RamDevs Community!</h4>
<p class="subtitle">🔍 Seeking the perfect hassle-free safe online transactions? RamDevs Community is your gateway to easier and safer transactions. Explore free expert sessions, customer support, and password transformation tips.</p>
<p class="subtitle">💼 We offer an upskill program in <b>CyberSecurity, Password management, Legal Terms and Services</b>, and assist customers in <b>security and safer online transactions</b> at minimal development costs.</p>
<p class="subtitle">🆓 Best of all, everything we offer is <b>completely free</b>! We are dedicated to helping society.</p>
<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>
<p class="subtitle">✨ We dedicate over 30 minutes to each applicant’s Password selection, Online profile, mock frauds, 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>
<p class="subtitle">💡 Join us now, and turbocharge your CyberSecurity!</p>
<p class="subtitle">
<a class="link" href="https://RamDevscommunity.wixsite.com/RamDevs" target="__blank">Website</a>
<a class="link" href="https://www.youtube.com/@RamDevsCommunity1307/" target="__blank">YouTube</a>
<a class="link" href="https://www.instagram.com/RamDevs_community/" target="__blank">Instagram</a>
<a class="link" href="https://medium.com/@RamDevscommunity" target="__blank">Medium</a>
<a class="link" href="https://www.linkedin.com/company/RamDevs-community/" target="__blank">LinkedIn</a>
<a class="link" href="https://github.com/RamDevscommunity" target="__blank">GitHub</a>
</p>
</div>
""", height=600)
def main():
st.set_page_config(page_title="Online Payment Fraud Detection", page_icon=":chart_with_upwards_trend:")
st.title("Welcome to our Online Payment Fraud Detection App! 🚀")
le = load_label_encoder()
app_design(le)
st.header("About RamDevs Community")
about_RamDevs()
if __name__ == '__main__':
main()
|