MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / calc_image_tokens

Function calc_image_tokens

utils/src/llms.py:44–62  ·  view source on GitHub ↗

Calculate the number of tokens for a list of images.

(images: list[str])

Source from the content-addressed store, hash-verified

42
43
44def calc_image_tokens(images: list[str]):
45 """
46 Calculate the number of tokens for a list of images.
47 """
48 tokens = 0
49 for image in images:
50 with open(image, "rb") as f:
51 width, height = Image.open(f).size
52 if width > 1024 or height > 1024:
53 if width > height:
54 height = int(height * 1024 / width)
55 width = 1024
56 else:
57 width = int(width * 1024 / height)
58 height = 1024
59 h = ceil(height / 512)
60 w = ceil(width / 512)
61 tokens += 85 + 170 * h * w
62 return tokens
63
64
65class LLM:

Callers 1

calc_tokenMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected