anananan116 commited on
Commit
875151c
·
verified ·
1 Parent(s): edbdc5d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +35 -3
README.md CHANGED
@@ -1,3 +1,35 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
4
+
5
+ ```
6
+ from transformers import AutoModelForCausalLM, AutoTokenizer
7
+ from PIL import Image
8
+ import requests
9
+ import torch
10
+
11
+ model = AutoModelForCausalLM.from_pretrained(
12
+ "anananan116/TinyVLM",
13
+ trust_remote_code = True,
14
+ torch_dtype=torch.float16,
15
+ ).to('cuda').eval()
16
+ tokenizer = AutoTokenizer.from_pretrained("anananan116/TinyVLM")
17
+
18
+ # `<IMGPLH>` is the image placeholder which will be replaced by image embeddings.
19
+ # the number of `<IMGPLH>` should be equal to the number of input images
20
+
21
+ prompt = "Here's an image:<IMGPLH>Describe this image."
22
+ image = Image.open(requests.get('https://github.com/anananan116/TinyVLM/blob/main/test.png?raw=true',stream=True).raw)
23
+ inputs = model.prepare_input_ids_for_generation([prompt], [image], tokenizer)
24
+
25
+ with torch.no_grad():
26
+ outputs = model.generate(
27
+ input_ids=inputs['input_ids'].to("cuda"),
28
+ attention_mask=inputs['attention_mask'].to("cuda"),
29
+ encoded_image = inputs["encoded_image"],
30
+ max_new_tokens=128,
31
+ do_sample=True
32
+ )
33
+
34
+ output_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)
35
+ ```