Spaces:
Sleeping
Sleeping
Commit
·
bae31cb
1
Parent(s):
5effc07
Improve error handling
Browse files
app.py
CHANGED
|
@@ -29,7 +29,7 @@ st.title("Loan application model example")
|
|
| 29 |
def get_model_url():
|
| 30 |
model_url = st.text_area(
|
| 31 |
"Model URL (without the /explain endpoint, default is the demo deployment)",
|
| 32 |
-
"https://api.app.deeploy.ml/workspaces/
|
| 33 |
height=125,
|
| 34 |
)
|
| 35 |
elems = model_url.split("/")
|
|
@@ -66,13 +66,9 @@ with st.sidebar:
|
|
| 66 |
model_url, workspace_id, deployment_id = get_model_url()
|
| 67 |
st.session_state.deployment_id = deployment_id
|
| 68 |
deployment_token = st.text_input("Deeploy API token", "my-secret-token")
|
|
|
|
| 69 |
if deployment_token == "my-secret-token":
|
| 70 |
st.warning("Please enter Deeploy API token.")
|
| 71 |
-
# Split model URL into workspace and deployment ID
|
| 72 |
-
|
| 73 |
-
# st.write("Values below are for debug only:")
|
| 74 |
-
# st.write("Workspace ID: ", workspace_id)
|
| 75 |
-
# st.write("Deployment ID: ", deployment_id)
|
| 76 |
|
| 77 |
client_options = {
|
| 78 |
"host": host,
|
|
@@ -131,11 +127,19 @@ def predict_callback():
|
|
| 131 |
request_body = form_request_body() # Make sure we have the latest values after user input
|
| 132 |
st.session_state.exp = None
|
| 133 |
with st.spinner("Loading prediction and explanation..."):
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
st.session_state.predict_button_clicked = True
|
| 141 |
st.session_state.evaluation_submitted = False
|
|
|
|
| 29 |
def get_model_url():
|
| 30 |
model_url = st.text_area(
|
| 31 |
"Model URL (without the /explain endpoint, default is the demo deployment)",
|
| 32 |
+
"https://api.app.deeploy.ml/workspaces/7dcdf61c-66d0-4b07-bd8d-7608bcd492d0/deployments/e2c1d1c6-ca68-414d-b071-6cd13ade15c1/",
|
| 33 |
height=125,
|
| 34 |
)
|
| 35 |
elems = model_url.split("/")
|
|
|
|
| 66 |
model_url, workspace_id, deployment_id = get_model_url()
|
| 67 |
st.session_state.deployment_id = deployment_id
|
| 68 |
deployment_token = st.text_input("Deeploy API token", "my-secret-token")
|
| 69 |
+
|
| 70 |
if deployment_token == "my-secret-token":
|
| 71 |
st.warning("Please enter Deeploy API token.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
client_options = {
|
| 74 |
"host": host,
|
|
|
|
| 127 |
request_body = form_request_body() # Make sure we have the latest values after user input
|
| 128 |
st.session_state.exp = None
|
| 129 |
with st.spinner("Loading prediction and explanation..."):
|
| 130 |
+
try:
|
| 131 |
+
# Call the explain endpoint as it also includes the prediction
|
| 132 |
+
exp = client.explain(
|
| 133 |
+
request_body=request_body, deployment_id=st.session_state.deployment_id
|
| 134 |
+
)
|
| 135 |
+
st.session_state.exp = exp
|
| 136 |
+
except Exception as e:
|
| 137 |
+
logging.error(e)
|
| 138 |
+
st.error(
|
| 139 |
+
"Failed to get a prediction and explanation."
|
| 140 |
+
+ "Check whether you are using the right model URL and token for predictions. "
|
| 141 |
+
+ "Contact Deeploy if the problem persists."
|
| 142 |
+
)
|
| 143 |
|
| 144 |
st.session_state.predict_button_clicked = True
|
| 145 |
st.session_state.evaluation_submitted = False
|