Download handler.py from mart9992/eri2: direct link, hf CLI and curl.
- Browser
- Download file 1.84 kB
-
https://huggingface.co/mart9992/eri2/resolve/45dc1db69e956a64d00a6a5e795d3abb0ff8a799/handler.py
- Command line
-
hf download hf://mart9992/eri2@45dc1db69e956a64d00a6a5e795d3abb0ff8a799/handler.py
-
curl -L -o handler.py https://huggingface.co/mart9992/eri2/resolve/45dc1db69e956a64d00a6a5e795d3abb0ff8a799/handler.py
1.84 kB
| import os | |
| import subprocess | |
| import torch | |
| print(os.listdir('/usr/local/')) | |
| print(torch.version.cuda) | |
| class EndpointHandler(): | |
| def __init__(self, path=""): | |
| is_production = True | |
| os.chdir("/repository" if is_production else "/workspace/eri2") | |
| os.environ['AM_I_DOCKER'] = 'False' | |
| os.environ['BUILD_WITH_CUDA'] = 'True' | |
| os.environ['CUDA_HOME'] = '/usr/local/cuda-11.7/' | |
| # Install Segment Anything | |
| subprocess.run(["python", "-m", "pip", "install", "-e", "segment_anything"]) | |
| # Install Grounding DINO | |
| subprocess.run(["python", "-m", "pip", "install", "-e", "GroundingDINO"]) | |
| # Install diffusers | |
| subprocess.run(["pip", "install", "--upgrade", "diffusers[torch]"]) | |
| # Install osx | |
| subprocess.run(["git", "submodule", "update", "--init", "--recursive"]) | |
| subprocess.run(["bash", "grounded-sam-xxx/install.sh"], cwd="grounded-sam-xxx") | |
| # Install RAM & Tag2Text | |
| subprocess.run(["git", "clone", "https://github.com/xinyu1205/recognize-anything.git"]) | |
| subprocess.run(["pip", "install", "-r", "./recognize-anything/requirements.txt"]) | |
| subprocess.run(["pip", "install", "-e", "./recognize-anything/"]) | |
| def __call__(self, data): | |
| """ | |
| data args: | |
| inputs (:obj: `str`) | |
| date (:obj: `str`) | |
| Return: | |
| A :obj:`list` | `dict`: will be serialized and returned | |
| """ | |
| # get inputs | |
| inputs = data.pop("inputs",data) | |
| date = data.pop("date", None) | |
| # check if date exists and if it is a holiday | |
| if date is not None and date in self.holidays: | |
| return [{"label": "happy", "score": 1}] | |
| # run normal prediction | |
| prediction = self.pipeline(inputs) | |
| return prediction |