Spaces:
Sleeping
Sleeping
kz110AIPI commited on
Commit ·
af0cf81
1
Parent(s): 4213665
Track deployed model with Git LFS
Browse files- .gitattributes +1 -0
- .gitignore +2 -2
- models/tfidf_logistic_regression.joblib +3 -0
- models/tfidf_logistic_regression.joblib.b64 +0 -0
- src/campus_triage/predict.py +16 -33
.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
.gitignore
CHANGED
|
@@ -15,9 +15,9 @@ models/*.safetensors
|
|
| 15 |
models/*.pt
|
| 16 |
models/*.pth
|
| 17 |
models/*.pkl
|
| 18 |
-
models/*.joblib
|
|
|
|
| 19 |
!models/.gitkeep
|
| 20 |
-
!models/*.joblib.b64
|
| 21 |
data/raw/tmp*
|
| 22 |
data/raw/*.tmp
|
| 23 |
data/processed/*.tmp
|
|
|
|
| 15 |
models/*.pt
|
| 16 |
models/*.pth
|
| 17 |
models/*.pkl
|
| 18 |
+
models/*.joblib.b64
|
| 19 |
+
models/majority_baseline.joblib
|
| 20 |
!models/.gitkeep
|
|
|
|
| 21 |
data/raw/tmp*
|
| 22 |
data/raw/*.tmp
|
| 23 |
data/processed/*.tmp
|
models/tfidf_logistic_regression.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9ce6e02a03c5bc56673fb7d914f23d38a28bc2ae300884144160e127c24cca5b
|
| 3 |
+
size 136126
|
models/tfidf_logistic_regression.joblib.b64
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
src/campus_triage/predict.py
CHANGED
|
@@ -6,8 +6,6 @@ Portions of this file were developed with assistance from OpenAI ChatGPT/Codex a
|
|
| 6 |
|
| 7 |
from __future__ import annotations
|
| 8 |
|
| 9 |
-
import base64
|
| 10 |
-
import tempfile
|
| 11 |
from pathlib import Path
|
| 12 |
from typing import Any
|
| 13 |
|
|
@@ -25,45 +23,31 @@ EXAMPLE_MESSAGES = [
|
|
| 25 |
|
| 26 |
|
| 27 |
def candidate_model_paths(model_path: Path = CLASSICAL_MODEL_PATH) -> list[Path]:
|
| 28 |
-
"""Return likely
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
def candidate_encoded_model_paths(model_path: Path = CLASSICAL_MODEL_PATH) -> list[Path]:
|
| 43 |
-
"""Return likely text-encoded model locations across local and hosted layouts."""
|
| 44 |
-
|
| 45 |
-
return [path.with_suffix(path.suffix + ".b64") for path in candidate_model_paths(model_path)]
|
| 46 |
|
| 47 |
|
| 48 |
def resolve_deployed_model_path(model_path: Path = CLASSICAL_MODEL_PATH) -> Path | None:
|
| 49 |
-
"""Return
|
| 50 |
|
| 51 |
for candidate_path in candidate_model_paths(model_path):
|
| 52 |
if candidate_path.exists():
|
| 53 |
return candidate_path
|
| 54 |
-
|
| 55 |
-
for encoded_path in candidate_encoded_model_paths(model_path):
|
| 56 |
-
if encoded_path.exists():
|
| 57 |
-
decoded_path = Path(tempfile.gettempdir()) / model_path.name
|
| 58 |
-
if not decoded_path.exists():
|
| 59 |
-
encoded_text = encoded_path.read_text(encoding="ascii")
|
| 60 |
-
decoded_path.write_bytes(base64.b64decode(encoded_text))
|
| 61 |
-
return decoded_path
|
| 62 |
return None
|
| 63 |
|
| 64 |
|
| 65 |
def model_available(model_path: Path = CLASSICAL_MODEL_PATH) -> bool:
|
| 66 |
-
"""Return whether the deployed model artifact exists
|
| 67 |
|
| 68 |
return resolve_deployed_model_path(model_path) is not None
|
| 69 |
|
|
@@ -71,12 +55,11 @@ def model_available(model_path: Path = CLASSICAL_MODEL_PATH) -> bool:
|
|
| 71 |
def model_search_diagnostics(model_path: Path = CLASSICAL_MODEL_PATH) -> str:
|
| 72 |
"""Return a readable list of model paths checked during deployment."""
|
| 73 |
|
| 74 |
-
|
| 75 |
-
return "\n".join(str(path) for path in checked_paths)
|
| 76 |
|
| 77 |
|
| 78 |
def load_deployed_model(model_path: Path = CLASSICAL_MODEL_PATH) -> Any:
|
| 79 |
-
"""Load the deployed
|
| 80 |
|
| 81 |
resolved_model_path = resolve_deployed_model_path(model_path)
|
| 82 |
if resolved_model_path is None:
|
|
|
|
| 6 |
|
| 7 |
from __future__ import annotations
|
| 8 |
|
|
|
|
|
|
|
| 9 |
from pathlib import Path
|
| 10 |
from typing import Any
|
| 11 |
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
def candidate_model_paths(model_path: Path = CLASSICAL_MODEL_PATH) -> list[Path]:
|
| 26 |
+
"""Return likely model locations across local and Hugging Face layouts."""
|
| 27 |
+
|
| 28 |
+
return list(
|
| 29 |
+
dict.fromkeys(
|
| 30 |
+
[
|
| 31 |
+
model_path,
|
| 32 |
+
PROJECT_ROOT / "models" / model_path.name,
|
| 33 |
+
Path.cwd() / "models" / model_path.name,
|
| 34 |
+
Path("/app/models") / model_path.name,
|
| 35 |
+
]
|
| 36 |
+
)
|
| 37 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
def resolve_deployed_model_path(model_path: Path = CLASSICAL_MODEL_PATH) -> Path | None:
|
| 41 |
+
"""Return the trained model path using robust repo-root based lookup."""
|
| 42 |
|
| 43 |
for candidate_path in candidate_model_paths(model_path):
|
| 44 |
if candidate_path.exists():
|
| 45 |
return candidate_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
return None
|
| 47 |
|
| 48 |
|
| 49 |
def model_available(model_path: Path = CLASSICAL_MODEL_PATH) -> bool:
|
| 50 |
+
"""Return whether the deployed model artifact exists."""
|
| 51 |
|
| 52 |
return resolve_deployed_model_path(model_path) is not None
|
| 53 |
|
|
|
|
| 55 |
def model_search_diagnostics(model_path: Path = CLASSICAL_MODEL_PATH) -> str:
|
| 56 |
"""Return a readable list of model paths checked during deployment."""
|
| 57 |
|
| 58 |
+
return "\n".join(str(path) for path in candidate_model_paths(model_path))
|
|
|
|
| 59 |
|
| 60 |
|
| 61 |
def load_deployed_model(model_path: Path = CLASSICAL_MODEL_PATH) -> Any:
|
| 62 |
+
"""Load the deployed TF-IDF Logistic Regression model."""
|
| 63 |
|
| 64 |
resolved_model_path = resolve_deployed_model_path(model_path)
|
| 65 |
if resolved_model_path is None:
|