Instructions to use everyone-free/hi-bye with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use everyone-free/hi-bye with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("everyone-free/hi-bye") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Notebooks
- Google Colab
- Kaggle
Download handler.py from everyone-free/hi-bye: direct link, hf CLI and curl.
- Browser
- Download file 1.88 kB
-
https://huggingface.co/everyone-free/hi-bye/resolve/main/handler.py
- Command line
-
hf download hf://everyone-free/hi-bye/handler.py
-
curl -L -o handler.py https://huggingface.co/everyone-free/hi-bye/resolve/main/handler.py
1.88 kB
| """Custom handler for Hugging Face Inference Endpoints. | |
| HF creates EndpointHandler(path) once when the endpoint starts, then calls it | |
| for every request with the JSON body, e.g. {"inputs": "hello how are you"}. | |
| """ | |
| import os | |
| from typing import Any, Dict, List, Union | |
| import joblib | |
| from sentence_transformers import SentenceTransformer | |
| ENCODER_NAME = "sentence-transformers/all-MiniLM-L6-v2" | |
| # What to say for each label the classifier can predict. | |
| # Every label used in data.csv needs an entry here. | |
| REPLIES = { | |
| "greeting": "hello", | |
| "computer": "output", | |
| "other": "I don't understand", | |
| } | |
| class EndpointHandler: | |
| def __init__(self, path: str = ""): | |
| base = path or os.path.dirname(os.path.abspath(__file__)) | |
| self.encoder = SentenceTransformer(ENCODER_NAME) | |
| self.clf = joblib.load(os.path.join(base, "classifier.joblib")) | |
| def _predict(self, texts: List[str]) -> List[Dict[str, Any]]: | |
| if not texts: | |
| return [] | |
| embeddings = self.encoder.encode(texts, normalize_embeddings=True) | |
| probs = self.clf.predict_proba(embeddings) | |
| results = [] | |
| for row in probs: | |
| best = int(row.argmax()) | |
| label = str(self.clf.classes_[best]) | |
| results.append({ | |
| "reply": REPLIES[label], | |
| "label": label, | |
| "score": round(float(row[best]), 4), | |
| }) | |
| return results | |
| def __call__(self, data: Dict[str, Any]) -> Union[Dict[str, Any], List[Dict[str, Any]]]: | |
| if not isinstance(data, dict) or "inputs" not in data: | |
| raise ValueError('Send JSON like {"inputs": "hi"}') | |
| inputs = data["inputs"] | |
| if isinstance(inputs, list): # several texts -> list of results | |
| return self._predict([str(t) for t in inputs]) | |
| return self._predict([str(inputs)])[0] # one text -> one result | |