Download interface.py from mjpsm/Kinara-xgb-model: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/mjpsm/Kinara-xgb-model/resolve/main/interface.py
- Command line
-
hf download hf://mjpsm/Kinara-xgb-model/interface.py
-
curl -L -o interface.py https://huggingface.co/mjpsm/Kinara-xgb-model/resolve/main/interface.py
1.11 kB
| # inference.py | |
| import joblib | |
| from sentence_transformers import SentenceTransformer | |
| import numpy as np | |
| # ----------------------------- | |
| # Load model + embedder at container startup | |
| # ----------------------------- | |
| MODEL_FILENAME = "/Users/mazamessomeba/Desktop/Projects/Soulprint_snapshot/kinara-regression/Kinara_xgb_model.pkl" # change per repo | |
| model = joblib.load(MODEL_FILENAME) | |
| embedder = SentenceTransformer("all-mpnet-base-v2") | |
| # ----------------------------- | |
| # Hugging Face Inference API entrypoint | |
| # ----------------------------- | |
| def predict(inputs: dict) -> dict: | |
| """ | |
| Expected input: | |
| { | |
| "text": "During a heated family argument, I stayed calm and reminded everyone of our values." | |
| } | |
| Returns: | |
| { | |
| "score": 0.752 | |
| } | |
| """ | |
| if "text" not in inputs: | |
| return {"error": "Missing required field 'text'"} | |
| text = inputs["text"] | |
| # Convert text to embedding | |
| embedding = embedder.encode([text]) | |
| # Predict with model | |
| score = model.predict(embedding)[0] | |
| # Ensure it's a float for JSON serialization | |
| return {"score": float(score)} | |