RaushanTurganbay HF staff commited on
Commit
baedfe8
·
verified ·
1 Parent(s): 821bd6f

Update pipeline example

Browse files
Files changed (1) hide show
  1. README.md +6 -16
README.md CHANGED
@@ -2,7 +2,6 @@
2
  language:
3
  - en
4
  pipeline_tag: image-text-to-text
5
- inference: false
6
  arxiv: 2312.00784
7
  tags:
8
  - vision
@@ -52,30 +51,21 @@ Where `<prompt>` denotes the prompt asked by the user
52
 
53
  ```python
54
  from transformers import pipeline
55
- from PIL import Image
56
- import requests
57
-
58
- model_id = "llava-hf/vip-llava-7b-hf"
59
- pipe = pipeline("image-to-text", model=model_id)
60
- url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
61
- image = Image.open(requests.get(url, stream=True).raw)
62
 
63
- # Define a chat histiry and use `apply_chat_template` to get correctly formatted prompt
64
- # Each value in "content" has to be a list of dicts with types ("text", "image")
65
- conversation = [
66
  {
67
-
68
  "role": "user",
69
  "content": [
 
70
  {"type": "text", "text": "What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"},
71
- {"type": "image"},
72
  ],
73
  },
74
  ]
75
- prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
76
 
77
- outputs = pipe(image, prompt=prompt, generate_kwargs={"max_new_tokens": 200})
78
- print(outputs)
 
79
  ```
80
 
81
  ### Using pure `transformers`:
 
2
  language:
3
  - en
4
  pipeline_tag: image-text-to-text
 
5
  arxiv: 2312.00784
6
  tags:
7
  - vision
 
51
 
52
  ```python
53
  from transformers import pipeline
 
 
 
 
 
 
 
54
 
55
+ pipe = pipeline("image-text-to-text", model="llava-hf/vip-llava-7b-hf")
56
+ messages = [
 
57
  {
 
58
  "role": "user",
59
  "content": [
60
+ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"},
61
  {"type": "text", "text": "What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"},
 
62
  ],
63
  },
64
  ]
 
65
 
66
+ out = pipe(text=messages, max_new_tokens=20)
67
+ print(out)
68
+ >>> [{'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'}]
69
  ```
70
 
71
  ### Using pure `transformers`: