Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import Pix2StructProcessor, Pix2StructForConditionalGeneration
|
2 |
+
import requests
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
processor = Pix2StructProcessor.from_pretrained('google/deplot')
|
6 |
+
model = Pix2StructForConditionalGeneration.from_pretrained('google/deplot')
|
7 |
+
|
8 |
+
url = "https://raw.githubusercontent.com/vis-nlp/ChartQA/main/ChartQA%20Dataset/val/png/5090.png"
|
9 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
10 |
+
|
11 |
+
inputs = processor(images=image, text="Generate underlying data table of the figure below:", return_tensors="pt")
|
12 |
+
predictions = model.generate(**inputs, max_new_tokens=512)
|
13 |
+
print(processor.decode(predictions[0], skip_special_tokens=True))
|