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