deeploy-adubowski commited on
Commit
85b7407
·
1 Parent(s): 93f0de5

Fix eval request

Browse files
Files changed (3) hide show
  1. app.py +9 -9
  2. requirements.txt +1 -1
  3. utils.py +6 -4
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import streamlit as st
2
  import pandas as pd
3
  import logging
4
- from deeploy import Client
5
  from utils import (
6
  get_request_body,
7
  get_fake_certainty,
@@ -61,7 +61,7 @@ def get_input_no_button():
61
  st.session_state.no_button_text = comment.replace(
62
  st.session_state.no_button_text, st.session_state.no_comment
63
  )
64
- st.session_state.evaluation_input["explanation"] = st.session_state.no_button_text
65
 
66
 
67
  # func to be run when input changes in yes button text area
@@ -69,7 +69,7 @@ def get_input_yes_button():
69
  st.session_state.yes_button_text = comment.replace(
70
  st.session_state.yes_button_text, st.session_state.yes_comment
71
  )
72
- st.session_state.evaluation_input["explanation"] = st.session_state.yes_button_text
73
 
74
 
75
  # func to disable click again for button "Get suspicious transactions"
@@ -229,7 +229,7 @@ if st.session_state.got_explanation:
229
 
230
  if st.session_state.yes_button:
231
  st.session_state.eval_selected = True
232
- st.session_state.evaluation_input = {"result": 0} # Agree with the prediction
233
 
234
  # col 4 contains no button
235
  with col4:
@@ -248,8 +248,8 @@ if st.session_state.got_explanation:
248
  if st.session_state.no_button_clicked:
249
  st.session_state.eval_selected = True
250
  st.session_state.evaluation_input = {
251
- "result": 1, # Disagree with the prediction
252
- "value": {"predictions": [1]},
253
  }
254
 
255
  # define process for evaluation
@@ -271,7 +271,7 @@ if st.session_state.got_explanation:
271
  on_change=get_input_yes_button,
272
  )
273
  st.session_state.evaluation_input[
274
- "explanation"
275
  ] = st.session_state.yes_button_text
276
 
277
  # if disagree button clicked ("Not money laundering") prefill with text that user
@@ -284,7 +284,7 @@ if st.session_state.got_explanation:
284
  on_change=get_input_no_button,
285
  )
286
  st.session_state.evaluation_input[
287
- "explanation"
288
  ] = st.session_state.no_button_text
289
  # create empty state so that button submit disappears when st.empty is cleared
290
  eval3 = st.empty()
@@ -315,6 +315,6 @@ if st.session_state.got_explanation:
315
  eval1.empty()
316
  eval2.empty()
317
  eval3.empty()
318
- st.warning("Feedback submitted successfully")
319
  st.button("Next", key="next", use_container_width=True, on_click=rerun)
320
  ChangeButtonColour("Next", "#FFFFFF", "#00052D")
 
1
  import streamlit as st
2
  import pandas as pd
3
  import logging
4
+ from deeploy import Client, CreateEvaluation
5
  from utils import (
6
  get_request_body,
7
  get_fake_certainty,
 
61
  st.session_state.no_button_text = comment.replace(
62
  st.session_state.no_button_text, st.session_state.no_comment
63
  )
64
+ st.session_state.evaluation_input["comment"] = st.session_state.no_button_text
65
 
66
 
67
  # func to be run when input changes in yes button text area
 
69
  st.session_state.yes_button_text = comment.replace(
70
  st.session_state.yes_button_text, st.session_state.yes_comment
71
  )
72
+ st.session_state.evaluation_input["comment"] = st.session_state.yes_button_text
73
 
74
 
75
  # func to disable click again for button "Get suspicious transactions"
 
229
 
230
  if st.session_state.yes_button:
231
  st.session_state.eval_selected = True
232
+ st.session_state.evaluation_input = {"agree": True} # Agree with the prediction
233
 
234
  # col 4 contains no button
235
  with col4:
 
248
  if st.session_state.no_button_clicked:
249
  st.session_state.eval_selected = True
250
  st.session_state.evaluation_input = {
251
+ "agree": False, # Disagree with the prediction
252
+ "desired_output": {"predictions": [1]},
253
  }
254
 
255
  # define process for evaluation
 
271
  on_change=get_input_yes_button,
272
  )
273
  st.session_state.evaluation_input[
274
+ "comment"
275
  ] = st.session_state.yes_button_text
276
 
277
  # if disagree button clicked ("Not money laundering") prefill with text that user
 
284
  on_change=get_input_no_button,
285
  )
286
  st.session_state.evaluation_input[
287
+ "comment"
288
  ] = st.session_state.no_button_text
289
  # create empty state so that button submit disappears when st.empty is cleared
290
  eval3 = st.empty()
 
315
  eval1.empty()
316
  eval2.empty()
317
  eval3.empty()
318
+ st.success("Feedback submitted successfully")
319
  st.button("Next", key="next", use_container_width=True, on_click=rerun)
320
  ChangeButtonColour("Next", "#FFFFFF", "#00052D")
requirements.txt CHANGED
@@ -1,6 +1,6 @@
1
  boto3==1.28.0
2
  streamlit==1.31
3
  watchdog==3.0.0
4
- deeploy==1.2.1
5
  pandas>=1.3.5
6
  babel
 
1
  boto3==1.28.0
2
  streamlit==1.31
3
  watchdog==3.0.0
4
+ deeploy==1.39.0
5
  pandas>=1.3.5
6
  babel
utils.py CHANGED
@@ -78,7 +78,7 @@ def get_request_body(datapoint):
78
 
79
  # func for sorting and retrieving the explanation texts
80
  def get_explainability_texts(shap_values, feature_texts):
81
- # Separate positive and negative values, keep indice as corresponds to key
82
  positive_dict = {index: val for index, val in enumerate(shap_values) if val > 0}
83
  # Sort dictionaries based on the magnitude of values
84
  sorted_positive_indices = [
@@ -167,10 +167,10 @@ def get_random_suspicious_transaction(data):
167
  suspicious_data = data[data["isFraud"] == 1]
168
  max_n = len(suspicious_data)
169
  random_nr = randrange(max_n)
170
- suspicous_transaction = suspicious_data[random_nr - 1 : random_nr].drop(
171
  "isFraud", axis=1
172
  )
173
- return suspicous_transaction
174
 
175
 
176
  # func to send the evaluation to Deeploy
@@ -182,7 +182,9 @@ def send_evaluation(
182
  with st.spinner("Submitting response..."):
183
  # Call the explain endpoint as it also includes the prediction
184
  client.evaluate(
185
- deployment_id, request_log_id, prediction_log_id, evaluation_input
 
 
186
  )
187
  return True
188
  except Exception as e:
 
78
 
79
  # func for sorting and retrieving the explanation texts
80
  def get_explainability_texts(shap_values, feature_texts):
81
+ # Separate positive and negative values, keep indices corresponding to keys
82
  positive_dict = {index: val for index, val in enumerate(shap_values) if val > 0}
83
  # Sort dictionaries based on the magnitude of values
84
  sorted_positive_indices = [
 
167
  suspicious_data = data[data["isFraud"] == 1]
168
  max_n = len(suspicious_data)
169
  random_nr = randrange(max_n)
170
+ suspicious_transaction = suspicious_data[random_nr - 1 : random_nr].drop(
171
  "isFraud", axis=1
172
  )
173
+ return suspicious_transaction
174
 
175
 
176
  # func to send the evaluation to Deeploy
 
182
  with st.spinner("Submitting response..."):
183
  # Call the explain endpoint as it also includes the prediction
184
  client.evaluate(
185
+ deployment_id,
186
+ prediction_log_id,
187
+ evaluation_input
188
  )
189
  return True
190
  except Exception as e: