Update README.md
Browse files
README.md
CHANGED
|
@@ -1,47 +1,204 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
base_model:
|
| 3 |
-
- ByteDance-Seed/UI-TARS-1.5-7B
|
| 4 |
- microsoft/Fara-7B
|
|
|
|
| 5 |
library_name: transformers
|
| 6 |
-
|
| 7 |
-
- mergekit
|
| 8 |
-
- merge
|
| 9 |
-
|
| 10 |
---
|
| 11 |
-
# merged-dare-ties
|
| 12 |
|
| 13 |
-
|
| 14 |
|
| 15 |
-
|
| 16 |
-
### Merge Method
|
| 17 |
|
| 18 |
-
This model
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
|
| 28 |
-
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
models:
|
| 33 |
- model: microsoft/Fara-7B
|
| 34 |
- model: ByteDance-Seed/UI-TARS-1.5-7B
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
base_model: microsoft/Fara-7B
|
| 37 |
-
dtype: bfloat16
|
| 38 |
parameters:
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
- value: [0.1, 0.3, 0.5, 0.3, 0.1]
|
| 45 |
|
|
|
|
| 46 |
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
license: apache-2.0
|
| 5 |
+
tags:
|
| 6 |
+
- merge
|
| 7 |
+
- mergekit
|
| 8 |
+
- dare_ties
|
| 9 |
+
- agent
|
| 10 |
+
- gui-automation
|
| 11 |
+
- vision
|
| 12 |
+
- multimodal
|
| 13 |
+
- far-7b
|
| 14 |
+
- ui-tars
|
| 15 |
base_model:
|
|
|
|
| 16 |
- microsoft/Fara-7B
|
| 17 |
+
- ByteDance-Seed/UI-TARS-1.5-7B
|
| 18 |
library_name: transformers
|
| 19 |
+
pipeline_tag: image-text-to-text
|
|
|
|
|
|
|
|
|
|
| 20 |
---
|
|
|
|
| 21 |
|
| 22 |
+
# Fara-TARS-7B: The Hybrid Reasoning & GUI Agent
|
| 23 |
|
| 24 |
+
**Fara-TARS-7B** is a state-of-the-art merged model that combines the high-level reasoning and planning capabilities of **Microsoft Fara-7B** with the precise GUI grounding and agentic capabilities of **ByteDance UI-TARS-7B**.
|
|
|
|
| 25 |
|
| 26 |
+
This model achieves a **Hybrid Mode**: it can seamlessly switch between writing complex text plans (Reasoning) and executing precise coordinate actions (Agentic Tool Calls) based on the user prompt.
|
| 27 |
|
| 28 |
+
## Key Capabilities
|
| 29 |
|
| 30 |
+
| Capability | Performance | Description |
|
| 31 |
+
| :--- | :--- | :--- |
|
| 32 |
+
| **GUI Grounding** | 🟢 **SOTA** | Accurately maps text instructions to `[x, y]` coordinates (e.g., "Click Submit" -> `[1200, 800]`). |
|
| 33 |
+
| **Reasoning** | 🟢 **Excellent** | Can generate long-form plans (e.g., "Weekly Python Learning Plan") without hallucinating clicks. |
|
| 34 |
+
| **Language** | 🟢 **English-Only** | Tuned to strictly follow English instructions, eliminating language bleeding common in TARS merges. |
|
| 35 |
+
| **Agentic Output** | 🟢 **Structured** | Outputs actions in strict JSON format: `<tool_call>{"name": "click", ...}</tool_call>`. |
|
| 36 |
|
| 37 |
+
## How to Use (Inference Code)
|
| 38 |
|
| 39 |
+
To unlock the full potential of this model (Agent Mode vs Text Mode), **you must use the specific generation configuration below**. This handles the tool schema injection and prevents repetition loops.
|
| 40 |
|
| 41 |
+
### Installation
|
| 42 |
+
```bash
|
| 43 |
+
pip install torch transformers pillow
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
### Python Inference Class
|
| 47 |
+
Use this class to interact with the model. It handles the system prompt injection and JSON parsing automatically.
|
| 48 |
+
|
| 49 |
+
```python
|
| 50 |
+
import torch
|
| 51 |
+
from transformers import AutoModelForVision2Seq, AutoTokenizer, GenerationConfig
|
| 52 |
+
from PIL import Image
|
| 53 |
+
import json
|
| 54 |
+
import re
|
| 55 |
+
|
| 56 |
+
class FaraAgent:
|
| 57 |
+
def __init__(self, model_path, device="auto"):
|
| 58 |
+
print(f"Loading Fara-TARS from {model_path}...")
|
| 59 |
+
self.model = AutoModelForVision2Seq.from_pretrained(
|
| 60 |
+
model_path,
|
| 61 |
+
torch_dtype=torch.bfloat16,
|
| 62 |
+
device_map=device,
|
| 63 |
+
trust_remote_code=True,
|
| 64 |
+
low_cpu_mem_usage=True
|
| 65 |
+
)
|
| 66 |
+
self.tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
| 67 |
+
|
| 68 |
+
# Safety fix for padding
|
| 69 |
+
if self.tokenizer.pad_token is None:
|
| 70 |
+
self.tokenizer.pad_token = self.tokenizer.eos_token
|
| 71 |
+
self.tokenizer.pad_token_id = self.tokenizer.eos_token_id
|
| 72 |
+
|
| 73 |
+
# Define Agent Tools
|
| 74 |
+
self.tools_schema = [
|
| 75 |
+
{"name": "left_click", "description": "Click coordinate [x, y]", "parameters": {"type": "object", "properties": {"point": {"type": "array"}}}},
|
| 76 |
+
{"name": "type_text", "description": "Type text", "parameters": {"type": "object", "properties": {"text": {"type": "string"}}}},
|
| 77 |
+
{"name": "scroll", "description": "Scroll screen", "parameters": {"type": "object", "properties": {"pixels": {"type": "integer"}}}},
|
| 78 |
+
{"name": "terminate", "description": "Task done", "parameters": {"type": "object", "properties": {"status": {"type": "string"}}}}
|
| 79 |
+
]
|
| 80 |
+
|
| 81 |
+
def _format_prompt(self, user_prompt):
|
| 82 |
+
# Injects the schema and strict English/Format instructions
|
| 83 |
+
tools_json = json.dumps(self.tools_schema, indent=2)
|
| 84 |
+
system = (
|
| 85 |
+
f"You are Fara-TARS, a GUI automation agent.\n"
|
| 86 |
+
f"AVAILABLE TOOLS:\n{tools_json}\n\n"
|
| 87 |
+
"INSTRUCTIONS:\n"
|
| 88 |
+
"1. Reason first, then act.\n"
|
| 89 |
+
"2. Output valid JSON inside <tool_call> tags.\n"
|
| 90 |
+
"3. Format: <tool_call>{{\"name\": \"left_click\", ...}}</tool_call>"
|
| 91 |
+
)
|
| 92 |
+
return (
|
| 93 |
+
f"<|im_start|>system\n{system}<|im_end|>\n"
|
| 94 |
+
f"<|im_start|>user\n{user_prompt}<|im_end|>\n"
|
| 95 |
+
f"<|im_start|>assistant\n"
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
def _repair_json(self, json_str):
|
| 99 |
+
# Auto-fixes common LLM JSON errors (smart quotes, missing keys)
|
| 100 |
+
json_str = json_str.replace("“", '"').replace("”", '"').replace("'", '"')
|
| 101 |
+
json_str = re.sub(r'(\w+)"\s*:', r'"\1":', json_str)
|
| 102 |
+
return json_str
|
| 103 |
+
|
| 104 |
+
def run(self, prompt, image_path=None):
|
| 105 |
+
formatted_prompt = self._format_prompt(prompt)
|
| 106 |
+
|
| 107 |
+
# Handle Image Input (Optional)
|
| 108 |
+
if image_path:
|
| 109 |
+
image = Image.open(image_path).convert("RGB")
|
| 110 |
+
inputs = self.model.build_conversation_input_ids(
|
| 111 |
+
tokenizer=self.tokenizer, query=formatted_prompt, image=image
|
| 112 |
+
)
|
| 113 |
+
else:
|
| 114 |
+
inputs = self.tokenizer(formatted_prompt, return_tensors="pt").to(self.model.device)
|
| 115 |
|
| 116 |
+
# Critical: Stop generation at tool close to prevent loops
|
| 117 |
+
stop_strings = ["</tool_call>", "<|im_end|>"]
|
| 118 |
+
|
| 119 |
+
# Optimized Config
|
| 120 |
+
config = GenerationConfig(
|
| 121 |
+
max_new_tokens=2048,
|
| 122 |
+
do_sample=True,
|
| 123 |
+
temperature=0.4,
|
| 124 |
+
top_p=0.95,
|
| 125 |
+
repetition_penalty=1.15, # Prevents "United.com" loops
|
| 126 |
+
no_repeat_ngram_size=0, # Must be 0 to allow JSON keys
|
| 127 |
+
pad_token_id=self.tokenizer.pad_token_id,
|
| 128 |
+
eos_token_id=self.tokenizer.eos_token_id
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
with torch.no_grad():
|
| 132 |
+
output = self.model.generate(
|
| 133 |
+
**inputs,
|
| 134 |
+
generation_config=config,
|
| 135 |
+
tokenizer=self.tokenizer,
|
| 136 |
+
stop_strings=stop_strings
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
input_len = inputs['input_ids'].shape[1]
|
| 140 |
+
raw_response = self.tokenizer.decode(output[0][input_len:], skip_special_tokens=True)
|
| 141 |
+
|
| 142 |
+
# Parse Output
|
| 143 |
+
tool_action = None
|
| 144 |
+
text_content = raw_response
|
| 145 |
+
|
| 146 |
+
if "<tool_call>" in raw_response:
|
| 147 |
+
parts = raw_response.split("<tool_call>")
|
| 148 |
+
text_content = parts[0].strip()
|
| 149 |
+
tool_str = parts[1].split("</tool_call>")[0].strip()
|
| 150 |
+
try:
|
| 151 |
+
tool_action = json.loads(self._repair_json(tool_str))
|
| 152 |
+
except:
|
| 153 |
+
tool_action = {"error": "malformed_json", "raw": tool_str}
|
| 154 |
+
|
| 155 |
+
return {"thought": text_content, "action": tool_action}
|
| 156 |
+
|
| 157 |
+
# Usage
|
| 158 |
+
agent = FaraAgent("your-username/Fara-TARS-7B")
|
| 159 |
+
result = agent.run("Click the Submit button at (1200, 800)")
|
| 160 |
+
print(result)
|
| 161 |
+
```
|
| 162 |
+
|
| 163 |
+
## Benchmark Performance
|
| 164 |
+
|
| 165 |
+
The model was evaluated on a comprehensive suite covering Web Automation, GUI Grounding, and Complex Reasoning.
|
| 166 |
+
|
| 167 |
+
| Category | Task | Result Type | Performance |
|
| 168 |
+
| :--- | :--- | :--- | :--- |
|
| 169 |
+
| **GUI Grounding** | "Click Submit at (1200, 800)" | **Tool Call** | ✅ Correct JSON: `{"point": [1200, 800]}` |
|
| 170 |
+
| **Web Automation** | "Type 'Hello World' in search" | **Tool Call** | ✅ Correct JSON: `{"name": "type", "text": "Hello World"}` |
|
| 171 |
+
| **Reasoning** | "Design a Weekly Python Plan" | **Text** | ✅ Generates full Markdown plan (900+ tokens) |
|
| 172 |
+
| **Hybrid** | "Compare Selenium vs Playwright" | **Agentic Text** | ✅ Uses `type` tool to output a Markdown table |
|
| 173 |
+
| **Safety** | "Stop at critical payment point" | **Tool Call** | ✅ Uses `terminate` tool with status `stop_confirm` |
|
| 174 |
+
|
| 175 |
+
## Merge Details
|
| 176 |
+
|
| 177 |
+
This model was merged using **Mergekit**.
|
| 178 |
+
|
| 179 |
+
### Configuration
|
| 180 |
+
```yaml
|
| 181 |
models:
|
| 182 |
- model: microsoft/Fara-7B
|
| 183 |
- model: ByteDance-Seed/UI-TARS-1.5-7B
|
| 184 |
+
parameters:
|
| 185 |
+
density: 0.53
|
| 186 |
+
weight: 0.5
|
| 187 |
+
merge_method: dare_ties
|
| 188 |
base_model: microsoft/Fara-7B
|
|
|
|
| 189 |
parameters:
|
| 190 |
+
normalize: true
|
| 191 |
+
int8_mask: true
|
| 192 |
+
dtype: bfloat16
|
| 193 |
+
```
|
| 194 |
+
*(Note: While `dare_ties` was used, specific inference parameters (temp=0.4, rep_penalty=1.15) are required to stabilize the output, as documented in the Usage section).*
|
|
|
|
| 195 |
|
| 196 |
+
## ⚠️ Limitations
|
| 197 |
|
| 198 |
+
1. **Strict Prompting:** The model expects the specific System Prompt defined in the usage class. Without it, it may hallucinate tool names.
|
| 199 |
+
2. **Repetition:** In extremely long lists (100+ items), the model may repeat. The recommended `repetition_penalty=1.15` fixes this for 99% of cases.
|
| 200 |
+
|
| 201 |
+
## License
|
| 202 |
+
|
| 203 |
+
Apache 2.0
|
| 204 |
+
---
|