Animorish commited on
Commit
c5ef92b
·
verified ·
1 Parent(s): 044d7a6

Create asdf

Browse files
Files changed (1) hide show
  1. asdf +21 -0
asdf ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import LlavaNextProcessor, LlavaNextForConditionalGeneration
2
+ import torch
3
+ from PIL import Image
4
+ import requests
5
+
6
+ processor = LlavaNextProcessor.from_pretrained("llava-hf/llava-v1.6-mistral-7b-hf")
7
+
8
+ model = LlavaNextForConditionalGeneration.from_pretrained("llava-hf/llava-v1.6-mistral-7b-hf", torch_dtype=torch.float16, low_cpu_mem_usage=True)
9
+ model.to("cuda:0")
10
+
11
+ # prepare image and text prompt, using the appropriate prompt template
12
+ url = "https://github.com/haotian-liu/LLaVA/blob/1a91fc274d7c35a9b50b3cb29c4247ae5837ce39/images/llava_v1_5_radar.jpg?raw=true"
13
+ image = Image.open(requests.get(url, stream=True).raw)
14
+ prompt = "[INST] <image>\nWhat is shown in this image? [/INST]"
15
+
16
+ inputs = processor(prompt, image, return_tensors="pt").to("cuda:0")
17
+
18
+ # autoregressively complete prompt
19
+ output = model.generate(**inputs, max_new_tokens=100)
20
+
21
+ print(processor.decode(output[0], skip_special_tokens=True))