Spaces:
Running
on
Zero
Running
on
Zero
Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- .gradio/certificate.pem +31 -0
- app.py +247 -0
- app_legacy.py +128 -0
- assets/showui.png +0 -0
- examples/apple_music.png +0 -0
- examples/safari_google.png +3 -0
- requirements.txt +1 -0
- showui-2b/.gitattributes +35 -0
- showui-2b/README.md +188 -0
- showui-2b/added_tokens.json +16 -0
- showui-2b/config.json +48 -0
- showui-2b/examples/0730d43001da36204b8cb9495b61308.png +0 -0
- showui-2b/examples/chrome.png +0 -0
- showui-2b/examples/showui.png +0 -0
- showui-2b/generation_config.json +14 -0
- showui-2b/merges.txt +0 -0
- showui-2b/preprocessor_config.json +29 -0
- showui-2b/pytorch_model.bin +3 -0
- showui-2b/special_tokens_map.json +24 -0
- showui-2b/tokenizer.json +0 -0
- showui-2b/tokenizer_config.json +144 -0
- showui-2b/vocab.json +0 -0
- votes.json +0 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
examples/safari_google.png filter=lfs diff=lfs merge=lfs -text
|
.gradio/certificate.pem
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-----BEGIN CERTIFICATE-----
|
2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQ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radio as gr
|
5 |
+
import torch
|
6 |
+
from PIL import Image, ImageDraw
|
7 |
+
from qwen_vl_utils import process_vision_info
|
8 |
+
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
|
9 |
+
import ast
|
10 |
+
import os
|
11 |
+
from datetime import datetime
|
12 |
+
import numpy as np
|
13 |
+
|
14 |
+
# Define constants
|
15 |
+
DESCRIPTION = "[ShowUI-2B Demo](https://huggingface.co/showlab/ShowUI-2B)"
|
16 |
+
_SYSTEM = "Based on the screenshot of the page, I give a text description and you give its corresponding location. The coordinate represents a clickable location [x, y] for an element, which is a relative coordinate on the screenshot, scaled from 0 to 1."
|
17 |
+
MIN_PIXELS = 256 * 28 * 28
|
18 |
+
MAX_PIXELS = 1344 * 28 * 28
|
19 |
+
|
20 |
+
# Load the model
|
21 |
+
model = Qwen2VLForConditionalGeneration.from_pretrained(
|
22 |
+
"/users/difei/siyuan/showui_demo/showui-2b",
|
23 |
+
torch_dtype=torch.bfloat16,
|
24 |
+
device_map="auto",
|
25 |
+
)
|
26 |
+
|
27 |
+
# Load the processor
|
28 |
+
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct", min_pixels=MIN_PIXELS, max_pixels=MAX_PIXELS)
|
29 |
+
|
30 |
+
# Helper functions
|
31 |
+
def draw_point(image_input, point=None, radius=5):
|
32 |
+
"""Draw a point on the image."""
|
33 |
+
if isinstance(image_input, str):
|
34 |
+
image = Image.open(image_input)
|
35 |
+
else:
|
36 |
+
image = Image.fromarray(np.uint8(image_input))
|
37 |
+
|
38 |
+
if point:
|
39 |
+
x, y = point[0] * image.width, point[1] * image.height
|
40 |
+
ImageDraw.Draw(image).ellipse((x - radius, y - radius, x + radius, y + radius), fill='red')
|
41 |
+
return image
|
42 |
+
|
43 |
+
def array_to_image_path(image_array):
|
44 |
+
"""Save the uploaded image and return its path."""
|
45 |
+
if image_array is None:
|
46 |
+
raise ValueError("No image provided. Please upload an image before submitting.")
|
47 |
+
img = Image.fromarray(np.uint8(image_array))
|
48 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
49 |
+
filename = f"image_{timestamp}.png"
|
50 |
+
img.save(filename)
|
51 |
+
return os.path.abspath(filename)
|
52 |
+
|
53 |
+
def run_showui(image, query):
|
54 |
+
"""Main function for inference."""
|
55 |
+
image_path = array_to_image_path(image)
|
56 |
+
|
57 |
+
messages = [
|
58 |
+
{
|
59 |
+
"role": "user",
|
60 |
+
"content": [
|
61 |
+
{"type": "text", "text": _SYSTEM},
|
62 |
+
{"type": "image", "image": image_path, "min_pixels": MIN_PIXELS, "max_pixels": MAX_PIXELS},
|
63 |
+
{"type": "text", "text": query}
|
64 |
+
],
|
65 |
+
}
|
66 |
+
]
|
67 |
+
|
68 |
+
# Prepare inputs for the model
|
69 |
+
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
70 |
+
image_inputs, video_inputs = process_vision_info(messages)
|
71 |
+
inputs = processor(
|
72 |
+
text=[text],
|
73 |
+
images=image_inputs,
|
74 |
+
videos=video_inputs,
|
75 |
+
padding=True,
|
76 |
+
return_tensors="pt"
|
77 |
+
)
|
78 |
+
inputs = inputs.to("cuda")
|
79 |
+
|
80 |
+
# Generate output
|
81 |
+
generated_ids = model.generate(**inputs, max_new_tokens=128)
|
82 |
+
generated_ids_trimmed = [
|
83 |
+
out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
84 |
+
]
|
85 |
+
output_text = processor.batch_decode(
|
86 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
87 |
+
)[0]
|
88 |
+
|
89 |
+
# Parse the output into coordinates
|
90 |
+
click_xy = ast.literal_eval(output_text)
|
91 |
+
|
92 |
+
# Draw the point on the image
|
93 |
+
result_image = draw_point(image_path, click_xy, radius=10)
|
94 |
+
return result_image, str(click_xy)
|
95 |
+
|
96 |
+
# Function to record votes
|
97 |
+
def record_vote(vote_type, image_path, query, action_generated):
|
98 |
+
"""Record a vote in a JSON file."""
|
99 |
+
vote_data = {
|
100 |
+
"vote_type": vote_type,
|
101 |
+
"image_path": image_path,
|
102 |
+
"query": query,
|
103 |
+
"action_generated": action_generated,
|
104 |
+
"timestamp": datetime.now().isoformat()
|
105 |
+
}
|
106 |
+
with open("votes.json", "a") as f:
|
107 |
+
f.write(json.dumps(vote_data) + "\n")
|
108 |
+
return f"Your {vote_type} has been recorded. Thank you!"
|
109 |
+
|
110 |
+
# Helper function to handle vote recording
|
111 |
+
def handle_vote(vote_type, image_path, query, action_generated):
|
112 |
+
"""Handle vote recording by using the consistent image path."""
|
113 |
+
if image_path is None:
|
114 |
+
return "No image uploaded. Please upload an image before voting."
|
115 |
+
return record_vote(vote_type, image_path, query, action_generated)
|
116 |
+
|
117 |
+
# Load logo and encode to Base64
|
118 |
+
with open("./assets/showui.png", "rb") as image_file:
|
119 |
+
base64_image = base64.b64encode(image_file.read()).decode("utf-8")
|
120 |
+
|
121 |
+
|
122 |
+
# Define layout and UI
|
123 |
+
def build_demo(embed_mode, concurrency_count=1):
|
124 |
+
with gr.Blocks(title="ShowUI-2B Demo", theme=gr.themes.Default()) as demo:
|
125 |
+
# State to store the consistent image path
|
126 |
+
state_image_path = gr.State(value=None)
|
127 |
+
|
128 |
+
if not embed_mode:
|
129 |
+
# Replace the original description with new content
|
130 |
+
gr.HTML(
|
131 |
+
f"""
|
132 |
+
<div style="display: flex; align-items: center; justify-content: center; margin-bottom: 20px;">
|
133 |
+
<!-- Logo on the left -->
|
134 |
+
<a href="https://github.com/showlab/ShowUI" target="_blank" style="margin-right: 20px;">
|
135 |
+
<img src="data:image/png;base64,{base64_image}" alt="ShowUI Logo" style="width: auto; height: 66px;"/>
|
136 |
+
</a>
|
137 |
+
<!-- Links on the right -->
|
138 |
+
<div style="display: flex; gap: 15px; font-size: 20px;">
|
139 |
+
<a href="https://github.com/showlab/ShowUI" target="_blank">🏠[Project Homepage]</a>
|
140 |
+
<a href="https://github.com/showlab/ShowUI" target="_blank">🤖[Code]</a>
|
141 |
+
<a href="https://huggingface.co/showlab/ShowUI-2B" target="_blank">😊[Model]</a>
|
142 |
+
<a href="https://arxiv.org/" target="_blank">📚[Paper]</a>
|
143 |
+
</div>
|
144 |
+
</div>
|
145 |
+
"""
|
146 |
+
)
|
147 |
+
|
148 |
+
with gr.Row():
|
149 |
+
with gr.Column(scale=3):
|
150 |
+
# Input components
|
151 |
+
imagebox = gr.Image(type="numpy", label="Input Screenshot")
|
152 |
+
textbox = gr.Textbox(
|
153 |
+
show_label=True,
|
154 |
+
placeholder="Enter a query (e.g., 'Click Nahant')",
|
155 |
+
label="Query",
|
156 |
+
)
|
157 |
+
submit_btn = gr.Button(value="Submit", variant="primary")
|
158 |
+
|
159 |
+
# Placeholder examples
|
160 |
+
gr.Examples(
|
161 |
+
examples=[
|
162 |
+
["./examples/safari_google.png", "Click on search bar."],
|
163 |
+
["./examples/apple_music.png", "Click on star."],
|
164 |
+
],
|
165 |
+
inputs=[imagebox, textbox],
|
166 |
+
examples_per_page=2
|
167 |
+
)
|
168 |
+
|
169 |
+
with gr.Column(scale=8):
|
170 |
+
# Output components
|
171 |
+
output_img = gr.Image(type="pil", label="Output Image")
|
172 |
+
output_coords = gr.Textbox(label="Clickable Coordinates")
|
173 |
+
|
174 |
+
# Buttons for voting, flagging, regenerating, and clearing
|
175 |
+
with gr.Row(elem_id="action-buttons", equal_height=True):
|
176 |
+
vote_btn = gr.Button(value="👍 Vote", variant="secondary")
|
177 |
+
downvote_btn = gr.Button(value="👎 Downvote", variant="secondary")
|
178 |
+
flag_btn = gr.Button(value="🚩 Flag", variant="secondary")
|
179 |
+
regenerate_btn = gr.Button(value="🔄 Regenerate", variant="secondary")
|
180 |
+
clear_btn = gr.Button(value="🗑️ Clear", interactive=True) # Combined Clear button
|
181 |
+
|
182 |
+
# Define button actions
|
183 |
+
def on_submit(image, query):
|
184 |
+
"""Handle the submit button click."""
|
185 |
+
if image is None:
|
186 |
+
raise ValueError("No image provided. Please upload an image before submitting.")
|
187 |
+
|
188 |
+
# Generate consistent image path and store it in the state
|
189 |
+
image_path = array_to_image_path(image)
|
190 |
+
return run_showui(image, query) + (image_path,)
|
191 |
+
|
192 |
+
submit_btn.click(
|
193 |
+
on_submit,
|
194 |
+
[imagebox, textbox],
|
195 |
+
[output_img, output_coords, state_image_path],
|
196 |
+
)
|
197 |
+
|
198 |
+
clear_btn.click(
|
199 |
+
lambda: (None, None, None, None, None),
|
200 |
+
inputs=None,
|
201 |
+
outputs=[imagebox, textbox, output_img, output_coords, state_image_path], # Clear all outputs
|
202 |
+
queue=False
|
203 |
+
)
|
204 |
+
|
205 |
+
regenerate_btn.click(
|
206 |
+
lambda image, query, state_image_path: run_showui(image, query),
|
207 |
+
[imagebox, textbox, state_image_path],
|
208 |
+
[output_img, output_coords],
|
209 |
+
)
|
210 |
+
|
211 |
+
# Record vote actions without feedback messages
|
212 |
+
vote_btn.click(
|
213 |
+
lambda image_path, query, action_generated: handle_vote(
|
214 |
+
"upvote", image_path, query, action_generated
|
215 |
+
),
|
216 |
+
inputs=[state_image_path, textbox, output_coords],
|
217 |
+
outputs=[],
|
218 |
+
queue=False
|
219 |
+
)
|
220 |
+
|
221 |
+
downvote_btn.click(
|
222 |
+
lambda image_path, query, action_generated: handle_vote(
|
223 |
+
"downvote", image_path, query, action_generated
|
224 |
+
),
|
225 |
+
inputs=[state_image_path, textbox, output_coords],
|
226 |
+
outputs=[],
|
227 |
+
queue=False
|
228 |
+
)
|
229 |
+
|
230 |
+
flag_btn.click(
|
231 |
+
lambda image_path, query, action_generated: handle_vote(
|
232 |
+
"flag", image_path, query, action_generated
|
233 |
+
),
|
234 |
+
inputs=[state_image_path, textbox, output_coords],
|
235 |
+
outputs=[],
|
236 |
+
queue=False
|
237 |
+
)
|
238 |
+
|
239 |
+
return demo
|
240 |
+
# Launch the app
|
241 |
+
if __name__ == "__main__":
|
242 |
+
demo = build_demo(embed_mode=False)
|
243 |
+
demo.queue(api_open=False).launch(
|
244 |
+
server_name="0.0.0.0",
|
245 |
+
server_port=7860,
|
246 |
+
share=True
|
247 |
+
)
|
app_legacy.py
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import base64
|
2 |
+
import gradio as gr
|
3 |
+
import torch
|
4 |
+
from PIL import Image, ImageDraw
|
5 |
+
from qwen_vl_utils import process_vision_info
|
6 |
+
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
|
7 |
+
import ast
|
8 |
+
import os
|
9 |
+
from datetime import datetime
|
10 |
+
import numpy as np
|
11 |
+
|
12 |
+
# Function to draw a point on the image
|
13 |
+
def draw_point(image_input, point=None, radius=5):
|
14 |
+
if isinstance(image_input, str):
|
15 |
+
image = Image.open(image_input)
|
16 |
+
else:
|
17 |
+
image = Image.fromarray(np.uint8(image_input))
|
18 |
+
|
19 |
+
if point:
|
20 |
+
x, y = point[0] * image.width, point[1] * image.height
|
21 |
+
ImageDraw.Draw(image).ellipse((x - radius, y - radius, x + radius, y + radius), fill='red')
|
22 |
+
return image
|
23 |
+
|
24 |
+
# Function to save the uploaded image and return its path
|
25 |
+
def array_to_image_path(image_array):
|
26 |
+
if image_array is None:
|
27 |
+
raise ValueError("No image provided. Please upload an image before submitting.")
|
28 |
+
img = Image.fromarray(np.uint8(image_array))
|
29 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
30 |
+
filename = f"image_{timestamp}.png"
|
31 |
+
img.save(filename)
|
32 |
+
return os.path.abspath(filename)
|
33 |
+
|
34 |
+
# Load the model
|
35 |
+
model = Qwen2VLForConditionalGeneration.from_pretrained(
|
36 |
+
# "./showui-2b",
|
37 |
+
"/users/difei/siyuan/showui_demo/showui-2b",
|
38 |
+
torch_dtype=torch.bfloat16,
|
39 |
+
device_map="auto",
|
40 |
+
# verbose=True,
|
41 |
+
)
|
42 |
+
|
43 |
+
# Define minimum and maximum pixel thresholds
|
44 |
+
min_pixels = 256 * 28 * 28
|
45 |
+
max_pixels = 1344 * 28 * 28
|
46 |
+
|
47 |
+
# Load the processor
|
48 |
+
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
|
49 |
+
|
50 |
+
# Hugging Face Space description
|
51 |
+
DESCRIPTION = "[ShowUI-2B Demo](https://huggingface.co/showlab/ShowUI-2B)"
|
52 |
+
|
53 |
+
# Define the system instruction
|
54 |
+
_SYSTEM = "Based on the screenshot of the page, I give a text description and you give its corresponding location. The coordinate represents a clickable location [x, y] for an element, which is a relative coordinate on the screenshot, scaled from 0 to 1."
|
55 |
+
|
56 |
+
# Define the main function for inference
|
57 |
+
def run_showui(image, query):
|
58 |
+
image_path = array_to_image_path(image)
|
59 |
+
|
60 |
+
messages = [
|
61 |
+
{
|
62 |
+
"role": "user",
|
63 |
+
"content": [
|
64 |
+
{"type": "text", "text": _SYSTEM},
|
65 |
+
{"type": "image", "image": image_path, "min_pixels": min_pixels, "max_pixels": max_pixels},
|
66 |
+
{"type": "text", "text": query}
|
67 |
+
],
|
68 |
+
}
|
69 |
+
]
|
70 |
+
|
71 |
+
# Prepare inputs for the model
|
72 |
+
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
73 |
+
image_inputs, video_inputs = process_vision_info(messages)
|
74 |
+
inputs = processor(
|
75 |
+
text=[text],
|
76 |
+
images=image_inputs,
|
77 |
+
videos=video_inputs,
|
78 |
+
padding=True,
|
79 |
+
return_tensors="pt"
|
80 |
+
)
|
81 |
+
inputs = inputs.to("cuda")
|
82 |
+
|
83 |
+
# Generate output
|
84 |
+
generated_ids = model.generate(**inputs, max_new_tokens=128)
|
85 |
+
generated_ids_trimmed = [
|
86 |
+
out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
87 |
+
]
|
88 |
+
output_text = processor.batch_decode(
|
89 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
90 |
+
)[0]
|
91 |
+
|
92 |
+
# Parse the output into coordinates
|
93 |
+
click_xy = ast.literal_eval(output_text)
|
94 |
+
|
95 |
+
# Draw the point on the image
|
96 |
+
result_image = draw_point(image_path, click_xy, radius=10)
|
97 |
+
return result_image, str(click_xy)
|
98 |
+
|
99 |
+
with open("./assets/showui.png", "rb") as image_file:
|
100 |
+
base64_image = base64.b64encode(image_file.read()).decode("utf-8")
|
101 |
+
|
102 |
+
# Gradio UI
|
103 |
+
with gr.Blocks() as demo:
|
104 |
+
gr.HTML(
|
105 |
+
f"""
|
106 |
+
<div style="text-align: center; margin-bottom: 20px;">
|
107 |
+
<a href="https://github.com/showlab/ShowUI" target="_blank">
|
108 |
+
<img src="data:image/png;base64,{base64_image}" alt="ShowUI Logo" style="width: 200px; height: auto;"/>
|
109 |
+
</a>
|
110 |
+
</div>
|
111 |
+
"""
|
112 |
+
)
|
113 |
+
|
114 |
+
gr.Markdown(DESCRIPTION)
|
115 |
+
with gr.Tab(label="ShowUI-2B Input"):
|
116 |
+
with gr.Row():
|
117 |
+
with gr.Column():
|
118 |
+
input_img = gr.Image(label="Input Screenshot")
|
119 |
+
text_input = gr.Textbox(label="Query (e.g., 'Click Nahant')")
|
120 |
+
submit_btn = gr.Button(value="Submit")
|
121 |
+
with gr.Column():
|
122 |
+
output_img = gr.Image(label="Output Image")
|
123 |
+
output_coords = gr.Textbox(label="Clickable Coordinates")
|
124 |
+
|
125 |
+
submit_btn.click(run_showui, [input_img, text_input], [output_img, output_coords])
|
126 |
+
|
127 |
+
demo.queue(api_open=False)
|
128 |
+
demo.launch()
|
assets/showui.png
ADDED
examples/apple_music.png
ADDED
examples/safari_google.png
ADDED
Git LFS Details
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
qwen-vl-utils==0.0.8
|
showui-2b/.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
showui-2b/README.md
ADDED
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- GUI agents
|
4 |
+
- vision-language-action model
|
5 |
+
- computer use
|
6 |
+
---
|
7 |
+
[Github](https://github.com/showlab/ShowUI/tree/main) | [Quick Start](https://huggingface.co/showlab/ShowUI-2B)
|
8 |
+
<img src="examples/showui.png" alt="ShowUI" width="640">
|
9 |
+
|
10 |
+
ShowUI is a lightweight (2B) vision-language-action model designed for GUI agents.
|
11 |
+
[![demo](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Models-blue)](https://huggingface.co/showlab/ShowUI-2B)
|
12 |
+
## ⭐ Quick Start
|
13 |
+
|
14 |
+
1. Load model
|
15 |
+
```python
|
16 |
+
import ast
|
17 |
+
import torch
|
18 |
+
from PIL import Image, ImageDraw
|
19 |
+
from qwen_vl_utils import process_vision_info
|
20 |
+
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
|
21 |
+
|
22 |
+
def draw_point(image_input, point=None, radius=5):
|
23 |
+
if isinstance(image_input, str):
|
24 |
+
image = Image.open(BytesIO(requests.get(image_input).content)) if image_input.startswith('http') else Image.open(image_input)
|
25 |
+
else:
|
26 |
+
image = image_input
|
27 |
+
|
28 |
+
if point:
|
29 |
+
x, y = point[0] * image.width, point[1] * image.height
|
30 |
+
ImageDraw.Draw(image).ellipse((x - radius, y - radius, x + radius, y + radius), fill='red')
|
31 |
+
display(image)
|
32 |
+
return
|
33 |
+
|
34 |
+
model = Qwen2VLForConditionalGeneration.from_pretrained(
|
35 |
+
"showlab/ShowUI-2B",
|
36 |
+
torch_dtype=torch.bfloat16,
|
37 |
+
device_map="auto"
|
38 |
+
)
|
39 |
+
|
40 |
+
min_pixels = 256*28*28
|
41 |
+
max_pixels = 1344*28*28
|
42 |
+
|
43 |
+
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
|
44 |
+
```
|
45 |
+
|
46 |
+
2. **UI Grounding**
|
47 |
+
```python
|
48 |
+
img_url = 'examples/web_dbd7514b-9ca3-40cd-b09a-990f7b955da1.png'
|
49 |
+
query = "Nahant"
|
50 |
+
|
51 |
+
|
52 |
+
_SYSTEM = "Based on the screenshot of the page, I give a text description and you give its corresponding location. The coordinate represents a clickable location [x, y] for an element, which is a relative coordinate on the screenshot, scaled from 0 to 1."
|
53 |
+
messages = [
|
54 |
+
{
|
55 |
+
"role": "user",
|
56 |
+
"content": [
|
57 |
+
{"type": "text", "text": _SYSTEM},
|
58 |
+
{"type": "image", "image": img_url, "min_pixels": min_pixels, "max_pixels": max_pixels},
|
59 |
+
{"type": "text", "text": query}
|
60 |
+
],
|
61 |
+
}
|
62 |
+
]
|
63 |
+
|
64 |
+
text = processor.apply_chat_template(
|
65 |
+
messages, tokenize=False, add_generation_prompt=True,
|
66 |
+
)
|
67 |
+
image_inputs, video_inputs = process_vision_info(messages)
|
68 |
+
inputs = processor(
|
69 |
+
text=[text],
|
70 |
+
images=image_inputs,
|
71 |
+
videos=video_inputs,
|
72 |
+
padding=True,
|
73 |
+
return_tensors="pt",
|
74 |
+
)
|
75 |
+
inputs = inputs.to("cuda")
|
76 |
+
|
77 |
+
generated_ids = model.generate(**inputs, max_new_tokens=128)
|
78 |
+
generated_ids_trimmed = [
|
79 |
+
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
80 |
+
]
|
81 |
+
output_text = processor.batch_decode(
|
82 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
83 |
+
)[0]
|
84 |
+
|
85 |
+
click_xy = ast.literal_eval(output_text)
|
86 |
+
# [0.73, 0.21]
|
87 |
+
|
88 |
+
draw_point(img_url, click_xy, 10)
|
89 |
+
```
|
90 |
+
|
91 |
+
This will visualize the grounding results like (where the red points are [x,y])
|
92 |
+
|
93 |
+
![download](https://github.com/user-attachments/assets/8fe2783d-05b6-44e6-a26c-8718d02b56cb)
|
94 |
+
|
95 |
+
3. **UI Navigation**
|
96 |
+
- Set up system prompt.
|
97 |
+
```python
|
98 |
+
_NAV_SYSTEM = """You are an assistant trained to navigate the {_APP} screen.
|
99 |
+
Given a task instruction, a screen observation, and an action history sequence,
|
100 |
+
output the next action and wait for the next observation.
|
101 |
+
Here is the action space:
|
102 |
+
{_ACTION_SPACE}
|
103 |
+
"""
|
104 |
+
|
105 |
+
_NAV_FORMAT = """
|
106 |
+
Format the action as a dictionary with the following keys:
|
107 |
+
{'action': 'ACTION_TYPE', 'value': 'element', 'position': [x,y]}
|
108 |
+
|
109 |
+
If value or position is not applicable, set it as `None`.
|
110 |
+
Position might be [[x1,y1], [x2,y2]] if the action requires a start and end position.
|
111 |
+
Position represents the relative coordinates on the screenshot and should be scaled to a range of 0-1.
|
112 |
+
"""
|
113 |
+
|
114 |
+
action_map = {
|
115 |
+
'web': """
|
116 |
+
1. `CLICK`: Click on an element, value is not applicable and the position [x,y] is required.
|
117 |
+
2. `INPUT`: Type a string into an element, value is a string to type and the position [x,y] is required.
|
118 |
+
3. `SELECT`: Select a value for an element, value is not applicable and the position [x,y] is required.
|
119 |
+
4. `HOVER`: Hover on an element, value is not applicable and the position [x,y] is required.
|
120 |
+
5. `ANSWER`: Answer the question, value is the answer and the position is not applicable.
|
121 |
+
6. `ENTER`: Enter operation, value and position are not applicable.
|
122 |
+
7. `SCROLL`: Scroll the screen, value is the direction to scroll and the position is not applicable.
|
123 |
+
8. `SELECT_TEXT`: Select some text content, value is not applicable and position [[x1,y1], [x2,y2]] is the start and end position of the select operation.
|
124 |
+
9. `COPY`: Copy the text, value is the text to copy and the position is not applicable.
|
125 |
+
""",
|
126 |
+
|
127 |
+
'phone': """
|
128 |
+
1. `INPUT`: Type a string into an element, value is not applicable and the position [x,y] is required.
|
129 |
+
2. `SWIPE`: Swipe the screen, value is not applicable and the position [[x1,y1], [x2,y2]] is the start and end position of the swipe operation.
|
130 |
+
3. `TAP`: Tap on an element, value is not applicable and the position [x,y] is required.
|
131 |
+
4. `ANSWER`: Answer the question, value is the status (e.g., 'task complete') and the position is not applicable.
|
132 |
+
5. `ENTER`: Enter operation, value and position are not applicable.
|
133 |
+
"""
|
134 |
+
}
|
135 |
+
|
136 |
+
_NAV_USER = """{system}
|
137 |
+
Task: {task}
|
138 |
+
Observation: <|image_1|>
|
139 |
+
Action History: {action_history}
|
140 |
+
What is the next action?
|
141 |
+
"""
|
142 |
+
```
|
143 |
+
|
144 |
+
```python
|
145 |
+
img_url = 'examples/chrome.png'
|
146 |
+
split='web'
|
147 |
+
system_prompt = _NAV_SYSTEM.format(_APP=split, _ACTION_SPACE=action_map[split])
|
148 |
+
query = "Search the weather for the New York city."
|
149 |
+
|
150 |
+
messages = [
|
151 |
+
{
|
152 |
+
"role": "user",
|
153 |
+
"content": [
|
154 |
+
{"type": "text", "text": system_prompt},
|
155 |
+
{"type": "image", "image": img_url, "min_pixels": min_pixels, "max_pixels": max_pixels},
|
156 |
+
{"type": "text", "text": query}
|
157 |
+
],
|
158 |
+
}
|
159 |
+
]
|
160 |
+
|
161 |
+
text = processor.apply_chat_template(
|
162 |
+
messages, tokenize=False, add_generation_prompt=True,
|
163 |
+
)
|
164 |
+
image_inputs, video_inputs = process_vision_info(messages)
|
165 |
+
inputs = processor(
|
166 |
+
text=[text],
|
167 |
+
images=image_inputs,
|
168 |
+
videos=video_inputs,
|
169 |
+
padding=True,
|
170 |
+
return_tensors="pt",
|
171 |
+
)
|
172 |
+
inputs = inputs.to("cuda")
|
173 |
+
|
174 |
+
generated_ids = model.generate(**inputs, max_new_tokens=128)
|
175 |
+
generated_ids_trimmed = [
|
176 |
+
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
177 |
+
]
|
178 |
+
output_text = processor.batch_decode(
|
179 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
180 |
+
)[0]
|
181 |
+
|
182 |
+
print(output_text)
|
183 |
+
# {'action': 'CLICK', 'value': None, 'position': [0.49, 0.42]},
|
184 |
+
# {'action': 'INPUT', 'value': 'weather for New York city', 'position': [0.49, 0.42]},
|
185 |
+
# {'action': 'ENTER', 'value': None, 'position': None}
|
186 |
+
```
|
187 |
+
|
188 |
+
![download](https://github.com/user-attachments/assets/624097ea-06f2-4c8f-83f6-b6b9ee439c0c)
|
showui-2b/added_tokens.json
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"<|box_end|>": 151649,
|
3 |
+
"<|box_start|>": 151648,
|
4 |
+
"<|endoftext|>": 151643,
|
5 |
+
"<|im_end|>": 151645,
|
6 |
+
"<|im_start|>": 151644,
|
7 |
+
"<|image_pad|>": 151655,
|
8 |
+
"<|object_ref_end|>": 151647,
|
9 |
+
"<|object_ref_start|>": 151646,
|
10 |
+
"<|quad_end|>": 151651,
|
11 |
+
"<|quad_start|>": 151650,
|
12 |
+
"<|video_pad|>": 151656,
|
13 |
+
"<|vision_end|>": 151653,
|
14 |
+
"<|vision_pad|>": 151654,
|
15 |
+
"<|vision_start|>": 151652
|
16 |
+
}
|
showui-2b/config.json
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "Qwen/Qwen2-VL-2B-Instruct",
|
3 |
+
"architectures": [
|
4 |
+
"Qwen2VLForConditionalGeneration"
|
5 |
+
],
|
6 |
+
"attention_dropout": 0.0,
|
7 |
+
"bos_token_id": 151643,
|
8 |
+
"eos_token_id": 151645,
|
9 |
+
"hidden_act": "silu",
|
10 |
+
"hidden_size": 1536,
|
11 |
+
"image_token_id": 151655,
|
12 |
+
"initializer_range": 0.02,
|
13 |
+
"intermediate_size": 8960,
|
14 |
+
"max_position_embeddings": 32768,
|
15 |
+
"max_window_layers": 28,
|
16 |
+
"model_type": "qwen2_vl",
|
17 |
+
"num_attention_heads": 12,
|
18 |
+
"num_hidden_layers": 28,
|
19 |
+
"num_key_value_heads": 2,
|
20 |
+
"rms_norm_eps": 1e-06,
|
21 |
+
"rope_scaling": {
|
22 |
+
"mrope_section": [
|
23 |
+
16,
|
24 |
+
24,
|
25 |
+
24
|
26 |
+
],
|
27 |
+
"type": "mrope"
|
28 |
+
},
|
29 |
+
"rope_theta": 1000000.0,
|
30 |
+
"sliding_window": 32768,
|
31 |
+
"tie_word_embeddings": true,
|
32 |
+
"tokenizer_model_max_length": 4096,
|
33 |
+
"torch_dtype": "bfloat16",
|
34 |
+
"transformers_version": "4.45.0.dev0",
|
35 |
+
"use_cache": false,
|
36 |
+
"use_sliding_window": false,
|
37 |
+
"video_token_id": 151656,
|
38 |
+
"vision_config": {
|
39 |
+
"hidden_size": 1536,
|
40 |
+
"in_chans": 3,
|
41 |
+
"model_type": "qwen2_vl",
|
42 |
+
"spatial_patch_size": 14
|
43 |
+
},
|
44 |
+
"vision_end_token_id": 151653,
|
45 |
+
"vision_start_token_id": 151652,
|
46 |
+
"vision_token_id": 151654,
|
47 |
+
"vocab_size": 151936
|
48 |
+
}
|
showui-2b/examples/0730d43001da36204b8cb9495b61308.png
ADDED
showui-2b/examples/chrome.png
ADDED
showui-2b/examples/showui.png
ADDED
showui-2b/generation_config.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_attn_implementation": "eager",
|
3 |
+
"bos_token_id": 151643,
|
4 |
+
"do_sample": true,
|
5 |
+
"eos_token_id": [
|
6 |
+
151645,
|
7 |
+
151643
|
8 |
+
],
|
9 |
+
"pad_token_id": 151643,
|
10 |
+
"temperature": 0.01,
|
11 |
+
"top_k": 1,
|
12 |
+
"top_p": 0.001,
|
13 |
+
"transformers_version": "4.45.0.dev0"
|
14 |
+
}
|
showui-2b/merges.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
showui-2b/preprocessor_config.json
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"do_convert_rgb": true,
|
3 |
+
"do_normalize": true,
|
4 |
+
"do_rescale": true,
|
5 |
+
"do_resize": true,
|
6 |
+
"image_mean": [
|
7 |
+
0.48145466,
|
8 |
+
0.4578275,
|
9 |
+
0.40821073
|
10 |
+
],
|
11 |
+
"image_processor_type": "Qwen2VLImageProcessor",
|
12 |
+
"image_std": [
|
13 |
+
0.26862954,
|
14 |
+
0.26130258,
|
15 |
+
0.27577711
|
16 |
+
],
|
17 |
+
"max_pixels": 12845056,
|
18 |
+
"merge_size": 2,
|
19 |
+
"min_pixels": 3136,
|
20 |
+
"patch_size": 14,
|
21 |
+
"processor_class": "Qwen2VLProcessor",
|
22 |
+
"resample": 3,
|
23 |
+
"rescale_factor": 0.00392156862745098,
|
24 |
+
"size": {
|
25 |
+
"max_pixels": 12845056,
|
26 |
+
"min_pixels": 3136
|
27 |
+
},
|
28 |
+
"temporal_patch_size": 2
|
29 |
+
}
|
showui-2b/pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:68080df785764e98976eb9cc93a07c6c69cf8a6933738496e02aef55b53d2aa3
|
3 |
+
size 4418202778
|
showui-2b/special_tokens_map.json
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"additional_special_tokens": [
|
3 |
+
"<|im_start|>",
|
4 |
+
"<|im_end|>",
|
5 |
+
"<|object_ref_start|>",
|
6 |
+
"<|object_ref_end|>",
|
7 |
+
"<|box_start|>",
|
8 |
+
"<|box_end|>",
|
9 |
+
"<|quad_start|>",
|
10 |
+
"<|quad_end|>",
|
11 |
+
"<|vision_start|>",
|
12 |
+
"<|vision_end|>",
|
13 |
+
"<|vision_pad|>",
|
14 |
+
"<|image_pad|>",
|
15 |
+
"<|video_pad|>"
|
16 |
+
],
|
17 |
+
"eos_token": {
|
18 |
+
"content": "<|im_end|>",
|
19 |
+
"lstrip": false,
|
20 |
+
"normalized": false,
|
21 |
+
"rstrip": false,
|
22 |
+
"single_word": false
|
23 |
+
}
|
24 |
+
}
|
showui-2b/tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
showui-2b/tokenizer_config.json
ADDED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_prefix_space": false,
|
3 |
+
"added_tokens_decoder": {
|
4 |
+
"151643": {
|
5 |
+
"content": "<|endoftext|>",
|
6 |
+
"lstrip": false,
|
7 |
+
"normalized": false,
|
8 |
+
"rstrip": false,
|
9 |
+
"single_word": false,
|
10 |
+
"special": true
|
11 |
+
},
|
12 |
+
"151644": {
|
13 |
+
"content": "<|im_start|>",
|
14 |
+
"lstrip": false,
|
15 |
+
"normalized": false,
|
16 |
+
"rstrip": false,
|
17 |
+
"single_word": false,
|
18 |
+
"special": true
|
19 |
+
},
|
20 |
+
"151645": {
|
21 |
+
"content": "<|im_end|>",
|
22 |
+
"lstrip": false,
|
23 |
+
"normalized": false,
|
24 |
+
"rstrip": false,
|
25 |
+
"single_word": false,
|
26 |
+
"special": true
|
27 |
+
},
|
28 |
+
"151646": {
|
29 |
+
"content": "<|object_ref_start|>",
|
30 |
+
"lstrip": false,
|
31 |
+
"normalized": false,
|
32 |
+
"rstrip": false,
|
33 |
+
"single_word": false,
|
34 |
+
"special": true
|
35 |
+
},
|
36 |
+
"151647": {
|
37 |
+
"content": "<|object_ref_end|>",
|
38 |
+
"lstrip": false,
|
39 |
+
"normalized": false,
|
40 |
+
"rstrip": false,
|
41 |
+
"single_word": false,
|
42 |
+
"special": true
|
43 |
+
},
|
44 |
+
"151648": {
|
45 |
+
"content": "<|box_start|>",
|
46 |
+
"lstrip": false,
|
47 |
+
"normalized": false,
|
48 |
+
"rstrip": false,
|
49 |
+
"single_word": false,
|
50 |
+
"special": true
|
51 |
+
},
|
52 |
+
"151649": {
|
53 |
+
"content": "<|box_end|>",
|
54 |
+
"lstrip": false,
|
55 |
+
"normalized": false,
|
56 |
+
"rstrip": false,
|
57 |
+
"single_word": false,
|
58 |
+
"special": true
|
59 |
+
},
|
60 |
+
"151650": {
|
61 |
+
"content": "<|quad_start|>",
|
62 |
+
"lstrip": false,
|
63 |
+
"normalized": false,
|
64 |
+
"rstrip": false,
|
65 |
+
"single_word": false,
|
66 |
+
"special": true
|
67 |
+
},
|
68 |
+
"151651": {
|
69 |
+
"content": "<|quad_end|>",
|
70 |
+
"lstrip": false,
|
71 |
+
"normalized": false,
|
72 |
+
"rstrip": false,
|
73 |
+
"single_word": false,
|
74 |
+
"special": true
|
75 |
+
},
|
76 |
+
"151652": {
|
77 |
+
"content": "<|vision_start|>",
|
78 |
+
"lstrip": false,
|
79 |
+
"normalized": false,
|
80 |
+
"rstrip": false,
|
81 |
+
"single_word": false,
|
82 |
+
"special": true
|
83 |
+
},
|
84 |
+
"151653": {
|
85 |
+
"content": "<|vision_end|>",
|
86 |
+
"lstrip": false,
|
87 |
+
"normalized": false,
|
88 |
+
"rstrip": false,
|
89 |
+
"single_word": false,
|
90 |
+
"special": true
|
91 |
+
},
|
92 |
+
"151654": {
|
93 |
+
"content": "<|vision_pad|>",
|
94 |
+
"lstrip": false,
|
95 |
+
"normalized": false,
|
96 |
+
"rstrip": false,
|
97 |
+
"single_word": false,
|
98 |
+
"special": true
|
99 |
+
},
|
100 |
+
"151655": {
|
101 |
+
"content": "<|image_pad|>",
|
102 |
+
"lstrip": false,
|
103 |
+
"normalized": false,
|
104 |
+
"rstrip": false,
|
105 |
+
"single_word": false,
|
106 |
+
"special": true
|
107 |
+
},
|
108 |
+
"151656": {
|
109 |
+
"content": "<|video_pad|>",
|
110 |
+
"lstrip": false,
|
111 |
+
"normalized": false,
|
112 |
+
"rstrip": false,
|
113 |
+
"single_word": false,
|
114 |
+
"special": true
|
115 |
+
}
|
116 |
+
},
|
117 |
+
"additional_special_tokens": [
|
118 |
+
"<|im_start|>",
|
119 |
+
"<|im_end|>",
|
120 |
+
"<|object_ref_start|>",
|
121 |
+
"<|object_ref_end|>",
|
122 |
+
"<|box_start|>",
|
123 |
+
"<|box_end|>",
|
124 |
+
"<|quad_start|>",
|
125 |
+
"<|quad_end|>",
|
126 |
+
"<|vision_start|>",
|
127 |
+
"<|vision_end|>",
|
128 |
+
"<|vision_pad|>",
|
129 |
+
"<|image_pad|>",
|
130 |
+
"<|video_pad|>"
|
131 |
+
],
|
132 |
+
"bos_token": null,
|
133 |
+
"chat_template": "{% set image_count = namespace(value=0) %}{% set video_count = namespace(value=0) %}{% for message in messages %}{% if loop.first and message['role'] != 'system' %}<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n{% endif %}<|im_start|>{{ message['role'] }}\n{% if message['content'] is string %}{{ message['content'] }}<|im_end|>\n{% else %}{% for content in message['content'] %}{% if content['type'] == 'image' or 'image' in content or 'image_url' in content %}{% set image_count.value = image_count.value + 1 %}{% if add_vision_id %}Picture {{ image_count.value }}: {% endif %}<|vision_start|><|image_pad|><|vision_end|>{% elif content['type'] == 'video' or 'video' in content %}{% set video_count.value = video_count.value + 1 %}{% if add_vision_id %}Video {{ video_count.value }}: {% endif %}<|vision_start|><|video_pad|><|vision_end|>{% elif 'text' in content %}{{ content['text'] }}{% endif %}{% endfor %}<|im_end|>\n{% endif %}{% endfor %}{% if add_generation_prompt %}<|im_start|>assistant\n{% endif %}",
|
134 |
+
"clean_up_tokenization_spaces": false,
|
135 |
+
"eos_token": "<|im_end|>",
|
136 |
+
"errors": "replace",
|
137 |
+
"model_max_length": 4096,
|
138 |
+
"pad_token": null,
|
139 |
+
"padding_side": "right",
|
140 |
+
"processor_class": "Qwen2VLProcessor",
|
141 |
+
"split_special_tokens": false,
|
142 |
+
"tokenizer_class": "Qwen2Tokenizer",
|
143 |
+
"unk_token": null
|
144 |
+
}
|
showui-2b/vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
votes.json
ADDED
File without changes
|