RaushanTurganbay HF staff commited on
Commit
b128a05
·
verified ·
1 Parent(s): 6864c65

Update pipeline example

Browse files
Files changed (1) hide show
  1. README.md +7 -18
README.md CHANGED
@@ -40,33 +40,22 @@ Below we used [`"llava-hf/llava-interleave-qwen-0.5b-hf"`](https://huggingface.c
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-0.5b-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 histiry 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`:
 
40
 
41
 
42
  ```python
43
+ from transformers import pipeline
 
 
 
 
 
 
 
 
 
44
 
45
+ pipe = pipeline("image-text-to-text", model="llava-interleave-qwen-0.5b-hf")
46
+ messages = [
 
47
  {
 
48
  "role": "user",
49
  "content": [
50
+ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"},
51
  {"type": "text", "text": "What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"},
 
52
  ],
53
  },
54
  ]
 
55
 
56
+ out = pipe(text=messages, max_new_tokens=20)
57
+ print(out)
58
+ >>> [{'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'}]
59
  ```
60
 
61
  ### Using pure `transformers`: