Code snippets (#10)
Browse files- Code snippets (c0a7af506d0f71a771f24216ade491dec52ff6c5)
Co-authored-by: Pedro Cuenca <[email protected]>
README.md
CHANGED
@@ -74,6 +74,7 @@ You can load the model as follows.
|
|
74 |
|
75 |
```python
|
76 |
from transformers import AutoProcessor, AutoModelForImageTextToText
|
|
|
77 |
|
78 |
model_path = "HuggingFaceTB/SmolVLM2-2.2B-Instruct"
|
79 |
processor = AutoProcessor.from_pretrained(model_path)
|
@@ -93,9 +94,8 @@ messages = [
|
|
93 |
{
|
94 |
"role": "user",
|
95 |
"content": [
|
96 |
-
{"type": "
|
97 |
-
{"type": "
|
98 |
-
|
99 |
]
|
100 |
},
|
101 |
]
|
@@ -159,14 +159,13 @@ messages = [
|
|
159 |
{
|
160 |
"role": "user",
|
161 |
"content": [
|
162 |
-
{"type": "text", "text": "What is the similarity between
|
163 |
-
|
164 |
-
|
165 |
-
{"type": "text", "text": "and this image <image>"},
|
166 |
-
{"type": "image", "path": "image_2.png"},
|
167 |
]
|
168 |
},
|
169 |
]
|
|
|
170 |
inputs = processor.apply_chat_template(
|
171 |
messages,
|
172 |
add_generation_prompt=True,
|
|
|
74 |
|
75 |
```python
|
76 |
from transformers import AutoProcessor, AutoModelForImageTextToText
|
77 |
+
import torch
|
78 |
|
79 |
model_path = "HuggingFaceTB/SmolVLM2-2.2B-Instruct"
|
80 |
processor = AutoProcessor.from_pretrained(model_path)
|
|
|
94 |
{
|
95 |
"role": "user",
|
96 |
"content": [
|
97 |
+
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg"},
|
98 |
+
{"type": "text", "text": "Can you describe this image?"},
|
|
|
99 |
]
|
100 |
},
|
101 |
]
|
|
|
159 |
{
|
160 |
"role": "user",
|
161 |
"content": [
|
162 |
+
{"type": "text", "text": "What is the similarity between these two images?"},
|
163 |
+
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg"},
|
164 |
+
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/0052a70beed5bf71b92610a43a52df6d286cd5f3/diffusers/rabbit.jpg"},
|
|
|
|
|
165 |
]
|
166 |
},
|
167 |
]
|
168 |
+
|
169 |
inputs = processor.apply_chat_template(
|
170 |
messages,
|
171 |
add_generation_prompt=True,
|