Spaces:
Running
Running
deeploy-adubowski
commited on
Commit
β’
7995f88
1
Parent(s):
6ceb1f0
Show prediction after evaluation
Browse files
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.
|
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 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
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 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|