Skip to main content

Keye Vision Language Model Utils - PyTorch

Project description

keye-vl-utils

Keye-VL Utils contains a set of helper functions for processing and integrating visual language information with KeyeVL1.5.

Install

pip install keye-vl-utils==1.5.0

Usage

KeyeVL

from transformers import AutoModel, AutoProcessor
from keye_vl_utils import process_vision_info


# You can directly insert a local file path, a URL, or a base64-encoded image into the position where you want in the text.
messages = [
    # Image
    ## Local file path
    [{"role": "user", "content": [{"type": "image", "image": "file:///path/to/your/image.jpg"}, {"type": "text", "text": "Describe this image."}]}],
    ## Image URL
    [{"role": "user", "content": [{"type": "image", "image": "http://path/to/your/image.jpg"}, {"type": "text", "text": "Describe this image."}]}],
    ## Base64 encoded image
    [{"role": "user", "content": [{"type": "image", "image": "data:image;base64,/9j/..."}, {"type": "text", "text": "Describe this image."}]}],
    ## PIL.Image.Image
    [{"role": "user", "content": [{"type": "image", "image": pil_image}, {"type": "text", "text": "Describe this image."}]}],
    # Video
    ## Local video path
    [{"role": "user", "content": [{"type": "video", "video": "file:///path/to/video1.mp4"}, {"type": "text", "text": "Describe this video."}]}],
    ## Local video frames
    [{"role": "user", "content": [{"type": "video", "video": ["file:///path/to/extracted_frame1.jpg", "file:///path/to/extracted_frame2.jpg", "file:///path/to/extracted_frame3.jpg"],}, {"type": "text", "text": "Describe this video."},],}],
    ## Model dynamically adjusts video nframes, video height and width. specify args if required.
    [{"role": "user", "content": [{"type": "video", "video": "file:///path/to/video1.mp4"}, {"type": "text", "text": "Describe this video."}]}],
]

processor = AutoProcessor.from_pretrained("Kwai-Keye/Keye-VL-1.5-8B", trust_remote_code=True)
model = AutoModel.from_pretrained("Kwai-Keye/Keye-VL-1.5-8B", torch_dtype="auto", device_map="auto", trust_remote_code=True)
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
images, videos, **processor_args = process_vision_info(messages)
inputs = processor(text=text, images=images, videos=videos,  return_tensors="pt", **processor_args)
print(inputs)
generated_ids = model.generate(**inputs)
print(generated_ids)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

keye_vl_utils-1.5.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

keye_vl_utils-1.5.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file keye_vl_utils-1.5.1.tar.gz.

File metadata

  • Download URL: keye_vl_utils-1.5.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for keye_vl_utils-1.5.1.tar.gz
Algorithm Hash digest
SHA256 cb645668c28214fb2380c66fe1ecbb44dee223be939a7a1e8270c656898d6e9f
MD5 1032fa16e61d4c93a24ba14ecd509d49
BLAKE2b-256 720bd0377b24400033a71015fbfd16f0ad76356cb4dfd901a000e35a98439ce6

See more details on using hashes here.

File details

Details for the file keye_vl_utils-1.5.1-py3-none-any.whl.

File metadata

  • Download URL: keye_vl_utils-1.5.1-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for keye_vl_utils-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e8d8cd7bc50f0706dd1fbc860669343ebb715a6f615f4a128eab909255302016
MD5 9466430658fc7ea9b15102833689c778
BLAKE2b-256 aa4a73f93042b3bbb74a715a2f04f6891018df2b4eaaf474fb92f66126f89f14

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page