Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import Pix2StructProcessor, Pix2StructForConditionalGeneration
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
# Load model and processor
|
| 6 |
+
model = Pix2StructForConditionalGeneration.from_pretrained("google/pix2struct-screen2words-large")
|
| 7 |
+
processor = Pix2StructProcessor.from_pretrained("google/pix2struct-screen2words-large")
|
| 8 |
+
|
| 9 |
+
# Define the function
|
| 10 |
+
def describe_ui(image):
|
| 11 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 12 |
+
outputs = model.generate(**inputs)
|
| 13 |
+
return processor.decode(outputs[0], skip_special_tokens=True)
|
| 14 |
+
|
| 15 |
+
# Launch the Gradio interface
|
| 16 |
+
gr.Interface(
|
| 17 |
+
fn=describe_ui,
|
| 18 |
+
inputs=gr.Image(type="pil"),
|
| 19 |
+
outputs="text",
|
| 20 |
+
title="UI Screen Describer (Pix2Struct)",
|
| 21 |
+
description="Upload a screenshot or UI image and get an automatic description powered by Google’s Pix2Struct model."
|
| 22 |
+
).launch()
|