sujr commited on
Commit
e998d9d
·
1 Parent(s): 32e07da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -1,6 +1,17 @@
1
  import gradio as gr
 
 
 
 
 
 
2
 
3
  def run(image):
4
- return type(image)
 
 
 
 
 
5
 
6
  gr.Interface(fn=run, inputs="image", outputs="text").launch()
 
1
  import gradio as gr
2
+ import numpy as np
3
+ from PIL import Image
4
+ from transformers import Pix2StructForConditionalGeneration, Pix2StructProcessor
5
+
6
+ model = Pix2StructForConditionalGeneration.from_pretrained("sujr/pix2struct-base")
7
+ processor = Pix2StructProcessor.from_pretrained("sujr/pix2struct-base")
8
 
9
  def run(image):
10
+ image = Image.fromarray(image)
11
+ inputs = processor(images=image, return_tensors="pt")
12
+ generated_ids = model.generate(**inputs)
13
+ generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
14
+
15
+ return generated_text
16
 
17
  gr.Interface(fn=run, inputs="image", outputs="text").launch()