File size: 1,229 Bytes
d3b61f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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()