Spaces:
Build error
Build error
Upload 8 files
Browse files- .gitattributes +1 -0
- Procfile +1 -0
- app.py +68 -0
- card.csv +3 -0
- card_clf.pkl +3 -0
- requirements.txt +6 -0
- setup.sh +13 -0
.gitattributes
CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
35 |
+
card.csv filter=lfs diff=lfs merge=lfs -text
|
Procfile
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
web: sh setup.sh && streamlit run app.py
|
app.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import pickle
|
5 |
+
import base64
|
6 |
+
import seaborn as sns
|
7 |
+
import matplotlib.pyplot as plt
|
8 |
+
|
9 |
+
st.write("""
|
10 |
+
# Detection Fraud Credit Card
|
11 |
+
|
12 |
+
Kartu kredit adalah sebuah alat pembayaran menggunakan kartu yang berfungsi sebagai pengganti uang tunai.
|
13 |
+
""")
|
14 |
+
|
15 |
+
url_dataset = f'<a href="card.csv">Download Dataset CSV File</a>'
|
16 |
+
st.markdown(url_dataset, unsafe_allow_html=True)
|
17 |
+
|
18 |
+
def user_input_features() :
|
19 |
+
distance_from_home = st.sidebar.slider('distance_from_home', 0.004874, 10632.723672)
|
20 |
+
distance_from_last_transaction = st.sidebar.slider('distance_from_last_transaction', 0.000118, 11851.104565)
|
21 |
+
ratio_to_median_purchase_price = st.sidebar.slider('ratio_to_median_purchase_price', 0.004399, 267.802942)
|
22 |
+
repeat_retailer = st.sidebar.slider('repeat_retailer', 0.0, 1.0)
|
23 |
+
used_chip = st.sidebar.slider('used_chip', 0.0, 1.0)
|
24 |
+
used_pin_number = st.sidebar.slider('used_pin_number ', 0.0, 1.0)
|
25 |
+
online_order = st.sidebar.slider('online_order ', 0.0, 1.0)
|
26 |
+
|
27 |
+
data = {
|
28 |
+
'distance_from_home':[distance_from_home],
|
29 |
+
'distance_from_last_transaction':[distance_from_last_transaction],
|
30 |
+
'ratio_to_median_purchase_price':[ratio_to_median_purchase_price],
|
31 |
+
'repeat_retailer':[repeat_retailer],
|
32 |
+
'used_pin_number':[used_pin_number],
|
33 |
+
'online_order':[online_order],
|
34 |
+
'used_chip':[used_chip]
|
35 |
+
}
|
36 |
+
|
37 |
+
features = pd.DataFrame(data)
|
38 |
+
return features
|
39 |
+
|
40 |
+
input_df = user_input_features()
|
41 |
+
|
42 |
+
card_raw = pd.read_csv('card.csv')
|
43 |
+
card_raw.fillna(0, inplace=True)
|
44 |
+
card = card_raw.drop(columns=['fraud'])
|
45 |
+
df = pd.concat([input_df, card],axis=0)
|
46 |
+
|
47 |
+
df = df[:1] # Selects only the first row (the user input data)
|
48 |
+
df.fillna(0, inplace=True)
|
49 |
+
|
50 |
+
features = ['distance_from_home', 'distance_from_last_transaction',
|
51 |
+
'ratio_to_median_purchase_price', 'repeat_retailer', 'used_chip',
|
52 |
+
'used_pin_number', 'online_order']
|
53 |
+
|
54 |
+
df = df[features]
|
55 |
+
|
56 |
+
st.subheader('User Input features')
|
57 |
+
st.write(df)
|
58 |
+
load_clf = pickle.load(open('card_clf.pkl', 'rb'))
|
59 |
+
detection = load_clf.predict(df)
|
60 |
+
if(detection > 0) :
|
61 |
+
detection = 1
|
62 |
+
detection_proba = load_clf.predict_proba(df)
|
63 |
+
knee_labels = np.array(['Normal','Penipuan'])
|
64 |
+
st.subheader('Detection')
|
65 |
+
st.write(knee_labels[detection])
|
66 |
+
st.subheader('Detection Probability')
|
67 |
+
df_prob = pd.DataFrame(data=detection_proba, index=['Probability'], columns=knee_labels)
|
68 |
+
st.write(df_prob)
|
card.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7013c329bae9ef0ef32d65dbeb095694f0c7cd6c00ff74b2d0087fa1c67b8717
|
3 |
+
size 76277977
|
card_clf.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:92834859475433d0b26912608c842357f4f49fe381c5ffa9f4ca4caaf10f3bf8
|
3 |
+
size 3198324
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
matplotlib==3.6.0
|
2 |
+
numpy==1.23.3
|
3 |
+
pandas==1.5.0
|
4 |
+
seaborn==0.12.0
|
5 |
+
streamlit==1.12.2
|
6 |
+
sklearn
|
setup.sh
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
mkdir -p ~/.streamlit/
|
2 |
+
|
3 |
+
echo "\
|
4 |
+
[general]\n\
|
5 |
+
email = \"your-email@domain.com\"\n\
|
6 |
+
" > ~/.streamlit/credentials.toml
|
7 |
+
|
8 |
+
echo "\
|
9 |
+
[server]\n\
|
10 |
+
headless = true\n\
|
11 |
+
enableCORS=false\n\
|
12 |
+
port = $PORT\n\
|
13 |
+
" > ~/.streamlit/config.toml
|