Spaces:
Running
Running
deeploy-adubowski
commited on
Commit
•
9dfefb7
1
Parent(s):
01cc876
Hide submit button and comment box after submission
Browse files
app.py
CHANGED
@@ -42,7 +42,7 @@ def send_evaluation(
|
|
42 |
):
|
43 |
"""Send evaluation to Deeploy."""
|
44 |
try:
|
45 |
-
with st.spinner("Submitting
|
46 |
# Call the explain endpoint as it also includes the prediction
|
47 |
client.evaluate(
|
48 |
deployment_id, request_log_id, prediction_log_id, evaluation_input
|
@@ -52,7 +52,7 @@ def send_evaluation(
|
|
52 |
logging.error(e)
|
53 |
st.error(
|
54 |
"Failed to submit feedback."
|
55 |
-
+ "Check whether you are using the right model URL and
|
56 |
+ "Contact Deeploy if the problem persists."
|
57 |
)
|
58 |
st.write(f"Error message: {e}")
|
@@ -144,10 +144,10 @@ with st.expander("Application form", expanded=False):
|
|
144 |
"Working hours per week", min_value=0, max_value=100, value=40
|
145 |
)
|
146 |
capital_gain = st.number_input(
|
147 |
-
"Yearly income", min_value=0, max_value=1000000, value=70000
|
148 |
)
|
149 |
capital_loss = st.number_input(
|
150 |
-
"Yearly expenditures", min_value=0, max_value=1000000, value=60000
|
151 |
)
|
152 |
data_df = pd.DataFrame(
|
153 |
[
|
@@ -207,8 +207,9 @@ if deployment_token != "my-secret-token":
|
|
207 |
|
208 |
if st.session_state.selected == "Loan Decision":
|
209 |
# If no prediction, show "loading..."
|
|
|
210 |
try:
|
211 |
-
with st.spinner("Loading..."):
|
212 |
# Call the explain endpoint as it also includes the prediction
|
213 |
exp = client.explain(
|
214 |
request_body=request_body, deployment_id=deployment_id
|
@@ -361,13 +362,13 @@ if st.session_state.selected == "Loan Decision":
|
|
361 |
)
|
362 |
ChangeButtonColour("No, I disagree", "white", "#DD360C")
|
363 |
# ChangeButtonColour("No, I disagree", "#DD360C", "#F0F0F0")
|
364 |
-
|
365 |
-
st.session_state["eval_selected"] = False
|
366 |
if yes_button:
|
367 |
st.session_state.eval_selected = True
|
368 |
st.session_state.evaluation_input = {
|
369 |
"result": 0 # Agree with the prediction
|
370 |
}
|
|
|
371 |
if no_button:
|
372 |
st.session_state.eval_selected = True
|
373 |
desired_output = not predictions[0]
|
@@ -375,29 +376,46 @@ if st.session_state.selected == "Loan Decision":
|
|
375 |
"result": 1, # Disagree with the prediction
|
376 |
"value": {"predictions": [desired_output]},
|
377 |
}
|
|
|
378 |
|
379 |
-
success
|
|
|
380 |
if st.session_state.eval_selected:
|
381 |
-
comment = st.text_input("Would you like to add a comment?")
|
382 |
if comment:
|
383 |
st.session_state.evaluation_input["explanation"] = comment
|
384 |
logging.debug(
|
385 |
"Selected feedback:" + str(st.session_state.evaluation_input)
|
386 |
)
|
387 |
-
|
388 |
-
|
389 |
-
st.
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
401 |
st.success("Feedback submitted successfully.")
|
402 |
|
403 |
except Exception as e:
|
|
|
42 |
):
|
43 |
"""Send evaluation to Deeploy."""
|
44 |
try:
|
45 |
+
with st.spinner("Submitting evaluation..."):
|
46 |
# Call the explain endpoint as it also includes the prediction
|
47 |
client.evaluate(
|
48 |
deployment_id, request_log_id, prediction_log_id, evaluation_input
|
|
|
52 |
logging.error(e)
|
53 |
st.error(
|
54 |
"Failed to submit feedback."
|
55 |
+
+ "Check whether you are using the right model URL and token for evaluations. "
|
56 |
+ "Contact Deeploy if the problem persists."
|
57 |
)
|
58 |
st.write(f"Error message: {e}")
|
|
|
144 |
"Working hours per week", min_value=0, max_value=100, value=40
|
145 |
)
|
146 |
capital_gain = st.number_input(
|
147 |
+
"Yearly income [€]", min_value=0, max_value=1000000, value=70000
|
148 |
)
|
149 |
capital_loss = st.number_input(
|
150 |
+
"Yearly expenditures [€]", min_value=0, max_value=1000000, value=60000
|
151 |
)
|
152 |
data_df = pd.DataFrame(
|
153 |
[
|
|
|
207 |
|
208 |
if st.session_state.selected == "Loan Decision":
|
209 |
# If no prediction, show "loading..."
|
210 |
+
# FIXME: Cleanup session state so that it's not sending a request to the explain endpoint each time
|
211 |
try:
|
212 |
+
with st.spinner("Loading prediction and explanation..."):
|
213 |
# Call the explain endpoint as it also includes the prediction
|
214 |
exp = client.explain(
|
215 |
request_body=request_body, deployment_id=deployment_id
|
|
|
362 |
)
|
363 |
ChangeButtonColour("No, I disagree", "white", "#DD360C")
|
364 |
# ChangeButtonColour("No, I disagree", "#DD360C", "#F0F0F0")
|
365 |
+
st.session_state["eval_selected"] = False
|
|
|
366 |
if yes_button:
|
367 |
st.session_state.eval_selected = True
|
368 |
st.session_state.evaluation_input = {
|
369 |
"result": 0 # Agree with the prediction
|
370 |
}
|
371 |
+
placeholder = "Income is sufficient, given applicant's background"
|
372 |
if no_button:
|
373 |
st.session_state.eval_selected = True
|
374 |
desired_output = not predictions[0]
|
|
|
376 |
"result": 1, # Disagree with the prediction
|
377 |
"value": {"predictions": [desired_output]},
|
378 |
}
|
379 |
+
placeholder = "Income is too low, given applicant's background"
|
380 |
|
381 |
+
if 'success' not in st.session_state:
|
382 |
+
st.session_state['success'] = False
|
383 |
if st.session_state.eval_selected:
|
384 |
+
comment = st.text_input("Would you like to add a comment?", placeholder=placeholder)
|
385 |
if comment:
|
386 |
st.session_state.evaluation_input["explanation"] = comment
|
387 |
logging.debug(
|
388 |
"Selected feedback:" + str(st.session_state.evaluation_input)
|
389 |
)
|
390 |
+
success = True
|
391 |
+
print(success)
|
392 |
+
if st.button("Submit", key="submit_button"):
|
393 |
+
with st.spinner("Submitting evaluation..."):
|
394 |
+
try:
|
395 |
+
# Call the explain endpoint as it also includes the prediction
|
396 |
+
client.evaluate(
|
397 |
+
deployment_id, request_log_id, prediction_log_id, evaluation_input
|
398 |
+
)
|
399 |
+
except Exception as e:
|
400 |
+
success = False
|
401 |
+
logging.error(e)
|
402 |
+
st.error(
|
403 |
+
"Failed to submit feedback."
|
404 |
+
+ "Check whether you are using the right model URL and token for evaluations. "
|
405 |
+
+ "Contact Deeploy if the problem persists."
|
406 |
+
)
|
407 |
+
st.write(f"Error message: {e}")
|
408 |
+
print(success)
|
409 |
+
if success:
|
410 |
+
st.session_state.success = True
|
411 |
+
else:
|
412 |
+
st.error("Evaluation failed. Check whether your token allows for evaluations.")
|
413 |
+
# st.session_state.eval_selected = False
|
414 |
+
# yes_button = False
|
415 |
+
# no_button = False
|
416 |
+
# print(st.session_state.success)
|
417 |
+
# print(st.session_state.success)
|
418 |
+
if st.session_state.success:
|
419 |
st.success("Feedback submitted successfully.")
|
420 |
|
421 |
except Exception as e:
|