Views
No views yet
checkin_or_not_classifier.json
README.md1from sentence_transformers import SentenceTransformer
2import xgboost as xgb
3import numpy as np
4from huggingface_hub import hf_hub_download
5
6# ----------------------------------------------------
7# 1. Load the embedding model (must be downloaded locally)
8# ----------------------------------------------------
9# Users must install: pip install sentence-transformers
10embedder = SentenceTransformer("all-MiniLM-L6-v2")
11
12# ----------------------------------------------------
13# 2. Download your XGBoost model from HuggingFace Hub
14# ----------------------------------------------------
15model_path = hf_hub_download(
16 repo_id="mjpsm/checkin_or_not_model",
17 filename="checkin_or_not_classifier.json"
18)
19
20# Load the model
21booster = xgb.Booster()
22booster.load_model(model_path)
23
24# ----------------------------------------------------
25# 3. Prediction function
26# ----------------------------------------------------
27def predict(text: str):
28 emb = embedder.encode([text])
29 dmatrix = xgb.DMatrix(emb)
30
31 score = float(booster.predict(dmatrix)[0])
32 label = "CHECKIN" if score >= 0.5 else "NOT_CHECKIN"
33
34 return {"label": label, "score": score}
35
36
37# ----------------------------------------------------
38# 4. Example usage
39# ----------------------------------------------------
40example = "Today I worked on improving the automation workflow."
41result = predict(example)
42
43print(result)
44