Spaces:
Running
on
Zero
Running
on
Zero
File size: 21,317 Bytes
7d0d550 d27700b 7d0d550 83e0b46 c875d85 7d0d550 1c19f0a 7d0d550 1c19f0a 73b010f 35f77a2 73b010f 0f4a1d2 73b010f 0f4a1d2 7d0d550 1c19f0a 73b010f 7696916 5b3b978 73b010f 5b3b978 73b010f 5b3b978 73b010f 5b3b978 73b010f 5b3b978 73b010f 5b3b978 73b010f bf237a8 7696916 bf237a8 0b96563 d27700b bf237a8 35f77a2 d27700b 7696916 83e0b46 35f77a2 7696916 83e0b46 35f77a2 83e0b46 35f77a2 6cd9363 7d0d550 7696916 6cd9363 0b96563 c875d85 0b96563 0f4a1d2 9c44f17 0b96563 9c44f17 d87b209 35f77a2 83e0b46 35f77a2 83e0b46 7696916 0b96563 35f77a2 83e0b46 7696916 35f77a2 7d0d550 d27700b 35f77a2 d214428 0b96563 d214428 83e0b46 6cd9363 d214428 6cd9363 0f4a1d2 fcb0f85 7d0d550 0f4a1d2 7d0d550 0f4a1d2 73b010f 0f4a1d2 73b010f 35f77a2 7d0d550 83e0b46 7696916 83e0b46 7696916 83e0b46 7696916 83e0b46 7696916 83e0b46 7696916 83e0b46 7696916 7d0d550 0f4a1d2 7d0d550 35f77a2 0b96563 35f77a2 7d0d550 6aaf210 9c44f17 35f77a2 d214428 7d0d550 83e0b46 6cd9363 83e0b46 d87b209 35f77a2 bf237a8 35f77a2 0b96563 83e0b46 7d0d550 7696916 0a8e8e5 0f4a1d2 e98b5fc 35f77a2 7d0d550 0f4a1d2 35f77a2 83e0b46 0f4a1d2 35f77a2 6cd9363 d214428 0b96563 0f4a1d2 bf237a8 0f4a1d2 35f77a2 d214428 bf237a8 0f4a1d2 bf237a8 0f4a1d2 35f77a2 d27700b 0f4a1d2 6aaf210 7696916 83e0b46 7696916 83e0b46 7696916 83e0b46 7696916 83e0b46 7696916 83e0b46 7696916 83e0b46 7696916 83e0b46 7696916 83e0b46 7696916 35f77a2 0b96563 35f77a2 7696916 35f77a2 7696916 35f77a2 7696916 35f77a2 7696916 35f77a2 83e0b46 35f77a2 7696916 83e0b46 d214428 7d0d550 0f4a1d2 7d0d550 83e0b46 7696916 83e0b46 7d0d550 84d673e 0a8e8e5 84d673e 50c43e5 9528754 7696916 7d0d550 73b010f fb61d02 fcb0f85 6f12eee 73b010f 7696916 73b010f 6f12eee 5c21f23 7d0d550 0a8e8e5 7d0d550 1c19f0a fb61d02 9e4971c 73b010f 7d0d550 83e0b46 7d0d550 6f12eee 7d0d550 35f77a2 5b3b978 7696916 35f77a2 6f12eee 7d0d550 c875d85 9e4971c 5b3b978 |
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
import os
import re
import json
import time
import unicodedata
import gc
from io import BytesIO
from typing import Iterable, Tuple, Optional, List, Dict, Any
import gradio as gr
import numpy as np
import torch
import spaces
from PIL import Image, ImageDraw, ImageFont
from transformers import (
Qwen2_5_VLForConditionalGeneration,
AutoProcessor,
AutoModelForImageTextToText
)
from transformers.models.qwen2_vl.image_processing_qwen2_vl import smart_resize
from qwen_vl_utils import process_vision_info
from gradio.themes import Soft
from gradio.themes.utils import colors, fonts, sizes
# --- Theme Configuration ---
colors.orange_red = colors.Color(
name="orange_red",
c50="#FFF0E5",
c100="#FFE0CC",
c200="#FFC299",
c300="#FFA366",
c400="#FF8533",
c500="#FF4500",
c600="#E63E00",
c700="#CC3700",
c800="#B33000",
c900="#992900",
c950="#802200",
)
class OrangeRedTheme(Soft):
def __init__(
self,
*,
primary_hue: colors.Color | str = colors.gray,
secondary_hue: colors.Color | str = colors.orange_red,
neutral_hue: colors.Color | str = colors.slate,
text_size: sizes.Size | str = sizes.text_lg,
font: fonts.Font | str | Iterable[fonts.Font | str] = (
fonts.GoogleFont("Outfit"), "Arial", "sans-serif",
),
font_mono: fonts.Font | str | Iterable[fonts.Font | str] = (
fonts.GoogleFont("IBM Plex Mono"), "ui-monospace", "monospace",
),
):
super().__init__(
primary_hue=primary_hue,
secondary_hue=secondary_hue,
neutral_hue=neutral_hue,
text_size=text_size,
font=font,
font_mono=font_mono,
)
super().set(
background_fill_primary="*primary_50",
background_fill_primary_dark="*primary_900",
body_background_fill="linear-gradient(135deg, *primary_200, *primary_100)",
body_background_fill_dark="linear-gradient(135deg, *primary_900, *primary_800)",
button_primary_text_color="white",
button_primary_text_color_hover="white",
button_primary_background_fill="linear-gradient(90deg, *secondary_500, *secondary_600)",
button_primary_background_fill_hover="linear-gradient(90deg, *secondary_600, *secondary_700)",
button_primary_background_fill_dark="linear-gradient(90deg, *secondary_600, *secondary_700)",
button_primary_background_fill_hover_dark="linear-gradient(90deg, *secondary_500, *secondary_600)",
button_secondary_text_color="black",
button_secondary_text_color_hover="white",
button_secondary_background_fill="linear-gradient(90deg, *primary_300, *primary_300)",
button_secondary_background_fill_hover="linear-gradient(90deg, *primary_400, *primary_400)",
button_secondary_background_fill_dark="linear-gradient(90deg, *primary_500, *primary_600)",
button_secondary_background_fill_hover_dark="linear-gradient(90deg, *primary_500, *primary_500)",
slider_color="*secondary_500",
slider_color_dark="*secondary_600",
block_title_text_weight="600",
block_border_width="3px",
block_shadow="*shadow_drop_lg",
button_primary_shadow="*shadow_drop_lg",
button_large_padding="11px",
color_accent_soft="*primary_100",
block_label_background_fill="*primary_200",
)
orange_red_theme = OrangeRedTheme()
device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"Running on device: {device}")
# --- Model Loading ---
print("π Loading Fara-7B...")
MODEL_ID_V = "microsoft/Fara-7B"
try:
processor_v = AutoProcessor.from_pretrained(MODEL_ID_V, trust_remote_code=True)
model_v = Qwen2_5_VLForConditionalGeneration.from_pretrained(
MODEL_ID_V,
trust_remote_code=True,
torch_dtype=torch.float16
).to(device).eval()
except Exception as e:
print(f"Failed to load Fara: {e}")
model_v = None
processor_v = None
print("π Loading UI-TARS-1.5-7B...")
MODEL_ID_X = "ByteDance-Seed/UI-TARS-1.5-7B"
try:
processor_x = AutoProcessor.from_pretrained(MODEL_ID_X, trust_remote_code=True, use_fast=False)
model_x = AutoModelForImageTextToText.from_pretrained(
MODEL_ID_X,
trust_remote_code=True,
torch_dtype=torch.bfloat16 if device == "cuda" else torch.float32,
).to(device).eval()
except Exception as e:
print(f"Failed to load UI-TARS: {e}")
model_x = None
processor_x = None
print("π Loading Holo2-4B...")
MODEL_ID_H = "Hcompany/Holo2-4B"
try:
processor_h = AutoProcessor.from_pretrained(MODEL_ID_H, trust_remote_code=True)
model_h = AutoModelForImageTextToText.from_pretrained(
MODEL_ID_H,
trust_remote_code=True,
torch_dtype=torch.bfloat16 if device == "cuda" else torch.float32,
device_map="auto" if device == "cuda" else None
).eval()
if device == "cpu":
model_h = model_h.to(device)
except Exception as e:
print(f"Failed to load Holo2-4B: {e}")
model_h = None
processor_h = None
print("β
Models loading sequence complete.")
# --- Helper Functions ---
def array_to_image(image_array: np.ndarray) -> Image.Image:
if image_array is None: raise ValueError("No image provided.")
return Image.fromarray(np.uint8(image_array))
def get_image_proc_params(processor) -> Dict[str, int]:
ip = getattr(processor, "image_processor", None)
default_min = 256 * 256
default_max = 1280 * 1280
patch_size = getattr(ip, "patch_size", 14)
merge_size = getattr(ip, "merge_size", 2)
min_pixels = getattr(ip, "min_pixels", default_min)
max_pixels = getattr(ip, "max_pixels", default_max)
if min_pixels is None: min_pixels = default_min
if max_pixels is None: max_pixels = default_max
return {
"patch_size": patch_size,
"merge_size": merge_size,
"min_pixels": min_pixels,
"max_pixels": max_pixels,
}
def apply_chat_template_compat(processor, messages: List[Dict[str, Any]]) -> str:
tok = getattr(processor, "tokenizer", None)
if hasattr(processor, "apply_chat_template"):
return processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
if tok is not None and hasattr(tok, "apply_chat_template"):
return tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
return ""
def batch_decode_compat(processor, token_id_batches, **kw):
tok = getattr(processor, "tokenizer", None)
if hasattr(processor, "batch_decode"):
return processor.batch_decode(token_id_batches, **kw)
if tok is not None and hasattr(tok, "batch_decode"):
return tok.batch_decode(token_id_batches, **kw)
raise AttributeError("No batch_decode available on processor or tokenizer.")
def trim_generated(generated_ids, inputs):
in_ids = getattr(inputs, "input_ids", None)
if in_ids is None and isinstance(inputs, dict):
in_ids = inputs.get("input_ids", None)
if in_ids is None:
return generated_ids
return [out_ids[len(in_seq):] for in_seq, out_ids in zip(in_ids, generated_ids)]
# --- Prompt Builders ---
def get_fara_prompt(task, image):
OS_SYSTEM_PROMPT = """You are a GUI agent. You are given a task and a screenshot of the current status.
You need to generate the next action to complete the task.
Output your action inside a <tool_call> block using JSON format.
Include "coordinate": [x, y] in pixels for interactions.
Examples:
<tool_call>{"name": "User", "arguments": {"action": "click", "coordinate": [400, 300]}}</tool_call>
<tool_call>{"name": "User", "arguments": {"action": "type", "coordinate": [100, 200], "text": "hello"}}</tool_call>
"""
return [
{"role": "system", "content": [{"type": "text", "text": OS_SYSTEM_PROMPT}]},
{"role": "user", "content": [{"type": "image", "image": image}, {"type": "text", "text": f"Instruction: {task}"}]},
]
def get_localization_prompt(task, image):
guidelines = (
"Localize an element on the GUI image according to my instructions and "
"output a click position as Click(x, y) with x num pixels from the left edge "
"and y num pixels from the top edge."
)
return [
{
"role": "user",
"content": [
{"type": "image", "image": image},
{"type": "text", "text": f"{guidelines}\n{task}"}
],
}
]
def get_holo2_messages(task, image):
return [
{
"role": "user",
"content": [
{"type": "image", "image": image},
{"type": "text", "text": task}
]
}
]
# --- Response Parsers ---
def parse_click_response(text: str) -> List[Dict]:
actions = []
text = text.strip()
matches_click = re.findall(r"Click\s*\(\s*(\d+)\s*,\s*(\d+)\s*\)", text, re.IGNORECASE)
for m in matches_click:
actions.append({"type": "click", "x": int(m[0]), "y": int(m[1]), "text": ""})
matches_point = re.findall(r"point=\[\s*(\d+)\s*,\s*(\d+)\s*\]", text, re.IGNORECASE)
for m in matches_point:
actions.append({"type": "click", "x": int(m[0]), "y": int(m[1]), "text": ""})
matches_box = re.findall(r"start_box=['\"]?\(\s*(\d+)\s*,\s*(\d+)\s*\)['\"]?", text, re.IGNORECASE)
for m in matches_box:
actions.append({"type": "click", "x": int(m[0]), "y": int(m[1]), "text": ""})
matches_tuple = re.findall(r"(?:^|\s)\(\s*(\d+)\s*,\s*(\d+)\s*\)(?:$|\s|,)", text)
for m in matches_tuple:
actions.append({"type": "click", "x": int(m[0]), "y": int(m[1]), "text": ""})
# Deduplicate
unique_actions = []
seen = set()
for a in actions:
key = (a['type'], a['x'], a['y'])
if key not in seen:
seen.add(key)
unique_actions.append(a)
return unique_actions
def parse_fara_response(response: str) -> List[Dict]:
actions = []
matches = re.findall(r"<tool_call>(.*?)</tool_call>", response, re.DOTALL)
for match in matches:
try:
data = json.loads(match.strip())
args = data.get("arguments", {})
coords = args.get("coordinate", [])
action_type = args.get("action", "unknown")
text_content = args.get("text", "")
if coords and len(coords) == 2:
actions.append({
"type": action_type, "x": float(coords[0]), "y": float(coords[1]), "text": text_content
})
except Exception as e:
print(f"Error parsing Fara JSON: {e}")
pass
return actions
def parse_holo2_reasoning(processor, generated_ids) -> tuple[str, str]:
"""Parse content from generated_ids specifically for Holo2"""
all_ids = generated_ids[0].tolist()
# Try to find thinking block indices
try:
think_start_index = all_ids.index(151667)
except ValueError:
think_start_index = -1
try:
think_end_index = all_ids.index(151668)
except ValueError:
think_end_index = -1
if think_start_index != -1 and think_end_index != -1:
thinking_content = processor.decode(all_ids[think_start_index+1:think_end_index], skip_special_tokens=True).strip("\n")
content = processor.decode(all_ids[think_end_index+1:], skip_special_tokens=True).strip("\n")
else:
# If no thinking tags or incomplete, decode everything
thinking_content = ""
content = processor.decode(all_ids, skip_special_tokens=True).strip("\n")
return content, thinking_content
def parse_holo2_json(content: str) -> List[Dict]:
actions = []
try:
# Clean potential markdown
cleaned = content.replace("```json", "").replace("```", "").strip()
data = json.loads(cleaned)
if "x" in data and "y" in data:
actions.append({"type": "click", "x": data["x"], "y": data["y"], "text": ""})
except json.JSONDecodeError:
print(f"Failed to parse Holo2 JSON: {content}")
return actions
# --- Visualizer ---
def create_localized_image(original_image: Image.Image, actions: list[dict]) -> Optional[Image.Image]:
if not actions: return None
img_copy = original_image.copy()
draw = ImageDraw.Draw(img_copy)
try:
font = ImageFont.load_default(size=18)
except IOError:
font = ImageFont.load_default()
for act in actions:
x = act['x']
y = act['y']
pixel_x, pixel_y = int(x), int(y)
color = 'red' if 'click' in act['type'].lower() else 'blue'
# Draw Cross and Circle style (as requested by user preference)
cross_size = 20
# Horizontal line
draw.line([pixel_x - cross_size, pixel_y, pixel_x + cross_size, pixel_y], fill=color, width=4)
# Vertical line
draw.line([pixel_x, pixel_y - cross_size, pixel_x, pixel_y + cross_size], fill=color, width=4)
# Circle
r = 15
draw.ellipse([pixel_x - r, pixel_y - r, pixel_x + r, pixel_y + r], outline=color, width=3)
label = f"{act['type'].capitalize()}"
if act.get('text'): label += f": \"{act['text']}\""
text_pos = (pixel_x + 25, pixel_y - 15)
try:
bbox = draw.textbbox(text_pos, label, font=font)
padded_bbox = (bbox[0]-4, bbox[1]-2, bbox[2]+4, bbox[3]+2)
draw.rectangle(padded_bbox, fill="yellow", outline=color)
draw.text(text_pos, label, fill="black", font=font)
except Exception:
draw.text(text_pos, label, fill="black")
return img_copy
# --- Main Logic ---
@spaces.GPU
def process_screenshot(input_numpy_image: np.ndarray, task: str, model_choice: str):
if input_numpy_image is None: return "β οΈ Please upload an image.", None
if not task.strip(): return "β οΈ Please provide a task instruction.", None
input_pil_image = array_to_image(input_numpy_image)
orig_w, orig_h = input_pil_image.size
actions = []
raw_response = ""
thinking_output = ""
if model_choice == "Fara-7B":
if model_v is None: return "Error: Fara model failed to load on startup.", None
print("Using Fara Pipeline...")
messages = get_fara_prompt(task, input_pil_image)
text_prompt = processor_v.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor_v(
text=[text_prompt],
images=image_inputs,
videos=video_inputs,
padding=True,
return_tensors="pt"
)
inputs = inputs.to(device)
with torch.no_grad():
generated_ids = model_v.generate(**inputs, max_new_tokens=512)
generated_ids = trim_generated(generated_ids, inputs)
raw_response = processor_v.batch_decode(generated_ids, skip_special_tokens=True)[0]
actions = parse_fara_response(raw_response)
elif model_choice == "Holo2-4B":
if model_h is None: return "Error: Holo2-4B model failed to load.", None
print("Using Holo2-4B Pipeline...")
# Specific Holo2 resizing logic
ip_config = processor_h.image_processor
resized_h, resized_w = smart_resize(
input_pil_image.height,
input_pil_image.width,
factor=ip_config.patch_size * ip_config.merge_size,
min_pixels=ip_config.size.get("shortest_edge", 256*256),
max_pixels=ip_config.size.get("longest_edge", 1280*1280),
)
processed_image = input_pil_image.resize((resized_w, resized_h), Image.Resampling.LANCZOS)
messages = get_holo2_messages(task, processed_image)
# Apply template with thinking=False for localization as per documentation/snippet
text_prompt = processor_h.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
thinking=False
)
inputs = processor_h(
text=[text_prompt],
images=[processed_image],
padding=True,
return_tensors="pt"
).to(model_h.device)
with torch.no_grad():
generated_ids = model_h.generate(**inputs, max_new_tokens=128)
# Parse reasoning/content
content, thinking_output = parse_holo2_reasoning(processor_h, trim_generated(generated_ids, inputs))
raw_response = content
if thinking_output:
raw_response = f"[Thinking Process]:\n{thinking_output}\n\n[Action]:\n{content}"
actions = parse_holo2_json(content)
# Handle Holo2 coordinate normalization (0-1000) relative to image
# Math: (x_norm / 1000) * orig_w
for a in actions:
a['x'] = (a['x'] / 1000) * orig_w
a['y'] = (a['y'] / 1000) * orig_h
elif model_choice == "UI-TARS-1.5-7B":
if model_x is None: return "Error: UI-TARS model failed to load.", None
print("Using UI-TARS Pipeline...")
ip_params = get_image_proc_params(processor_x)
resized_h, resized_w = smart_resize(
input_pil_image.height, input_pil_image.width,
factor=ip_params["patch_size"] * ip_params["merge_size"],
min_pixels=ip_params["min_pixels"],
max_pixels=ip_params["max_pixels"]
)
proc_image = input_pil_image.resize((resized_w, resized_h), Image.Resampling.LANCZOS)
messages = get_localization_prompt(task, proc_image)
text_prompt = apply_chat_template_compat(processor_x, messages)
inputs = processor_x(text=[text_prompt], images=[proc_image], padding=True, return_tensors="pt")
inputs = {k: v.to(device) for k, v in inputs.items()}
with torch.no_grad():
generated_ids = model_x.generate(**inputs, max_new_tokens=128)
generated_ids = trim_generated(generated_ids, inputs)
raw_response = batch_decode_compat(processor_x, generated_ids, skip_special_tokens=True)[0]
actions = parse_click_response(raw_response)
# UI-TARS returns coordinates relative to resized image size
if resized_w > 0 and resized_h > 0:
scale_x = orig_w / resized_w
scale_y = orig_h / resized_h
for a in actions:
a['x'] = int(a['x'] * scale_x)
a['y'] = int(a['y'] * scale_y)
else:
return f"Error: Unknown model '{model_choice}'", None
print(f"Raw Output: {raw_response}")
print(f"Parsed Actions: {actions}")
output_image = input_pil_image
if actions:
vis = create_localized_image(input_pil_image, actions)
if vis: output_image = vis
return raw_response, output_image
# --- UI Setup ---
css="""
#col-container {
margin: 0 auto;
max-width: 960px;
}
#main-title h1 {font-size: 2.1em !important;}
"""
with gr.Blocks() as demo:
gr.Markdown("# **CUA GUI Operator π₯οΈ**", elem_id="main-title")
gr.Markdown("Perform Computer Use Agent tasks with the models: [Fara-7B](https://huggingface.co/microsoft/Fara-7B), [UI-TARS-1.5-7B](https://huggingface.co/ByteDance-Seed/UI-TARS-1.5-7B), and [Holo2-4B](https://huggingface.co/Hcompany/Holo2-4B).")
with gr.Row():
with gr.Column(scale=2):
input_image = gr.Image(label="Upload UI Image", type="numpy", height=500)
with gr.Row():
model_choice = gr.Radio(
choices=["Fara-7B", "UI-TARS-1.5-7B", "Holo2-4B"],
label="Select Model",
value="Fara-7B",
interactive=True
)
task_input = gr.Textbox(
label="Task Instruction",
placeholder="e.g. Click on the search bar",
lines=2
)
submit_btn = gr.Button("Call CUA Agent", variant="primary")
with gr.Column(scale=3):
output_image = gr.Image(label="Visualized Action Points", elem_id="out_img", height=500)
output_text = gr.Textbox(label="Agent Model Response", lines=10)
submit_btn.click(
fn=process_screenshot,
inputs=[input_image, task_input, model_choice],
outputs=[output_text, output_image]
)
gr.Examples(
examples=[
["examples/1.png", "Click on the Fara-7B model.", "Fara-7B"],
["examples/2.png", "Click on the VLMs Collection", "UI-TARS-1.5-7B"],
["examples/3.png", "Click on the 'Real-time vision models' collection.", "Holo2-4B"],
],
inputs=[input_image, task_input, model_choice],
label="Quick Examples"
)
if __name__ == "__main__":
demo.queue(max_size=50).launch(theme=orange_red_theme, css=css, mcp_server=True, ssr_mode=False, show_error=True) |