Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,17 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
def run(image):
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
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()
|