AlexHung29629 commited on
Commit
2012122
·
verified ·
1 Parent(s): a9cdb88

Update app.py

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