Update README.md
Browse files
README.md
CHANGED
|
@@ -16,8 +16,14 @@ At runtime, you must:
|
|
| 16 |
3. Parse <tool_call> tags in the model’s output to extract JSON tool calls.
|
| 17 |
|
| 18 |
```python
|
| 19 |
-
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
GroundNext_GROUNDER_SYS_PROMPT = """You are a helpful assistant.
|
| 22 |
|
| 23 |
# Tools
|
|
@@ -34,12 +40,24 @@ For each function call, return a json object with function name and arguments wi
|
|
| 34 |
{{"name": <function-name>, "arguments": <args-json-object>}}
|
| 35 |
</tool_call>"""
|
| 36 |
|
| 37 |
-
|
| 38 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 39 |
-
model =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
image_path = "screenshot.png"
|
| 42 |
-
instruction = "
|
| 43 |
|
| 44 |
|
| 45 |
# inference
|
|
@@ -48,9 +66,8 @@ width, height = image.size
|
|
| 48 |
resized_height, resized_width = smart_resize(
|
| 49 |
height,
|
| 50 |
width,
|
| 51 |
-
min_pixels=
|
| 52 |
max_pixels=6_000_000,
|
| 53 |
-
# max_pixels=2_100_00,
|
| 54 |
)
|
| 55 |
|
| 56 |
image = image.resize((resized_width, resized_height))
|
|
|
|
| 16 |
3. Parse <tool_call> tags in the model’s output to extract JSON tool calls.
|
| 17 |
|
| 18 |
```python
|
| 19 |
+
import torch
|
| 20 |
|
| 21 |
+
from transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer
|
| 22 |
+
from transformers.models.qwen2_vl.image_processing_qwen2_vl_fast import smart_resize
|
| 23 |
+
|
| 24 |
+
from PIL import Image
|
| 25 |
+
|
| 26 |
+
TEMP = 0.0
|
| 27 |
GroundNext_GROUNDER_SYS_PROMPT = """You are a helpful assistant.
|
| 28 |
|
| 29 |
# Tools
|
|
|
|
| 40 |
{{"name": <function-name>, "arguments": <args-json-object>}}
|
| 41 |
</tool_call>"""
|
| 42 |
|
| 43 |
+
model_name = "ServiceNow/GroundNext-7B-V0"
|
| 44 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 45 |
+
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 46 |
+
model_name,
|
| 47 |
+
torch_dtype=torch.bfloat16,
|
| 48 |
+
attn_implementation="flash_attention_2",
|
| 49 |
+
device_map="auto",
|
| 50 |
+
trust_remote_code=True
|
| 51 |
+
).eval()
|
| 52 |
+
processor = AutoProcessor.from_pretrained(model_name)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
model.generation_config.temperature = TEMP
|
| 56 |
+
model.generation_config.do_sample = False if TEMP == 0.0 else True
|
| 57 |
+
model.generation_config.use_cache = True
|
| 58 |
|
| 59 |
+
image_path = "./screenshot.png"
|
| 60 |
+
instruction = "Click on the 'Save' icon"
|
| 61 |
|
| 62 |
|
| 63 |
# inference
|
|
|
|
| 66 |
resized_height, resized_width = smart_resize(
|
| 67 |
height,
|
| 68 |
width,
|
| 69 |
+
min_pixels=78_400,
|
| 70 |
max_pixels=6_000_000,
|
|
|
|
| 71 |
)
|
| 72 |
|
| 73 |
image = image.resize((resized_width, resized_height))
|