RaushanTurganbay HF Staff commited on
Commit
2b7d773
·
verified ·
1 Parent(s): be9b17d

Update pipeline example

Browse files
Files changed (1) hide show
  1. README.md +7 -19
README.md CHANGED
@@ -38,35 +38,23 @@ The model supports multi-image and multi-prompt generation. Meaning that you can
38
 
39
  Below we used [`"llava-hf/llava-interleave-qwen-0.5b-hf"`](https://huggingface.co/llava-hf/llava-interleave-qwen-0.5b-hf) checkpoint.
40
 
41
-
42
  ```python
43
- from transformers import pipeline, AutoProcessor
44
- from PIL import Image
45
- import requests
46
-
47
- model_id = "llava-hf/llava-interleave-qwen-7b-hf"
48
- pipe = pipeline("image-to-text", model=model_id)
49
- processor = AutoProcessor.from_pretrained(model_id)
50
-
51
- url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
52
- image = Image.open(requests.get(url, stream=True).raw)
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
- outputs = pipe(image, prompt=prompt, generate_kwargs={"max_new_tokens": 200})
69
- print(outputs)
 
70
  ```
71
 
72
  ### Using pure `transformers`:
 
38
 
39
  Below we used [`"llava-hf/llava-interleave-qwen-0.5b-hf"`](https://huggingface.co/llava-hf/llava-interleave-qwen-0.5b-hf) checkpoint.
40
 
 
41
  ```python
42
+ from transformers import pipeline
 
 
 
 
 
 
 
 
 
43
 
44
+ pipe = pipeline("image-text-to-text", model="llava-interleave-qwen-7b-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`: