ravi-vc commited on
Commit
dfbe417
·
verified ·
1 Parent(s): a467490

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import Pix2StructProcessor, Pix2StructForConditionalGeneration
3
+ from PIL import Image
4
+ import torch
5
+
6
+ # Load model & processor
7
+ processor = Pix2StructProcessor.from_pretrained("google/deplot")
8
+ model = Pix2StructForConditionalGeneration.from_pretrained("google/deplot")
9
+
10
+ # Move model to GPU if available
11
+ device = "cuda" if torch.cuda.is_available() else "cpu"
12
+ model.to(device)
13
+
14
+ def extract_chart_data(img: Image.Image):
15
+ inputs = processor(images=img, return_tensors="pt").to(device)
16
+ outputs = model.generate(**inputs)
17
+ result = processor.decode(outputs[0], skip_special_tokens=True)
18
+ return result
19
+
20
+ # Gradio interface
21
+ iface = gr.Interface(
22
+ fn=extract_chart_data,
23
+ inputs=gr.Image(type="pil"),
24
+ outputs="text",
25
+ title="DePlot Chart Data Extractor",
26
+ description="Upload a chart image and get its extracted data/description."
27
+ )
28
+
29
+ iface.launch()