Update pipeline example
Browse files
README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2 |
language:
|
3 |
- en
|
4 |
pipeline_tag: image-text-to-text
|
5 |
-
inference: false
|
6 |
arxiv: 2304.08485
|
7 |
license: llama2
|
8 |
tags:
|
@@ -42,32 +41,21 @@ Below we used [`"llava-hf/llava-1.5-13b-hf"`](https://huggingface.co/llava-hf/ll
|
|
42 |
|
43 |
```python
|
44 |
from transformers import pipeline
|
45 |
-
from PIL import Image
|
46 |
-
import requests
|
47 |
-
|
48 |
-
model_id = "llava-hf/llava-1.5-13b-hf"
|
49 |
-
pipe = pipeline("image-to-text", model=model_id)
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
# Define a chat history and use `apply_chat_template` to get correctly formatted prompt
|
55 |
-
# Each value in "content" has to be a list of dicts with types ("text", "image")
|
56 |
-
conversation = [
|
57 |
{
|
58 |
-
|
59 |
"role": "user",
|
60 |
"content": [
|
|
|
61 |
{"type": "text", "text": "What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"},
|
62 |
-
{"type": "image"},
|
63 |
],
|
64 |
},
|
65 |
]
|
66 |
-
prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
|
67 |
|
68 |
-
|
69 |
-
print(
|
70 |
-
>>> {
|
71 |
```
|
72 |
|
73 |
### Using pure `transformers`:
|
|
|
2 |
language:
|
3 |
- en
|
4 |
pipeline_tag: image-text-to-text
|
|
|
5 |
arxiv: 2304.08485
|
6 |
license: llama2
|
7 |
tags:
|
|
|
41 |
|
42 |
```python
|
43 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
+
pipe = pipeline("image-text-to-text", model="llava-hf/llava-1.5-13b-hf")
|
46 |
+
messages = [
|
|
|
|
|
|
|
|
|
47 |
{
|
|
|
48 |
"role": "user",
|
49 |
"content": [
|
50 |
+
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"},
|
51 |
{"type": "text", "text": "What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"},
|
|
|
52 |
],
|
53 |
},
|
54 |
]
|
|
|
55 |
|
56 |
+
out = pipe(text=messages, max_new_tokens=20)
|
57 |
+
print(out)
|
58 |
+
>>> [{'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'}]
|
59 |
```
|
60 |
|
61 |
### Using pure `transformers`:
|