RaushanTurganbay HF staff commited on
Commit
d3ec962
·
verified ·
1 Parent(s): 8f3eefb

Update pipeline example

Browse files
Files changed (1) hide show
  1. README.md +6 -18
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! [![Open in Spaces](https://huggingface.co/datasets
41
 
42
  ```python
43
  from transformers import pipeline
44
- from PIL import Image
45
- import requests
46
-
47
- model_id = "llava-hf/bakLlava-v1-hf"
48
- pipe = pipeline("image-to-text", model=model_id)
49
 
50
- url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
51
- image = Image.open(requests.get(url, stream=True).raw)
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
- outputs = pipe(image, prompt=prompt, generate_kwargs={"max_new_tokens": 200})
68
- print(outputs)
69
- >>> {"generated_text": "\nUSER: What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud\nASSISTANT: Lava"}
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`: