Update README.md
Browse files
README.md
CHANGED
@@ -60,17 +60,19 @@ from transformers import Pix2StructForConditionalGeneration, Pix2StructProcessor
|
|
60 |
import requests
|
61 |
from PIL import Image
|
62 |
|
63 |
-
model = Pix2StructForConditionalGeneration.from_pretrained('ybelkada/matcha-chartqa')
|
64 |
processor = Pix2StructProcessor.from_pretrained('ybelkada/matcha-chartqa')
|
65 |
url = "https://raw.githubusercontent.com/vis-nlp/ChartQA/main/ChartQA%20Dataset/val/png/20294671002019.png"
|
66 |
image = Image.open(requests.get(url, stream=True).raw)
|
67 |
|
68 |
-
inputs = processor(images=image, text="Is the sum of all 4 places greater than Laos?", return_tensors="pt")
|
69 |
predictions = model.generate(**inputs, max_new_tokens=512)
|
70 |
print(processor.decode(predictions[0], skip_special_tokens=True))
|
71 |
>>> No
|
72 |
```
|
73 |
|
|
|
|
|
74 |
# Contribution
|
75 |
|
76 |
This model was originally contributed by Fangyu Liu, Francesco Piccinno et al. and added to the Hugging Face ecosystem by [Younes Belkada](https://huggingface.co/ybelkada).
|
|
|
60 |
import requests
|
61 |
from PIL import Image
|
62 |
|
63 |
+
model = Pix2StructForConditionalGeneration.from_pretrained('ybelkada/matcha-chartqa')
|
64 |
processor = Pix2StructProcessor.from_pretrained('ybelkada/matcha-chartqa')
|
65 |
url = "https://raw.githubusercontent.com/vis-nlp/ChartQA/main/ChartQA%20Dataset/val/png/20294671002019.png"
|
66 |
image = Image.open(requests.get(url, stream=True).raw)
|
67 |
|
68 |
+
inputs = processor(images=image, text="Is the sum of all 4 places greater than Laos?", return_tensors="pt")
|
69 |
predictions = model.generate(**inputs, max_new_tokens=512)
|
70 |
print(processor.decode(predictions[0], skip_special_tokens=True))
|
71 |
>>> No
|
72 |
```
|
73 |
|
74 |
+
To run the predictions on GPU, simply add `.to(0)` when creating the model and when getting the inputs (`inputs = inputs.to(0)`)
|
75 |
+
|
76 |
# Contribution
|
77 |
|
78 |
This model was originally contributed by Fangyu Liu, Francesco Piccinno et al. and added to the Hugging Face ecosystem by [Younes Belkada](https://huggingface.co/ybelkada).
|