NicoZenith's picture
Update README.md
b023a3f verified
|
raw
history blame
1.02 kB

Usage

import requests
from PIL import Image

import torch

from transformers import AutoProcessor, LlavaOnevisionForConditionalGeneration

model = LlavaOnevisionForConditionalGeneration.from_pretrained("NicoZenith/onevision-7b-all-vqa-conv")
processor = AutoProcessor.from_pretrained("NicoZenith/onevision-7b-all-vqa-conv")i

conversation = [
    {

      "role": "user",
      "content": [
          {"type": "text", "text": "What can you say about this X-ray?"},
          {"type": "image"},
        ],
    },
]


prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)

image_file = "https://prod-images-static.radiopaedia.org/images/29923576/fed73420497c8622734f21ce20fc91_gallery.jpeg"
raw_image = Image.open(requests.get(image_file, stream=True).raw)
inputs = processor(images=raw_image, text=prompt, return_tensors='pt').to(0, torch.float16)

output = model.generate(**inputs, max_new_tokens=200, do_sample=False)
print(processor.decode(output[0][2:], skip_special_tokens=True))