Spaces:
Sleeping
Sleeping
Commit
·
e38052c
1
Parent(s):
e28a7df
Cleanup template
Browse files
app.py
CHANGED
@@ -62,11 +62,12 @@ def ChangeButtonColour(widget_label, font_color, background_color="transparent")
|
|
62 |
"""
|
63 |
components.html(f"{htmlstr}", height=0, width=0)
|
64 |
|
65 |
-
def
|
66 |
-
with st.spinner("Loading prediction
|
67 |
try:
|
|
|
68 |
# Call the explain endpoint as it also includes the prediction
|
69 |
-
|
70 |
request_body=request_body, deployment_id=deployment_id
|
71 |
)
|
72 |
except Exception as e:
|
@@ -77,22 +78,18 @@ def predict():
|
|
77 |
+ "Contact Deeploy if the problem persists."
|
78 |
)
|
79 |
return
|
80 |
-
st.session_state.
|
81 |
st.session_state.evaluation_submitted = False
|
82 |
-
hide_expander()
|
83 |
|
84 |
-
def hide_expander():
|
85 |
-
st.session_state.expander_toggle = False
|
86 |
-
|
87 |
-
def show_expander():
|
88 |
-
st.session_state.expander_toggle = True
|
89 |
|
90 |
def submit_and_clear(evaluation: str):
|
91 |
if evaluation == "yes":
|
92 |
st.session_state.evaluation_input["result"] = 0 # Agree with the prediction
|
93 |
else:
|
94 |
-
|
95 |
st.session_state.evaluation_input["result"] = 1
|
|
|
|
|
96 |
st.session_state.evaluation_input["value"] = {"predictions": [desired_output]}
|
97 |
try:
|
98 |
# Call the explain endpoint as it also includes the prediction
|
@@ -100,8 +97,7 @@ def submit_and_clear(evaluation: str):
|
|
100 |
deployment_id, request_log_id, prediction_log_id, st.session_state.evaluation_input
|
101 |
)
|
102 |
st.session_state.evaluation_submitted = True
|
103 |
-
st.session_state.
|
104 |
-
show_expander()
|
105 |
except Exception as e:
|
106 |
logging.error(e)
|
107 |
st.error(
|
@@ -112,11 +108,8 @@ def submit_and_clear(evaluation: str):
|
|
112 |
|
113 |
|
114 |
# Define defaults for the session state
|
115 |
-
if "
|
116 |
-
st.session_state.
|
117 |
-
|
118 |
-
if "exp" not in st.session_state:
|
119 |
-
st.session_state.exp = None
|
120 |
|
121 |
if "evaluation_submitted" not in st.session_state:
|
122 |
st.session_state.evaluation_submitted = False
|
@@ -149,7 +142,7 @@ with st.sidebar:
|
|
149 |
# st.write(st.session_state)
|
150 |
|
151 |
# Input (for IRIS dataset)
|
152 |
-
with st.expander("Input values for prediction", expanded=
|
153 |
st.write("Please input the values for the model.")
|
154 |
col1, col2 = st.columns(2)
|
155 |
with col1:
|
@@ -171,33 +164,6 @@ request_body = {
|
|
171 |
}
|
172 |
|
173 |
# Predict and explain
|
174 |
-
predict_button = st.button("Predict", on_click=
|
175 |
-
if st.session_state.
|
176 |
-
st.write(st.session_state.
|
177 |
-
# predictions = st.session_state.exp["predictions"]
|
178 |
-
# request_log_id = exp["requestLogId"]
|
179 |
-
# prediction_log_id = exp["predictionLogIds"][0]
|
180 |
-
|
181 |
-
# # exp_df = pd.DataFrame(
|
182 |
-
# # [exp["explanations"][0]["shap_values"]], columns=exp["featureLabels"]
|
183 |
-
# # )
|
184 |
-
# st.write("Predictions:", predictions)
|
185 |
-
|
186 |
-
# # Evaluation
|
187 |
-
# if st.session_state.evaluation_submitted is False:
|
188 |
-
# evaluation = st.radio("Do you agree with the prediction?", ("yes", "no"))
|
189 |
-
# if evaluation == "no":
|
190 |
-
# desired_output = # TODO
|
191 |
-
# st.session_state.evaluation_input = {
|
192 |
-
# "result": 1,
|
193 |
-
# "value": {"predictions": [desired_output]},
|
194 |
-
# }
|
195 |
-
# else:
|
196 |
-
# st.session_state.evaluation_input = {"result": 0}
|
197 |
-
|
198 |
-
# submit_button = st.button("Submit evaluation", on_click=submit_and_clear, args=(evaluation,))
|
199 |
-
# else:
|
200 |
-
# st.success("Evaluation submitted successfully.")
|
201 |
-
|
202 |
-
|
203 |
-
|
|
|
62 |
"""
|
63 |
components.html(f"{htmlstr}", height=0, width=0)
|
64 |
|
65 |
+
def predict_callback():
|
66 |
+
with st.spinner("Loading prediction..."):
|
67 |
try:
|
68 |
+
print("Request body: ", request_body)
|
69 |
# Call the explain endpoint as it also includes the prediction
|
70 |
+
pred = client.predict(
|
71 |
request_body=request_body, deployment_id=deployment_id
|
72 |
)
|
73 |
except Exception as e:
|
|
|
78 |
+ "Contact Deeploy if the problem persists."
|
79 |
)
|
80 |
return
|
81 |
+
st.session_state.pred = pred
|
82 |
st.session_state.evaluation_submitted = False
|
|
|
83 |
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
def submit_and_clear(evaluation: str):
|
86 |
if evaluation == "yes":
|
87 |
st.session_state.evaluation_input["result"] = 0 # Agree with the prediction
|
88 |
else:
|
89 |
+
# Disagree with the prediction
|
90 |
st.session_state.evaluation_input["result"] = 1
|
91 |
+
# In binary classification problems we can just flip the prediction
|
92 |
+
desired_output = not predictions[0]
|
93 |
st.session_state.evaluation_input["value"] = {"predictions": [desired_output]}
|
94 |
try:
|
95 |
# Call the explain endpoint as it also includes the prediction
|
|
|
97 |
deployment_id, request_log_id, prediction_log_id, st.session_state.evaluation_input
|
98 |
)
|
99 |
st.session_state.evaluation_submitted = True
|
100 |
+
st.session_state.pred = None
|
|
|
101 |
except Exception as e:
|
102 |
logging.error(e)
|
103 |
st.error(
|
|
|
108 |
|
109 |
|
110 |
# Define defaults for the session state
|
111 |
+
if "pred" not in st.session_state:
|
112 |
+
st.session_state.pred = None
|
|
|
|
|
|
|
113 |
|
114 |
if "evaluation_submitted" not in st.session_state:
|
115 |
st.session_state.evaluation_submitted = False
|
|
|
142 |
# st.write(st.session_state)
|
143 |
|
144 |
# Input (for IRIS dataset)
|
145 |
+
with st.expander("Input values for prediction", expanded=True):
|
146 |
st.write("Please input the values for the model.")
|
147 |
col1, col2 = st.columns(2)
|
148 |
with col1:
|
|
|
164 |
}
|
165 |
|
166 |
# Predict and explain
|
167 |
+
predict_button = st.button("Predict", on_click=predict_callback)
|
168 |
+
if st.session_state.pred is not None:
|
169 |
+
st.write(st.session_state.pred)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|