Download handler.py from JosephTreitel/reddit-lora-V3: direct link, hf CLI and curl.
- Browser
- Download file 558 Bytes
-
https://huggingface.co/JosephTreitel/reddit-lora-V3/resolve/main/handler.py
- Command line
-
hf download hf://JosephTreitel/reddit-lora-V3/handler.py
-
curl -L -o handler.py https://huggingface.co/JosephTreitel/reddit-lora-V3/resolve/main/handler.py
558 Bytes
| from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline | |
| class EndpointHandler: | |
| def __init__(self, path=""): | |
| self.pipeline = pipeline( | |
| task="text-generation", | |
| model=AutoModelForCausalLM.from_pretrained(path, device_map="auto", trust_remote_code=True), | |
| tokenizer=AutoTokenizer.from_pretrained(path, trust_remote_code=True), | |
| ) | |
| def __call__(self, data): | |
| inputs = data.get("inputs", "") | |
| params = data.get("parameters", {}) | |
| return self.pipeline(inputs, **params) |