-
Notifications
You must be signed in to change notification settings - Fork 37
/
display_uigraph.py
45 lines (40 loc) · 1.1 KB
/
display_uigraph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import re
import time
from qwen_vl_utils import process_vision_info
from showui.processing_showui import ShowUIProcessor
min_pixels = 256*28*28
max_pixels = 1344*28*28
processor = ShowUIProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
# The input images for ui_graph preprocessing
img_url = 'examples/0730d43001da36204b8cb9495b61308.png'
# The dir to save images with ui_graph visualization
vis_dir = '.'
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": img_url,
"min_pixels": min_pixels,
"max_pixels": max_pixels,
},
],
}
]
# Preparation for inference
text = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
text=[text],
images=image_inputs,
videos=video_inputs,
padding=True,
return_tensors="pt",
ui_graph=True,
ui_graph_threshold=1,
ui_graph_vis_dir=vis_dir,
)