luciancotolan commited on
Commit
336ac28
·
1 Parent(s): 1e27e4a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -19
app.py CHANGED
@@ -1,9 +1,10 @@
1
  import gradio as gr
2
  import pandas as pd
3
  import pickle
 
4
 
5
  treemodel = pickle.load(open('decision_tree.pkl', 'rb'))
6
- #nnmodel = pickle.load(open('neural_network.pkl', 'rb'))
7
 
8
  def onehot(df, column):
9
  df = df.copy()
@@ -45,15 +46,15 @@ def tree(file_obj):
45
  pred_df = pd.concat([df_original, pred_df], axis=1)
46
  return pred_df
47
 
48
- #def nn(file_obj):
49
- # nn_df = pd.read_csv(file_obj.name)
50
- # nn_df = dataframe(nn_df)
51
- # y_prednn = nnmodel.predict(nn_df)
52
- # pred_dfnn = pd.DataFrame(y_prednn, columns = ['predictedFraud'])
53
- # #append the predictions to the original dataframe
54
- # df_originalnn = pd.read_csv(file_obj.name)
55
- # pred_dfnn = pd.concat([df_originalnn, pred_dfnn], axis=1)
56
- # return pred_dfnn
57
 
58
  file = gr.components.File(file_count="single", type="file", label="Fisierul CSV cu tranzactii", optional=False)
59
  tree_output = gr.components.Dataframe(max_rows=20, max_cols=None, overflow_row_behaviour="paginate", type="pandas", label="predictedFraud - Predictii bazate pe modelul de clasificare isFraud - Etichetele reale")
@@ -66,12 +67,13 @@ tree_interface = gr.Interface(
66
  description='<h2>Sistem expert bazat pe un model de clasificare pentru detectarea fraudelor in tranzactii bancare.<h2><h3>predictedFraud - Predictii bazate pe modelul de clasificare. isFraud - Etichetele reale<h3>'
67
  )
68
 
69
- #nn_interface = gr.Interface(
70
- # fn=nn,
71
- # inputs=file,
72
- # outputs=nn_output,
73
- # title="Fraud Detection - NEURAL NETWORK EXPERT SYSTEM",
74
- # description='<h2>Sistem expert bazat pe un model de clasificare pentru detectarea fraudelor in tranzactii bancare.<h2><h3>predictedFraud - Predictii bazate pe modelul de clasificare. isFraud - Etichetele reale<h3>'
75
- # )
76
- tree_interface.launch(inline=True)
77
- #gr.Parallel(tree_interface, nn_interface).launch()
 
 
1
  import gradio as gr
2
  import pandas as pd
3
  import pickle
4
+ from tensorflow import keras
5
 
6
  treemodel = pickle.load(open('decision_tree.pkl', 'rb'))
7
+ nnmodel = keras.models.load_model("nnmodel.h5")
8
 
9
  def onehot(df, column):
10
  df = df.copy()
 
46
  pred_df = pd.concat([df_original, pred_df], axis=1)
47
  return pred_df
48
 
49
+ def nn(file_obj):
50
+ nn_df = pd.read_csv(file_obj.name)
51
+ nn_df = dataframe(nn_df)
52
+ y_prednn = nnmodel.predict(nn_df)
53
+ pred_dfnn = pd.DataFrame(y_prednn, columns = ['predictedFraud'])
54
+ #append the predictions to the original dataframe
55
+ df_originalnn = pd.read_csv(file_obj.name)
56
+ pred_dfnn = pd.concat([df_originalnn, pred_dfnn], axis=1)
57
+ return pred_dfnn
58
 
59
  file = gr.components.File(file_count="single", type="file", label="Fisierul CSV cu tranzactii", optional=False)
60
  tree_output = gr.components.Dataframe(max_rows=20, max_cols=None, overflow_row_behaviour="paginate", type="pandas", label="predictedFraud - Predictii bazate pe modelul de clasificare isFraud - Etichetele reale")
 
67
  description='<h2>Sistem expert bazat pe un model de clasificare pentru detectarea fraudelor in tranzactii bancare.<h2><h3>predictedFraud - Predictii bazate pe modelul de clasificare. isFraud - Etichetele reale<h3>'
68
  )
69
 
70
+ nn_interface = gr.Interface(
71
+ fn=nn,
72
+ inputs=file,
73
+ outputs=nn_output,
74
+ title="Fraud Detection - NEURAL NETWORK EXPERT SYSTEM",
75
+ description='<h2>Sistem expert bazat pe un model de clasificare pentru detectarea fraudelor in tranzactii bancare.<h2><h3>predictedFraud - Predictii bazate pe modelul de clasificare. isFraud - Etichetele reale<h3>'
76
+
77
+ )
78
+ #tree_interface.launch(inline=True)
79
+ gr.Parallel(tree_interface, nn_interface).launch()