Joao Henrique
commited on
Commit
·
9943c93
1
Parent(s):
8aaf1c4
less
Browse files- app.py +57 -0
- gears.py +22 -0
- tensor1.pt +3 -0
- tensor2.pt +3 -0
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gears import load_tensor, calc_preds
|
3 |
+
|
4 |
+
coeffs = load_tensor()
|
5 |
+
|
6 |
+
examples = [
|
7 |
+
"""
|
8 |
+
-0.260648; -0.469648; 2.496266; -0.083724; 0.129681; 0.732898; 0.519014; -0.130006; 0.727159;
|
9 |
+
0.637735; -0.987020; 0.293438; -0.941386; 0.549020; 1.804879; 0.215598; 0.512307; 0.333644;
|
10 |
+
0.124270; 0.091202; -0.110552; 0.217606; -0.134794; 0.165959; 0.126280; -0.434824; -0.081230; -0.151045;
|
11 |
+
17982.1;
|
12 |
+
""",
|
13 |
+
|
14 |
+
"""
|
15 |
+
0.985100; -0.356045; 0.558056; -0.429654; 0.277140; 0.428605; 0.406466; -0.133118; 0.347452; 0.529808;
|
16 |
+
0.140107; 1.564246; 0.574074; 0.627719; 0.706121; 0.789188; 0.403810; 0.201799; -0.340687; -0.233984;
|
17 |
+
-0.194936; -0.605761; 0.079469; -0.577395; 0.190090; 0.296503; -0.248052; -0.064512;
|
18 |
+
6531.370000;
|
19 |
+
""",
|
20 |
+
|
21 |
+
"""
|
22 |
+
-0.478427; 0.142165; -0.046838; 0.683350; 0.067820; -0.404898; -0.206496; 0.184366; -0.762935; -0.228392; 0.660903;
|
23 |
+
-0.387520; -0.533249; -0.502266; 0.405143; -0.060691; -0.207237; 0.305603; 0.134876; -0.033921; 0.098977; -0.075191;
|
24 |
+
-0.481489; 0.678900; -0.011520; 0.409021; 0.075859; -0.447139;
|
25 |
+
1534.530000;
|
26 |
+
""",
|
27 |
+
|
28 |
+
"""
|
29 |
+
-0.617111; -1.733888; 1.150655; 0.207829; 0.903533; -0.171524; 0.551679; -0.167744; 0.338861; 0.291418; -0.884790;
|
30 |
+
0.344854; 0.763902; 0.068704; 2.560478; 0.955467; 0.663089; 1.897704; 0.024869; 1.841243; 0.153856; 0.369734; 1.471004;
|
31 |
+
-0.497633; 0.377656; -0.328051; -0.512415; -0.013653;
|
32 |
+
10554.680000;
|
33 |
+
"""
|
34 |
+
]
|
35 |
+
|
36 |
+
ans_examples = [0,0,1,1]
|
37 |
+
|
38 |
+
# 0, 1, 541, 623
|
39 |
+
|
40 |
+
def predict(indeps="0;0"):
|
41 |
+
indeps = list(map(float,indeps.split(';')))
|
42 |
+
|
43 |
+
fraud = calc_preds(coeffs, indeps)
|
44 |
+
|
45 |
+
if fraud >= 0.5:
|
46 |
+
return "Fraud"
|
47 |
+
|
48 |
+
return "Not fraud"
|
49 |
+
|
50 |
+
gr.Interface(
|
51 |
+
fn=predict,
|
52 |
+
inputs=gr.components.TextBox,
|
53 |
+
outputs=gr.components.Textbox,
|
54 |
+
examples=examples
|
55 |
+
).launch(share=False)
|
56 |
+
|
57 |
+
|
gears.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torch.nn.functional as F
|
3 |
+
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
|
7 |
+
def load_tensor():
|
8 |
+
coeffs = [None,None]
|
9 |
+
coeffs[0] = torch.load('tensor1.pt')
|
10 |
+
coeffs[1] = torch.load('tensor2.pt')
|
11 |
+
return coeffs
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
def calc_preds(coeffs, indeps):
|
16 |
+
layers,consts = coeffs
|
17 |
+
n = len(layers)
|
18 |
+
res = indeps
|
19 |
+
for i,l in enumerate(layers):
|
20 |
+
res = res@l + consts[i]
|
21 |
+
if i!=n-1: res = F.relu(res)
|
22 |
+
return torch.sigmoid(res)
|
tensor1.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:359cef2b080012664b03ab0e9931e2cc83993c57f167a66e8b319bc7bf860b71
|
3 |
+
size 2787
|
tensor2.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7cfa74c8d172743343ae607314a41a6c629e358604bc61995b6a7f9cfe62bafa
|
3 |
+
size 2787
|