Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- README.md +19 -0
- model.pkl +3 -0
- requirements.txt +16 -0
- slapp.py +96 -0
README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: "Fraud Detection Model"
|
| 3 |
+
emoji: "🔍"
|
| 4 |
+
colorFrom: "red"
|
| 5 |
+
colorTo: "pink"
|
| 6 |
+
sdk: "streamlit"
|
| 7 |
+
sdk_version: "1.19.0" # Adjust to the version you're using
|
| 8 |
+
app_file: "slapp.py"
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Fraud Detection Model
|
| 13 |
+
|
| 14 |
+
This Space hosts a fraud detection model that predicts the acceptability of transactions based on various features.
|
| 15 |
+
|
| 16 |
+
## How to Use
|
| 17 |
+
|
| 18 |
+
1. Enter the transaction details in the input fields.
|
| 19 |
+
2. Click on the "Predict" button to see the results.
|
model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:276fc889b0a67b07e440abb5c91c8e096c5dee3da739c33cf01db2b5e14afc96
|
| 3 |
+
size 1211
|
requirements.txt
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask==1.1.2
|
| 2 |
+
scikit-learn==1.0.2
|
| 3 |
+
scipy
|
| 4 |
+
numpy==1.23.5
|
| 5 |
+
pandas==1.5.0
|
| 6 |
+
matplotlib
|
| 7 |
+
seaborn
|
| 8 |
+
schedule
|
| 9 |
+
jupyter
|
| 10 |
+
mlflow
|
| 11 |
+
requests
|
| 12 |
+
jinja2==3.1.2
|
| 13 |
+
streamlit==1.19.0
|
| 14 |
+
altair==5.0.0
|
| 15 |
+
|
| 16 |
+
|
slapp.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pickle
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
# Load the saved model
|
| 6 |
+
try:
|
| 7 |
+
model = pickle.load(open('model.pkl', 'rb'))
|
| 8 |
+
except Exception as e:
|
| 9 |
+
st.error(f"Error loading model: {e}")
|
| 10 |
+
model = None
|
| 11 |
+
|
| 12 |
+
# Streamlit app
|
| 13 |
+
st.title("Fraud Detection API")
|
| 14 |
+
st.write("Enter the transaction details to check if it's acceptable or fraudulent.")
|
| 15 |
+
|
| 16 |
+
# Create input fields for the features
|
| 17 |
+
time = st.number_input('Time')
|
| 18 |
+
v1 = st.number_input('V1')
|
| 19 |
+
v2 = st.number_input('V2')
|
| 20 |
+
v3 = st.number_input('V3')
|
| 21 |
+
v4 = st.number_input('V4')
|
| 22 |
+
v5 = st.number_input('V5')
|
| 23 |
+
v6 = st.number_input('V6')
|
| 24 |
+
v7 = st.number_input('V7')
|
| 25 |
+
v8 = st.number_input('V8')
|
| 26 |
+
v9 = st.number_input('V9')
|
| 27 |
+
v10 = st.number_input('V10')
|
| 28 |
+
v11 = st.number_input('V11')
|
| 29 |
+
v12 = st.number_input('V12')
|
| 30 |
+
v13 = st.number_input('V13')
|
| 31 |
+
v14 = st.number_input('V14')
|
| 32 |
+
v15 = st.number_input('V15')
|
| 33 |
+
v16 = st.number_input('V16')
|
| 34 |
+
v17 = st.number_input('V17')
|
| 35 |
+
v18 = st.number_input('V18')
|
| 36 |
+
v19 = st.number_input('V19')
|
| 37 |
+
v20 = st.number_input('V20')
|
| 38 |
+
v21 = st.number_input('V21')
|
| 39 |
+
v22 = st.number_input('V22')
|
| 40 |
+
v23 = st.number_input('V23')
|
| 41 |
+
v24 = st.number_input('V24')
|
| 42 |
+
v25 = st.number_input('V25')
|
| 43 |
+
v26 = st.number_input('V26')
|
| 44 |
+
v27 = st.number_input('V27')
|
| 45 |
+
v28 = st.number_input('V28')
|
| 46 |
+
amount = st.number_input('Amount')
|
| 47 |
+
|
| 48 |
+
# Prepare a button for prediction
|
| 49 |
+
if st.button('Predict'):
|
| 50 |
+
try:
|
| 51 |
+
# Create a DataFrame from the input data
|
| 52 |
+
transaction_data = pd.DataFrame({
|
| 53 |
+
'Time': [time],
|
| 54 |
+
'V1': [v1],
|
| 55 |
+
'V2': [v2],
|
| 56 |
+
'V3': [v3],
|
| 57 |
+
'V4': [v4],
|
| 58 |
+
'V5': [v5],
|
| 59 |
+
'V6': [v6],
|
| 60 |
+
'V7': [v7],
|
| 61 |
+
'V8': [v8],
|
| 62 |
+
'V9': [v9],
|
| 63 |
+
'V10': [v10],
|
| 64 |
+
'V11': [v11],
|
| 65 |
+
'V12': [v12],
|
| 66 |
+
'V13': [v13],
|
| 67 |
+
'V14': [v14],
|
| 68 |
+
'V15': [v15],
|
| 69 |
+
'V16': [v16],
|
| 70 |
+
'V17': [v17],
|
| 71 |
+
'V18': [v18],
|
| 72 |
+
'V19': [v19],
|
| 73 |
+
'V20': [v20],
|
| 74 |
+
'V21': [v21],
|
| 75 |
+
'V22': [v22],
|
| 76 |
+
'V23': [v23],
|
| 77 |
+
'V24': [v24],
|
| 78 |
+
'V25': [v25],
|
| 79 |
+
'V26': [v26],
|
| 80 |
+
'V27': [v27],
|
| 81 |
+
'V28': [v28],
|
| 82 |
+
'Amount': [amount]
|
| 83 |
+
})
|
| 84 |
+
|
| 85 |
+
# Perform prediction using the loaded model
|
| 86 |
+
prediction = model.predict(transaction_data)
|
| 87 |
+
|
| 88 |
+
# Prepare response
|
| 89 |
+
if prediction[0] == 0:
|
| 90 |
+
st.success('Prediction: Acceptable transaction')
|
| 91 |
+
else:
|
| 92 |
+
st.error('Prediction: Fraudulent transaction')
|
| 93 |
+
|
| 94 |
+
except Exception as e:
|
| 95 |
+
st.error(f'Error: {str(e)}')
|
| 96 |
+
|