RaushanTurganbay HF staff commited on
Commit
55769ad
·
verified ·
1 Parent(s): 5b6d18d

Update pipeline example

Browse files
Files changed (1) hide show
  1. README.md +26 -2
README.md CHANGED
@@ -29,12 +29,36 @@ other versions on a task that interests you.
29
 
30
  ### How to use
31
 
32
- Here's the prompt template for this model:
 
 
33
  ```
34
  "A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions. USER: <image>\nWhat is shown in this image? ASSISTANT:"
35
  ```
36
 
37
- You can load and use the model like following:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  ```python
39
  from transformers import LlavaNextProcessor, LlavaNextForConditionalGeneration
40
  import torch
 
29
 
30
  ### How to use
31
 
32
+ Here's the prompt template for this model but we recommend to use chat templates to format the prompt with `processor.apply_chat_template()`.
33
+ That will apply the correct template for a given checkpoint for you.
34
+
35
  ```
36
  "A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions. USER: <image>\nWhat is shown in this image? ASSISTANT:"
37
  ```
38
 
39
+ To run the model with the `pipeline`, see the below example:
40
+
41
+ ```python
42
+ from transformers import pipeline
43
+
44
+ pipe = pipeline("image-text-to-text", model="llava-hf/llava-v1.6-vicuna-13b-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
+
61
+ You can also load and use the model like following:
62
  ```python
63
  from transformers import LlavaNextProcessor, LlavaNextForConditionalGeneration
64
  import torch