Download runtime/src/pixelone/cli.py from KangHui2200/PixelOne: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/KangHui2200/PixelOne/resolve/main/runtime/src/pixelone/cli.py
- Command line
-
hf download hf://KangHui2200/PixelOne/runtime/src/pixelone/cli.py
-
curl -L -o cli.py https://huggingface.co/KangHui2200/PixelOne/resolve/main/runtime/src/pixelone/cli.py
1.23 kB
| import argparse | |
| import json | |
| def main(): | |
| parser = argparse.ArgumentParser(prog='pixelone') | |
| commands = parser.add_subparsers(dest='command', required=True) | |
| inference = commands.add_parser('infer', help='Predict an original-image click') | |
| inference.add_argument('--model', required=True) | |
| inference.add_argument('--image', required=True) | |
| inference.add_argument('--instruction', required=True) | |
| inference.add_argument('--device', default='cuda:0') | |
| inference.add_argument('--revision') | |
| inference.add_argument('--subfolder', help='Model directory within a Hugging Face collection or local path') | |
| inference.add_argument('--kernel-backend', choices=['native', 'torch']) | |
| arguments = parser.parse_args() | |
| from PIL import Image | |
| from pixelone.inference import PixelOnePredictor | |
| predictor = PixelOnePredictor.from_pretrained(arguments.model, device=arguments.device, | |
| revision=arguments.revision, subfolder=arguments.subfolder, kernel_backend=arguments.kernel_backend) | |
| with Image.open(arguments.image) as screenshot: | |
| result = predictor.predict(screenshot, arguments.instruction) | |
| print(json.dumps(result, ensure_ascii=False)) | |
| if __name__ == '__main__': | |
| main() | |