Views
No views yet
1from transformers import LlavaProcessor, LlavaForCausalLM
2from PIL import Image
3import requests
4import torch
5
6PATH_TO_CONVERTED_WEIGHTS = "shauray/Llava-1.5-7B-hf"
7
8model = LlavaForCausalLM.from_pretrained(PATH_TO_CONVERTED_WEIGHTS,
9device_map="cuda",torch_dtype=torch.float16).to("cuda")
10processor = LlavaProcessor.from_pretrained(PATH_TO_CONVERTED_WEIGHTS)
11
12url = "https://llava-vl.github.io/static/images/view.jpg"
13image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
14prompt = "How can you best describe this image?"
15
16inputs = processor(text=prompt, images=image, return_tensors="pt").to("cuda",
17torch.float16)
18# Generate
19generate_ids = model.generate(**inputs,
20 do_sample=True,
21 max_length=1024,
22 temperature=0.1,
23 top_p=0.9,
24)
25out = processor.decode(generate_ids[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True).strip()
26
27print(out)
28
29"""The photograph shows a wooden dock floating on the water, with mountains in the background. It is an idyllic scene that captures both
30nature and human-made structures at their finest moments of beauty or tranquility depending upon one's perspective as they gaze into it"""