-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
52 lines (41 loc) · 1.37 KB
/
main.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import argparse
import torch
from transformers import AutoProcessor, AutoModelForCausalLM
from tinyclick_utils import prepare_inputs, postprocess
def main():
parser = argparse.ArgumentParser(
prog="TinyClickInference",
description="Example inference with TinyClick agent.",
)
parser.add_argument(
"--image-path",
required=True,
type=str,
help="Path to the input image (GUI screenshot).",
)
parser.add_argument(
"--text",
required=True,
type=str,
help="Input command to perform by agent on GUI screenshot.",
)
args = parser.parse_args()
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
processor = AutoProcessor.from_pretrained(
"Samsung/TinyClick", trust_remote_code=True
)
model = AutoModelForCausalLM.from_pretrained(
"Samsung/TinyClick",
trust_remote_code=True,
).to(device)
text = args.text
image_path = args.image_path
inputs = prepare_inputs(image_path, text, processor)
img_size = inputs.pop("image_size")
inputs = {k: v.to(device) for k, v in inputs.items()}
outputs = model.generate(**inputs)
generated_texts = processor.batch_decode(outputs, skip_special_tokens=False)
result = postprocess(generated_texts[0], img_size)
print(result)
if __name__ == "__main__":
main()