Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -24,45 +24,12 @@ std = np.array([3.9504547e+04, 1.9434261e+00, 1.6578650e+00, 1.4903845e+00,
|
|
24 |
6.0594761e-01, 5.0777191e-01, 4.8668963e-01, 4.0041801e-01,
|
25 |
3.3410770e-01, 2.5052232e+02])
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
'V1': [-56.407509631329, 2.45492999121121],
|
30 |
-
'V10': [-24.5882624372475, 23.7451361206545],
|
31 |
-
'V11': [-4.79747346479757, 12.0189131816199],
|
32 |
-
'V12': [-18.6837146333443, 7.8483920756446],
|
33 |
-
'V13': [-5.79188120632084, 7.12688295859376],
|
34 |
-
'V14': [-19.2143254902614, 10.5267660517847],
|
35 |
-
'V15': [-4.49894467676621, 8.87774159774277],
|
36 |
-
'V16': [-14.1298545174931, 17.3151115176278],
|
37 |
-
'V17': [-25.1627993693248, 9.25352625047285],
|
38 |
-
'V18': [-9.49874592104677, 5.04106918541184],
|
39 |
-
'V19': [-7.21352743017759, 5.59197142733558],
|
40 |
-
'V2': [-72.7157275629303, 22.0577289904909],
|
41 |
-
'V20': [-54.497720494566, 39.4209042482199],
|
42 |
-
'V21': [-34.8303821448146, 27.2028391573154],
|
43 |
-
'V22': [-10.933143697655, 10.5030900899454],
|
44 |
-
'V23': [-44.8077352037913, 22.5284116897749],
|
45 |
-
'V24': [-2.83662691870341, 4.58454913689817],
|
46 |
-
'V25': [-10.2953970749851, 7.51958867870916],
|
47 |
-
'V26': [-2.60455055280817, 3.5173456116238],
|
48 |
-
'V27': [-22.5656793207827, 31.6121981061363],
|
49 |
-
'V28': [-15.4300839055349, 33.8478078188831],
|
50 |
-
'V3': [-48.3255893623954, 9.38255843282114],
|
51 |
-
'V4': [-5.68317119816995, 16.8753440335975],
|
52 |
-
'V5': [-113.743306711146, 34.8016658766686],
|
53 |
-
'V6': [-26.1605059358433, 73.3016255459646],
|
54 |
-
'V7': [-43.5572415712451, 120.589493945238],
|
55 |
-
'V8': [-73.2167184552674, 20.0072083651213],
|
56 |
-
'V9': [-13.4340663182301, 15.5949946071278]}
|
57 |
-
|
58 |
-
def infer(seed):
|
59 |
|
60 |
data = pd.DataFrame({
|
61 |
-
|
62 |
-
|
63 |
-
else np.random.uniform(fts_min_max[col][0], fts_min_max[col][1])
|
64 |
-
for col in ['Time', 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', 'V7', 'V8', 'V9', 'V10', 'V11', 'V12', 'V13', 'V14', 'V15', 'V16', 'V17', 'V18', 'V19', 'V20', 'V21',
|
65 |
-
'V22', 'V23', 'V24', 'V25', 'V26', 'V27', 'V28', 'Amount']
|
66 |
}, index=[0])
|
67 |
|
68 |
test_features = data.copy().values
|
@@ -73,27 +40,81 @@ def infer(seed):
|
|
73 |
data = data.round(decimals = 2)
|
74 |
|
75 |
#return f"{round(pred.flatten()[0]*100, 5)}%", data.values.tolist()
|
76 |
-
result = 'This is fraudulent transaction
|
77 |
-
return result
|
78 |
|
79 |
# get the inputs
|
80 |
-
inputs = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
# the app outputs two segmented images
|
83 |
-
output = [
|
84 |
-
gr.Textbox(label=''),
|
85 |
-
gr.Dataframe(headers = ['Time', 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', 'V7', 'V8', 'V9', 'V10', 'V11', 'V12', 'V13', 'V14', 'V15', 'V16', 'V17', 'V18', 'V19', 'V20', 'V21',
|
86 |
-
'V22', 'V23', 'V24', 'V25', 'V26', 'V27', 'V28', 'Amount'],
|
87 |
-
max_rows = 1, row_count = 1, max_cols = 30, col_count = 30,
|
88 |
-
type='pandas', label='Display of generated data input for model')
|
89 |
-
]
|
90 |
|
91 |
title = 'Imbalanced Classification with Tensorflow'
|
92 |
description = 'Imbalanced Classification in predicting Credit card Fraud.'
|
93 |
|
94 |
-
article = "Author: <a href=\"https://huggingface.co/geninhu\">Nhu Hoang</a>. Based on this <a href=\"https://keras.io/examples/structured_data/imbalanced_classification/\">keras example</a> by <a href=\"https://twitter.com/fchollet\">fchollet.</a> HuggingFace Model <a href=\"https://huggingface.co/keras-io/imbalanced_classification\">here</a> "
|
95 |
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
-
gr.Interface(infer, inputs, output, allow_flagging='never',
|
99 |
title=title, description=description, article=article, live=False).launch(enable_queue=True, debug=False)
|
|
|
24 |
6.0594761e-01, 5.0777191e-01, 4.8668963e-01, 4.0041801e-01,
|
25 |
3.3410770e-01, 2.5052232e+02])
|
26 |
|
27 |
+
# def infer(seed):
|
28 |
+
def infer(Time, V1, V2, V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,V20,V21,V22,V23,V24,V25,V26,V27,V28,Amount):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
data = pd.DataFrame({
|
31 |
+
'Time': Time, 'V1': V1, 'V2':V2, 'V3':V3, 'V4':V4, 'V5':V5, 'V6':V6, 'V7':V7, 'V8':V8, 'V9':V9, 'V10':V10, 'V11':V11, 'V12':V12, 'V13':V13, 'V14':V14, 'V15':V15, 'V16':V16,
|
32 |
+
'V17':V17, 'V18':V18, 'V19':V19, 'V20':V20, 'V21':V21, 'V22':V22, 'V23':V23, 'V24':V24, 'V25':V25, 'V26':V26, 'V27':V27, 'V28':V28, 'Amount':Amount
|
|
|
|
|
|
|
33 |
}, index=[0])
|
34 |
|
35 |
test_features = data.copy().values
|
|
|
40 |
data = data.round(decimals = 2)
|
41 |
|
42 |
#return f"{round(pred.flatten()[0]*100, 5)}%", data.values.tolist()
|
43 |
+
result = f'This is fraudulent transaction with probability is {round(pred.flatten()[0]*100, 5)}%' if pred.flatten()[0] > 0.5 else f"This is real transaction with probability is {round((1-pred.flatten()[0])*100, 3)}%"
|
44 |
+
return result #, data.values.tolist()
|
45 |
|
46 |
# get the inputs
|
47 |
+
inputs = [
|
48 |
+
gr.Slider(minimum=0, maximum=172700, step=10, label='Time', value=10),
|
49 |
+
gr.Slider(minimum=-56, maximum=2, step=0.1, label='V1', value=0),
|
50 |
+
gr.Slider(minimum=-72, maximum=23, step=0.1, label='V2', value=0),
|
51 |
+
gr.Slider(minimum=-48, maximum=9, step=0.1, label='V3', value=0),
|
52 |
+
gr.Slider(minimum=-5, maximum=16, step=0.1, label='V4', value=0),
|
53 |
+
gr.Slider(minimum=-113, maximum=32, step=0.1, label='V5', value=0),
|
54 |
+
gr.Slider(minimum=-26, maximum=73, step=0.1, label='V6', value=0),
|
55 |
+
gr.Slider(minimum=-43, maximum=113, step=0.1, label='V7', value=0),
|
56 |
+
gr.Slider(minimum=-73, maximum=20, step=0.1, label='V8', value=0),
|
57 |
+
gr.Slider(minimum=-13, maximum=15, step=0.1, label='V9', value=0),
|
58 |
+
gr.Slider(minimum=-24, maximum=23, step=0.1, label='V10', value=0),
|
59 |
+
gr.Slider(minimum=-4, maximum=12, step=0.1, label='V11', value=0),
|
60 |
+
gr.Slider(minimum=-18, maximum=7, step=0.1, label='V12', value=0),
|
61 |
+
gr.Slider(minimum=-5, maximum=7, step=0.1, label='V13', value=0),
|
62 |
+
gr.Slider(minimum=-19, maximum=10, step=0.1, label='V14', value=0),
|
63 |
+
gr.Slider(minimum=-4, maximum=8, step=0.1, label='V15', value=0),
|
64 |
+
gr.Slider(minimum=-14, maximum=17, step=0.1, label='V16', value=0),
|
65 |
+
gr.Slider(minimum=-25, maximum=9, step=0.1, label='V17', value=0),
|
66 |
+
gr.Slider(minimum=-9, maximum=5, step=0.1, label='V18', value=0),
|
67 |
+
gr.Slider(minimum=-7, maximum=5, step=0.1, label='V19', value=0),
|
68 |
+
gr.Slider(minimum=-54, maximum=39, step=0.1, label='V20', value=0),
|
69 |
+
gr.Slider(minimum=-34, maximum=27, step=0.1, label='V21', value=0),
|
70 |
+
gr.Slider(minimum=-10, maximum=10, step=0.1, label='V22', value=0),
|
71 |
+
gr.Slider(minimum=-44, maximum=22, step=0.1, label='V23', value=0),
|
72 |
+
gr.Slider(minimum=-2, maximum=4, step=0.1, label='V24', value=0),
|
73 |
+
gr.Slider(minimum=-10, maximum=7, step=0.1, label='V25', value=0),
|
74 |
+
gr.Slider(minimum=-2, maximum=5, step=0.1, label='V26', value=0),
|
75 |
+
gr.Slider(minimum=-22, maximum=31, step=0.1, label='V27', value=0),
|
76 |
+
gr.Slider(minimum=-15, maximum=33, step=0.1, label='V28', value=0),
|
77 |
+
gr.Slider(minimum=0, maximum=25691, step=10, label='Amount', value=10),
|
78 |
+
]
|
79 |
|
80 |
# the app outputs two segmented images
|
81 |
+
output = [gr.Textbox(label='')]
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
title = 'Imbalanced Classification with Tensorflow'
|
84 |
description = 'Imbalanced Classification in predicting Credit card Fraud.'
|
85 |
|
86 |
+
article = "Author: <a href=\"https://huggingface.co/geninhu\">Nhu Hoang</a>. <br> Based on this <a href=\"https://keras.io/examples/structured_data/imbalanced_classification/\">keras example</a> by <a href=\"https://twitter.com/fchollet\">fchollet.</a> <br> HuggingFace Model <a href=\"https://huggingface.co/keras-io/imbalanced_classification\">here</a> "
|
87 |
|
88 |
+
examples = [[1.39271000e+05, -1.01966286e-01, -2.19383079e-01,
|
89 |
+
2.91556060e-01, -1.48187543e+00, 4.92119816e-01,
|
90 |
+
7.19159629e-01, 1.09760697e+00, -3.29724791e-01,
|
91 |
+
-5.36999746e-01, 4.44389995e-01, -6.76070884e-01,
|
92 |
+
-9.84972751e-01, -1.17935517e+00, 2.52172631e-02,
|
93 |
+
8.96468489e-01, -2.84669137e+00, 4.31550427e-01,
|
94 |
+
1.93543856e-01, -2.23790737e+00, -6.42987862e-01,
|
95 |
+
6.46948603e-02, 1.18711606e+00, -1.11801609e-01,
|
96 |
+
-1.05455472e+00, -8.00450431e-01, -1.24265267e-01,
|
97 |
+
-1.39086191e-01, -2.60693707e-01, 1.06000000e+02],
|
98 |
+
[ 2.32520000e+04, 1.29377595e+00, 3.69202958e-01,
|
99 |
+
3.09448258e-01, 6.29771401e-01, 8.24778408e-02,
|
100 |
+
-4.35559896e-01, 4.37783478e-02, -2.96998723e-01,
|
101 |
+
1.22423979e+00, -4.73446723e-01, 1.64211418e-01,
|
102 |
+
-1.84665003e+00, 3.17030274e+00, 1.41499690e+00,
|
103 |
+
2.40625127e-01, 4.69934516e-01, -5.57937991e-02,
|
104 |
+
-1.23218906e-01, -1.83562143e-02, -1.01346309e-02,
|
105 |
+
-4.41576748e-01, -1.00570303e+00, 1.84647505e-02,
|
106 |
+
-4.91389484e-01, 3.36660905e-01, 1.02774527e-01,
|
107 |
+
-5.27911412e-02, 9.04270816e-03, 1.69900000e+01],
|
108 |
+
[ 1.42659000e+05, 1.83404703e+00, -1.94875520e+00,
|
109 |
+
-1.78165816e+00, -1.56784758e+00, -1.00460825e+00,
|
110 |
+
-8.37986768e-01, -3.40342869e-01, -3.37935548e-01,
|
111 |
+
-1.96463717e+00, 1.72661800e+00, 6.57974945e-01,
|
112 |
+
-3.98308615e-01, 1.14503226e-01, 3.12088209e-01,
|
113 |
+
-4.79675451e-01, -3.73087478e-01, 1.73461298e-01,
|
114 |
+
1.71939285e-01, 1.69937838e-01, 5.18207228e-02,
|
115 |
+
-1.29125608e-01, -5.58702004e-01, 3.59553819e-02,
|
116 |
+
-4.36588035e-01, -2.80344803e-01, -3.32314616e-01,
|
117 |
+
-7.22218399e-02, -2.88505958e-02, 2.62000000e+02,]]
|
118 |
|
119 |
+
gr.Interface(infer, inputs, output, examples= examples, allow_flagging='never',
|
120 |
title=title, description=description, article=article, live=False).launch(enable_queue=True, debug=False)
|