Download handler.py from bhsinghgrid/devflow2: direct link, hf CLI and curl.
- Browser
- Download file 909 Bytes
-
https://huggingface.co/bhsinghgrid/devflow2/resolve/main/handler.py
- Command line
-
hf download hf://bhsinghgrid/devflow2/handler.py
-
curl -L -o handler.py https://huggingface.co/bhsinghgrid/devflow2/resolve/main/handler.py
909 Bytes
| from typing import Any, Dict | |
| from inference_api import predict | |
| class EndpointHandler: | |
| """ | |
| Hugging Face Inference Endpoint handler. | |
| Expects payload: | |
| { | |
| "inputs": "dharmo rakṣati rakṣitaḥ", | |
| "parameters": {"temperature": 0.7, ...} | |
| } | |
| """ | |
| def __init__(self, path: str = ""): | |
| self.path = path | |
| def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]: | |
| text = data.get("inputs", "") | |
| params = data.get("parameters", {}) or {} | |
| return predict( | |
| text=text, | |
| temperature=params.get("temperature", 0.7), | |
| top_k=params.get("top_k", 40), | |
| repetition_penalty=params.get("repetition_penalty", 1.2), | |
| diversity_penalty=params.get("diversity_penalty", 0.0), | |
| num_steps=params.get("num_steps", 64), | |
| clean_output=params.get("clean_output", True), | |
| ) | |