Spaces:
Runtime error
Runtime error
luciancotolan
commited on
Commit
·
e47faa9
1
Parent(s):
fcfa690
added model and interface
Browse files- app.py +39 -0
- decision_tree.pkl +3 -0
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import joblib
|
4 |
+
|
5 |
+
model = joblib.load('decision_tree.pkl')
|
6 |
+
|
7 |
+
def onehot(df, column):
|
8 |
+
df = df.copy()
|
9 |
+
dummies = pd.get_dummies(df[column])
|
10 |
+
df = pd.concat([df,dummies], axis=1)
|
11 |
+
df = df.drop(column, axis=1)
|
12 |
+
return df
|
13 |
+
|
14 |
+
|
15 |
+
def dataframe(file_obj):
|
16 |
+
df = pd.read_csv(file_obj.name)
|
17 |
+
df = onehot(df, column='type')
|
18 |
+
df = df.drop(['nameOrig','nameDest','isFlaggedFraud'], axis=1)
|
19 |
+
print(df.shape)
|
20 |
+
y_pred = model.predict(df)
|
21 |
+
|
22 |
+
pred_df = pd.DataFrame(y_pred, columns = ['isFraud'])
|
23 |
+
print(type(pred_df))
|
24 |
+
print(pred_df.shape)
|
25 |
+
# clr = classification_report(y_test, y_pred, target_names=['Not Fraud','Fraud'])
|
26 |
+
# return 'Classification Report:\n'+ clr
|
27 |
+
return pred_df
|
28 |
+
|
29 |
+
file = gr.inputs.File(file_count="single", type="file", label="CSV File for Predictions", optional=False)
|
30 |
+
y_pred_df = gr.outputs.Dataframe(max_rows=20, max_cols=None, overflow_row_behaviour="paginate", type="auto", label="Predictions of records in the file")
|
31 |
+
interface_csv = gr.Interface(
|
32 |
+
fn=dataframe,
|
33 |
+
inputs=file,
|
34 |
+
outputs=y_pred_df,
|
35 |
+
title="Fraud Detection - EXPERT SYSTEM",
|
36 |
+
theme="dark-peach"
|
37 |
+
)
|
38 |
+
|
39 |
+
interface_csv.launch(share=True, inline=False)
|
decision_tree.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2aa27c6228c73b27dccb1837f7fb2ae30b92067c622ed936de6df219702e92f3
|
3 |
+
size 131544
|