AlexHung29629 commited on
Commit
b9f48bf
·
verified ·
1 Parent(s): c2763e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -2,14 +2,18 @@ import spaces
2
  import gradio as gr
3
  from transformers import pipeline
4
  from PIL import Image
 
5
 
6
  # Load model and processor
7
- pipe = pipeline("image-text-to-text", model="google/pix2struct-screen2words-large")
 
 
8
  # Define the function
9
  @spaces.GPU
10
  def describe_ui(image):
11
- outputs = pipe(image, text="describe this image.")
12
- return outputs[0]['generated_text']
 
13
 
14
  # Launch the Gradio interface
15
  gr.Interface(
 
2
  import gradio as gr
3
  from transformers import pipeline
4
  from PIL import Image
5
+ from transformers import Pix2StructForConditionalGeneration, Pix2StructProcessor
6
 
7
  # Load model and processor
8
+ model = Pix2StructForConditionalGeneration.from_pretrained("google/pix2struct-screen2words-large", torch_dtype=torch.bfloat16).to("cuda")
9
+ processor = Pix2StructProcessor.from_pretrained("google/pix2struct-screen2words-large)
10
+
11
  # Define the function
12
  @spaces.GPU
13
  def describe_ui(image):
14
+ inputs = processor(images=image, text="describe this image: ", return_tensors="pt")
15
+ predictions = model.generate(**inputs)
16
+ return processor.decode(predictions[0], skip_special_tokens=True)
17
 
18
  # Launch the Gradio interface
19
  gr.Interface(