Llava Example#

Source vllm-project/vllm.

 1import os
 2import subprocess
 3
 4from PIL import Image
 5
 6from vllm import LLM
 7
 8# The assets are located at `s3://air-example-data-2/vllm_opensource_llava/`.
 9# You can use `.buildkite/download-images.sh` to download them
10
11
12def run_llava():
13    llm = LLM(model="llava-hf/llava-1.5-7b-hf")
14
15    prompt = "USER: <image>\nWhat is the content of this image?\nASSISTANT:"
16
17    image = Image.open("images/stop_sign.jpg")
18
19    outputs = llm.generate({
20        "prompt": prompt,
21        "multi_modal_data": {
22            "image": image
23        },
24    })
25
26    for o in outputs:
27        generated_text = o.outputs[0].text
28        print(generated_text)
29
30
31def main():
32    run_llava()
33
34
35if __name__ == "__main__":
36    # Download from s3
37    s3_bucket_path = "s3://air-example-data-2/vllm_opensource_llava/"
38    local_directory = "images"
39
40    # Make sure the local directory exists or create it
41    os.makedirs(local_directory, exist_ok=True)
42
43    # Use AWS CLI to sync the directory, assume anonymous access
44    subprocess.check_call([
45        "aws",
46        "s3",
47        "sync",
48        s3_bucket_path,
49        local_directory,
50        "--no-sign-request",
51    ])
52    main()