Commit
•
a23b0b5
1
Parent(s):
0dbc5f3
Update README.md
Browse files
README.md
CHANGED
@@ -23,8 +23,38 @@ PROMPT = "<s>[INST]Describe the images.\n[IMG][IMG][IMG][IMG][/INST]"
|
|
23 |
|
24 |
inputs = processor(text=PROMPT, images=IMG_URLS, return_tensors="pt").to("cuda")
|
25 |
generate_ids = model.generate(**inputs, max_new_tokens=500)
|
26 |
-
|
27 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
I got something like this:
|
29 |
```
|
30 |
|
|
|
23 |
|
24 |
inputs = processor(text=PROMPT, images=IMG_URLS, return_tensors="pt").to("cuda")
|
25 |
generate_ids = model.generate(**inputs, max_new_tokens=500)
|
26 |
+
output = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
27 |
```
|
28 |
+
|
29 |
+
You can also use a chat template to format your chat history for Pixtral. Here's an example - note how you can interleave text and multiple images in the same message!
|
30 |
+
|
31 |
+
```python
|
32 |
+
from PIL import Image
|
33 |
+
from transformers import AutoProcessor, LlavaForConditionalGeneration
|
34 |
+
model_id = "mistral-community/pixtral-12b"
|
35 |
+
model = LlavaForConditionalGeneration.from_pretrained(model_id)
|
36 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
37 |
+
|
38 |
+
url_dog = "https://picsum.photos/id/237/200/300"
|
39 |
+
url_mountain = "https://picsum.photos/seed/picsum/200/300"
|
40 |
+
|
41 |
+
chat = [
|
42 |
+
{
|
43 |
+
"role": "user", "content": [
|
44 |
+
{"type": "text", "content": "Can this animal"},
|
45 |
+
{"type": "image"},
|
46 |
+
{"type": "text", "content": "live here?"},
|
47 |
+
{"type": "image"}
|
48 |
+
]
|
49 |
+
}
|
50 |
+
]
|
51 |
+
|
52 |
+
prompt = processor.apply_chat_template(chat)
|
53 |
+
inputs = processor(text=PROMPT, images=[url_dog, url_mountain], return_tensors="pt").to(model.device)
|
54 |
+
generate_ids = model.generate(**inputs, max_new_tokens=500)
|
55 |
+
output = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
56 |
+
```
|
57 |
+
|
58 |
I got something like this:
|
59 |
```
|
60 |
|