Download handler.py from wang-sy/gpt2-stinfo: direct link, hf CLI and curl.
- Browser
- Download file 825 Bytes
-
https://huggingface.co/wang-sy/gpt2-stinfo/resolve/main/handler.py
- Command line
-
hf download hf://wang-sy/gpt2-stinfo/handler.py
-
curl -L -o handler.py https://huggingface.co/wang-sy/gpt2-stinfo/resolve/main/handler.py
825 Bytes
| from typing import Dict, List, Any | |
| import pipeline | |
| import gdown | |
| class EndpointHandler(): | |
| def __init__(self, path=""): | |
| # Preload all the elements you are going to need at inference. | |
| # pseudo: | |
| file_name = 'ckpt.pt' | |
| url = 'https://drive.google.com/file/d/1jt5zyFcyVUOd5kC_yMrcj3Wqk7kAzuPU' | |
| gdown.download(url, file_name, quiet=False) | |
| def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]: | |
| """ | |
| data args: | |
| inputs (:obj: `str` | `PIL.Image` | `np.array`) | |
| kwargs | |
| Return: | |
| A :obj:`list` | `dict`: will be serialized and returned | |
| """ | |
| inputs = data.pop("inputs", data) | |
| pipeline.start = inputs | |
| output = pipeline.infer() | |
| # isinstance(output,str) | |
| return {"image": output} |