import re from PIL import Image MODEL = "docling-project/DeskForge-Gemma4-E4B" SYSTEM_PROMPT = """You are a computer-use agent operating a desktop graphical interface. At each step you see the user's task, a screenshot of the current screen, and the actions you have already taken. Reply with the next action as pyautogui code and nothing else -- no explanation, no code fence, no commentary. Coordinates are fractions of the screen, not pixels: x runs from 0.0 at the left edge to 1.0 at the right edge, y from 0.0 at the top to 1.0 at the bottom. Write both with four decimals. These are the only actions available:pyautogui.click(x=0.0000, y=0.0000)pyautogui.doubleClick(x=0.0000, y=0.0000)pyautogui.rightClick(x=0.0000, y=0.0000)pyautogui.middleClick(x=0.0000, y=0.0000)computer.tripleClick(x=0.0000, y=0.0000)pyautogui.moveTo(x=0.0000, y=0.0000)pyautogui.dragTo(x=0.0000, y=0.0000, button='left')pyautogui.scroll(-4)pyautogui.hscroll(4)pyautogui.write(message='text to type')pyautogui.press('enter')pyautogui.hotkey(['ctrl', 'c'])computer.wait()computer.terminate(status='success') To scroll at a particular place, move there first and then scroll. When the task is finished, or cannot be finished, end with computer.terminate.""" def fit(image, max_pixels=2_097_152): """Downscale to at most max_pixels (bilinear, sides rounded down), as in training.""" w, h = image.size if w * h <= max_pixels: return image ratio = w / h height = (max_pixels / ratio) ** 0.5 return image.resize((max(1, int(height * ratio)), max(1, int(height))), Image.BILINEAR) def user_text(instruction): return f"Task: {instruction}\n\nActions already taken:\n(none -- this is the first step)\n\nNext action:" def chat(instruction): return [ {"role": "system", "content": SYSTEM_PROMPT}, {"role": "user", "content": [{"type": "image"}, {"type": "text", "text": user_text(instruction)}]}, ] def to_pixels(action, screenshot): x, y = map(float, re.search(r"x=([\d.]+), y=([\d.]+)", action).groups()) return round(x * screenshot.width), round(y * screenshot.height) screenshot = Image.open("screenshot.png").convert("RGB")instruction = "Open the File menu of the text editor."