Nikhil0987 commited on
Commit
76a752e
·
verified ·
1 Parent(s): 124b238

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -0
app.py CHANGED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from PIL import Image
3
+ from transformers import Pix2StructForConditionalGeneration, Pix2StructProcessor
4
+
5
+
6
+ image_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
7
+ image = Image.open(requests.get(image_url, stream=True).raw)
8
+
9
+ model = Pix2StructForConditionalGeneration.from_pretrained("google/pix2struct-ai2d-base")
10
+ processor = Pix2StructProcessor.from_pretrained("google/pix2struct-ai2d-base")
11
+
12
+ question = "What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"
13
+
14
+ inputs = processor(images=image, text=question, return_tensors="pt")
15
+
16
+ predictions = model.generate(**inputs)
17
+ print(processor.decode(predictions[0], skip_special_tokens=True))