deeploy-adubowski commited on
Commit
7995f88
β€’
1 Parent(s): 6ceb1f0

Show prediction after evaluation

Browse files
Files changed (1) hide show
  1. app.py +56 -50
app.py CHANGED
@@ -95,6 +95,8 @@ with st.sidebar:
95
  if "expander_toggle" not in st.session_state:
96
  st.session_state.expander_toggle = True
97
 
 
 
98
 
99
  def submit_and_clear():
100
  try:
@@ -104,9 +106,8 @@ def submit_and_clear():
104
  )
105
  st.toast(":green[Feedback submitted successfully.]", icon="βœ…")
106
  st.session_state.eval_selected = False
107
- st.session_state.predict_button_clicked = False
108
  st.session_state.eval_selected = False
109
- show_expander()
110
  except Exception as e:
111
  logging.error(e)
112
  st.error(
@@ -203,12 +204,14 @@ with st.expander("Application form", expanded=st.session_state.expander_toggle):
203
  }
204
  if "predict_button_clicked" not in st.session_state:
205
  st.session_state.predict_button_clicked = False
 
206
  if deployment_token != "my-secret-token":
207
  predict_button = st.button(
208
  "Send loan application", key="predict_button", help="Click to get the AI prediction.", on_click=hide_expander
209
  )
210
  if predict_button:
211
  st.session_state.predict_button_clicked = True
 
212
  # st.session_state.selected = "Loan Decision"
213
  with st.spinner("Loading prediction and explanation..."):
214
  # Call the explain endpoint as it also includes the prediction
@@ -342,55 +345,58 @@ if st.session_state.predict_button_clicked:
342
  )
343
 
344
  st.divider()
345
-
346
- # Add prediction evaluation
347
- st.subheader("Evaluation: Do you agree with the predicted creditworthiness?")
348
- st.info(
349
- "AI model predictions always come with a certain level of uncertainty. \nEvaluate the correctness of the prediction based on your expertise and experience."
350
- )
351
- cols = st.columns(4)
352
- col_yes, col_no = cols[:2]
353
- with col_yes:
354
- yes_button = st.button(
355
- "Yes, I agree",
356
- key="yes_button",
357
- use_container_width=True,
358
- help="Click if you agree with the prediction",
359
- )
360
- ChangeButtonColour("Yes, I agree", "white", "green")
361
- with col_no:
362
- no_button = st.button(
363
- "No, I disagree",
364
- key="no_button",
365
- use_container_width=True,
366
- help="Click if you disagree with the prediction",
367
- type="primary",
368
  )
369
- ChangeButtonColour("No, I disagree", "white", "#DD360C")
370
- # ChangeButtonColour("No, I disagree", "#DD360C", "#F0F0F0")
371
- if "eval_selected" not in st.session_state:
372
- st.session_state["eval_selected"] = False
373
- if yes_button:
374
- st.session_state.eval_selected = True
375
- st.session_state.evaluation_input = {
376
- "result": 0 # Agree with the prediction
377
- }
378
- st.session_state.placeholder = "Income is sufficient, given applicant's background"
379
- if no_button:
380
- st.session_state.eval_selected = True
381
- desired_output = not predictions[0]
382
- st.session_state.evaluation_input = {
383
- "result": 1, # Disagree with the prediction
384
- "value": {"predictions": [desired_output]},
385
- }
386
- st.session_state.placeholder = "Income is too low, given applicant's background"
387
-
388
- if st.session_state.eval_selected:
389
- comment = st.text_input("Would you like to add a comment?", placeholder=st.session_state.placeholder)
390
- if comment:
391
- st.session_state.evaluation_input["explanation"] = comment
392
-
393
- st.button("Submit", key="submit_button", on_click=submit_and_clear)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
394
 
395
  except Exception as e:
396
  logging.error(e)
 
95
  if "expander_toggle" not in st.session_state:
96
  st.session_state.expander_toggle = True
97
 
98
+ if "evaluation_submitted" not in st.session_state:
99
+ st.session_state.evaluation_submitted = False
100
 
101
  def submit_and_clear():
102
  try:
 
106
  )
107
  st.toast(":green[Feedback submitted successfully.]", icon="βœ…")
108
  st.session_state.eval_selected = False
109
+ st.session_state.evaluation_submitted = True
110
  st.session_state.eval_selected = False
 
111
  except Exception as e:
112
  logging.error(e)
113
  st.error(
 
204
  }
205
  if "predict_button_clicked" not in st.session_state:
206
  st.session_state.predict_button_clicked = False
207
+
208
  if deployment_token != "my-secret-token":
209
  predict_button = st.button(
210
  "Send loan application", key="predict_button", help="Click to get the AI prediction.", on_click=hide_expander
211
  )
212
  if predict_button:
213
  st.session_state.predict_button_clicked = True
214
+ st.session_state.evaluation_submitted = False
215
  # st.session_state.selected = "Loan Decision"
216
  with st.spinner("Loading prediction and explanation..."):
217
  # Call the explain endpoint as it also includes the prediction
 
345
  )
346
 
347
  st.divider()
348
+
349
+ if not st.session_state.evaluation_submitted:
350
+ # Add prediction evaluation
351
+ st.subheader("Evaluation: Do you agree with the predicted creditworthiness?")
352
+ st.info(
353
+ "AI model predictions always come with a certain level of uncertainty. \nEvaluate the correctness of the prediction based on your expertise and experience."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
354
  )
355
+ cols = st.columns(4)
356
+ col_yes, col_no = cols[:2]
357
+ with col_yes:
358
+ yes_button = st.button(
359
+ "Yes, I agree",
360
+ key="yes_button",
361
+ use_container_width=True,
362
+ help="Click if you agree with the prediction",
363
+ )
364
+ ChangeButtonColour("Yes, I agree", "white", "green")
365
+ with col_no:
366
+ no_button = st.button(
367
+ "No, I disagree",
368
+ key="no_button",
369
+ use_container_width=True,
370
+ help="Click if you disagree with the prediction",
371
+ type="primary",
372
+ )
373
+ ChangeButtonColour("No, I disagree", "white", "#DD360C")
374
+ # ChangeButtonColour("No, I disagree", "#DD360C", "#F0F0F0")
375
+ if "eval_selected" not in st.session_state:
376
+ st.session_state["eval_selected"] = False
377
+ if yes_button:
378
+ st.session_state.eval_selected = True
379
+ st.session_state.evaluation_input = {
380
+ "result": 0 # Agree with the prediction
381
+ }
382
+ st.session_state.placeholder = "Income is sufficient, given applicant's background"
383
+ if no_button:
384
+ st.session_state.eval_selected = True
385
+ desired_output = not predictions[0]
386
+ st.session_state.evaluation_input = {
387
+ "result": 1, # Disagree with the prediction
388
+ "value": {"predictions": [desired_output]},
389
+ }
390
+ st.session_state.placeholder = "Income is too low, given applicant's background"
391
+
392
+ if st.session_state.eval_selected:
393
+ comment = st.text_input("Would you like to add a comment?", placeholder=st.session_state.placeholder)
394
+ if comment:
395
+ st.session_state.evaluation_input["explanation"] = comment
396
+
397
+ st.button("Submit", key="submit_button", on_click=submit_and_clear)
398
+ else:
399
+ st.write("Loan application already evaluated - send another loan application to evaluate again.")
400
 
401
  except Exception as e:
402
  logging.error(e)