Othniel74 commited on
Commit
475a89a
·
verified ·
1 Parent(s): 406c813

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -4
app.py CHANGED
@@ -4,10 +4,19 @@ import json
4
  import plotly
5
 
6
  def predict_fraud(selected_model, selected_interpretability_method, step, transaction_type, amount, oldbalanceOrg):
7
- # Validation check for all fields
8
-
9
- if not all([selected_model, selected_interpretability_method, step, transaction_type, amount, oldbalanceOrg]):
10
- return "All fields are required. Please ensure no fields are left empty."
 
 
 
 
 
 
 
 
 
11
 
12
  url = "https://sea-lion-app-5kxay.ondigitalocean.app/predict_and_explain"
13
  data = {
@@ -63,6 +72,7 @@ def predict_fraud(selected_model, selected_interpretability_method, step, transa
63
  with gr.Blocks() as app:
64
  gr.Markdown("<h2 style='text-align: center; font-weight: bold;'>FraudSenseXAI - Advanced Fraud Detection</h2>")
65
  gr.Markdown("<p style='text-align: center;'>Predict and analyze fraudulent transactions.</p>", elem_id="description")
 
66
 
67
 
68
  with gr.Row():
@@ -102,6 +112,17 @@ with gr.Blocks() as app:
102
  bar_chart = gr.Plot(label="Bar Chart")
103
  narrative = gr.Textbox(label="Narrative")
104
 
 
 
 
 
 
 
 
 
 
 
 
105
  submit_btn.click(
106
  predict_fraud,
107
  inputs=[model_selection, interpretability_selection, step, transaction_type, transaction_amount, old_balance_org],
 
4
  import plotly
5
 
6
  def predict_fraud(selected_model, selected_interpretability_method, step, transaction_type, amount, oldbalanceOrg):
7
+ # Validation checks
8
+ if not selected_model:
9
+ return "Model Selection is required.", None, None, None, None, None, None, None, None, None, None
10
+ if not selected_interpretability_method:
11
+ return "Interpretability Technique is required.", None, None, None, None, None, None, None, None, None, None
12
+ if step == 0: # Assuming step is a numerical value, check for None explicitly
13
+ return "Step (Transaction Time) is required.", None, None, None, None, None, None, None, None, None, None
14
+ if not transaction_type:
15
+ return "Transaction Type is required.", None, None, None, None, None, None, None, None, None, None
16
+ if amount == 0: # Assuming amount is a numerical value, check for None explicitly
17
+ return "Transaction Amount is required.", None, None, None, None, None, None, None, None, None, None
18
+ if oldbalanceOrg is None: # Assuming oldbalanceOrg is a numerical value, check for None explicitly
19
+ return "Old Balance Org is required.", None, None, None, None, None, None, None, None, None, None
20
 
21
  url = "https://sea-lion-app-5kxay.ondigitalocean.app/predict_and_explain"
22
  data = {
 
72
  with gr.Blocks() as app:
73
  gr.Markdown("<h2 style='text-align: center; font-weight: bold;'>FraudSenseXAI - Advanced Fraud Detection</h2>")
74
  gr.Markdown("<p style='text-align: center;'>Predict and analyze fraudulent transactions.</p>", elem_id="description")
75
+ error_message = gr.Textbox(label="Error Message", visible=False, lines=2, interactive=False)
76
 
77
 
78
  with gr.Row():
 
112
  bar_chart = gr.Plot(label="Bar Chart")
113
  narrative = gr.Textbox(label="Narrative")
114
 
115
+
116
+ def update_error_message(error_text, *rest):
117
+ if error_text and not error_text.startswith("Error: "):
118
+ error_message.update(value=error_text, visible=True)
119
+ return (None,) * len(rest) # Update to match the number of outputs minus the error message
120
+ else:
121
+ error_message.update(visible=False)
122
+ return (error_text,) + rest
123
+
124
+
125
+
126
  submit_btn.click(
127
  predict_fraud,
128
  inputs=[model_selection, interpretability_selection, step, transaction_type, transaction_amount, old_balance_org],