Spaces:
Sleeping
Sleeping
Arielle Messer commited on
Commit ·
c23f0f7
1
Parent(s): 26258da
Harden Supabase URL and explanation fallback
Browse files- src/ml/predict.py +3 -1
- src/store/supabase_io.py +4 -2
src/ml/predict.py
CHANGED
|
@@ -29,6 +29,8 @@ def explain_linear_top_features(
|
|
| 29 |
Returns top_k feature contributions for `class_label` on the first row of X.
|
| 30 |
Contributions are in logit units (not probability).
|
| 31 |
"""
|
|
|
|
|
|
|
| 32 |
text = model.named_steps["text"]
|
| 33 |
clf = model.named_steps["clf"]
|
| 34 |
|
|
@@ -73,4 +75,4 @@ def predict_one_with_reasons(model: Pipeline, subject: str, body: str, top_k: in
|
|
| 73 |
reasons = explain_linear_top_features(model, X, class_label=label, top_k=top_k)
|
| 74 |
return label, confidence, probs, reasons
|
| 75 |
|
| 76 |
-
|
|
|
|
| 29 |
Returns top_k feature contributions for `class_label` on the first row of X.
|
| 30 |
Contributions are in logit units (not probability).
|
| 31 |
"""
|
| 32 |
+
if "text" not in model.named_steps:
|
| 33 |
+
return ["Feature explanations unavailable for this model."]
|
| 34 |
text = model.named_steps["text"]
|
| 35 |
clf = model.named_steps["clf"]
|
| 36 |
|
|
|
|
| 75 |
reasons = explain_linear_top_features(model, X, class_label=label, top_k=top_k)
|
| 76 |
return label, confidence, probs, reasons
|
| 77 |
|
| 78 |
+
|
src/store/supabase_io.py
CHANGED
|
@@ -7,7 +7,9 @@ from supabase import create_client
|
|
| 7 |
|
| 8 |
|
| 9 |
def make_supabase_client():
|
| 10 |
-
url = os.environ["SUPABASE_URL"]
|
|
|
|
|
|
|
| 11 |
key = os.environ["SUPABASE_ANON_KEY"]
|
| 12 |
return create_client(url, key)
|
| 13 |
|
|
@@ -50,4 +52,4 @@ def download_artifact(
|
|
| 50 |
|
| 51 |
data = supabase.storage.from_(bucket).download(object_path) # bytes
|
| 52 |
lp.write_bytes(data)
|
| 53 |
-
return lp
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
def make_supabase_client():
|
| 10 |
+
url = os.environ["SUPABASE_URL"].strip()
|
| 11 |
+
if not url.endswith("/"):
|
| 12 |
+
url = f"{url}/"
|
| 13 |
key = os.environ["SUPABASE_ANON_KEY"]
|
| 14 |
return create_client(url, key)
|
| 15 |
|
|
|
|
| 52 |
|
| 53 |
data = supabase.storage.from_(bucket).download(object_path) # bytes
|
| 54 |
lp.write_bytes(data)
|
| 55 |
+
return lp
|