Update pipeline example
Browse files
README.md
CHANGED
@@ -44,33 +44,22 @@ The model supports multi-image and multi-prompt generation. Meaning that you can
|
|
44 |
Below we used [`"llava-hf/llava-1.5-7b-hf"`](https://huggingface.co/llava-hf/llava-1.5-7b-hf) checkpoint.
|
45 |
|
46 |
```python
|
47 |
-
from transformers import pipeline
|
48 |
-
from PIL import Image
|
49 |
-
import requests
|
50 |
-
|
51 |
-
model_id = "llava-hf/llava-1.5-7b-hf"
|
52 |
-
pipe = pipeline("image-to-text", model=model_id)
|
53 |
-
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
|
54 |
-
image = Image.open(requests.get(url, stream=True).raw)
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
conversation = [
|
59 |
{
|
60 |
"role": "user",
|
61 |
"content": [
|
|
|
62 |
{"type": "text", "text": "What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"},
|
63 |
-
{"type": "image"},
|
64 |
],
|
65 |
},
|
66 |
]
|
67 |
-
processor = AutoProcessor.from_pretrained(model_id)
|
68 |
-
|
69 |
-
prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
|
70 |
|
71 |
-
|
72 |
-
print(
|
73 |
-
>>> {
|
74 |
```
|
75 |
|
76 |
### Using pure `transformers`:
|
|
|
44 |
Below we used [`"llava-hf/llava-1.5-7b-hf"`](https://huggingface.co/llava-hf/llava-1.5-7b-hf) checkpoint.
|
45 |
|
46 |
```python
|
47 |
+
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
+
pipe = pipeline("image-text-to-text", model="llava-hf/llava-1.5-7b-hf")
|
50 |
+
messages = [
|
|
|
51 |
{
|
52 |
"role": "user",
|
53 |
"content": [
|
54 |
+
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"},
|
55 |
{"type": "text", "text": "What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"},
|
|
|
56 |
],
|
57 |
},
|
58 |
]
|
|
|
|
|
|
|
59 |
|
60 |
+
out = pipe(text=messages, max_new_tokens=20)
|
61 |
+
print(out)
|
62 |
+
>>> [{'input_text': [{'role': 'user', 'content': [{'type': 'image', 'url': 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg'}, {'type': 'text', 'text': 'What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud'}]}], 'generated_text': 'Lava'}]
|
63 |
```
|
64 |
|
65 |
### Using pure `transformers`:
|