Spaces:
Sleeping
Sleeping
import requests | |
from PIL import Image | |
from transformers import Pix2StructForConditionalGeneration, Pix2StructProcessor | |
image_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg" | |
image = Image.open(requests.get(image_url, stream=True).raw) | |
model = Pix2StructForConditionalGeneration.from_pretrained("google/pix2struct-ai2d-base") | |
processor = Pix2StructProcessor.from_pretrained("google/pix2struct-ai2d-base") | |
question = "What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud" | |
inputs = processor(images=image, text=question, return_tensors="pt") | |
predictions = model.generate(**inputs) | |
print(processor.decode(predictions[0], skip_special_tokens=True)) |