Views
No views yet
transformers library and other dependencies as described in the GitHub repository:pip install git+https://github.com/huggingface/transformers accelerate torch torchvision openai pillow tqdm nltk scipySky-VLM model:1from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
2from qwen_vl_utils import process_vision_info # Note: qwen_vl_utils might need to be installed separately or adapted
3
4# Default: Load the model on the available device(s)
5model = Qwen2VLForConditionalGeneration.from_pretrained(
6 "llxs/Sky-VLM", torch_dtype="auto", device_map="auto"
7)
8processor = AutoProcessor.from_pretrained("llxs/Sky-VLM")
9
10messages = [
11 {
12 "role": "user",
13 "content": [
14 {
15 "type": "image",
16 "image": "./examples/images/web_6f93090a-81f6-489e-bb35-1a2838b18c01.png", # Placeholder image path
17 },
18 {"type": "text", "text": "In this UI screenshot, what is the position of the element corresponding to the command \\\"switch language of current page\\\" (with bbox)?"},
19 ],
20 }
21]
22
23
24# Preparation for inference
25text = processor.apply_chat_template(
26 messages, tokenize=False, add_generation_prompt=True
27)
28# Assuming process_vision_info is available from qwen_vl_utils or a similar helper
29# For a minimal example, image_inputs can be directly a list of PIL Images or similar
30# If qwen_vl_utils is not installed, manual processing might be needed.
31# For simplicity, if this exact helper isn't critical for basic HF inference, we might skip/adapt.
32# Here, we assume its presence for direct copy.
33image_inputs, video_inputs = process_vision_info(messages) # Requires qwen_vl_utils for this exact function
34inputs = processor(
35 text=[text],
36 images=image_inputs,
37 videos=video_inputs,
38 padding=True,
39 return_tensors="pt",
40)
41inputs = inputs.to("cuda")
42
43# Inference: Generation of the output
44generated_ids = model.generate(**inputs, max_new_tokens=128)
45
46generated_ids_trimmed = [
47 out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
48]
49
50output_text = processor.batch_decode(
51 generated_ids_trimmed, skip_special_tokens=False, clean_up_tokenization_spaces=False
52)
53print(output_text)
54# Expected output example: <|object_ref_start|>language switch<|object_ref_end|><|box_start|>(576,12),(592,42)<|box_end|><|im_end|>