Run this model with HF Jobs
Run GD-ML/Code2World on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/GD-ML/Code2World. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/GD-ML/Code2World on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/GD-ML/Code2World. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/GD-ML/Code2World. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use GD-ML/Code2World with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use GD-ML/Code2World with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="GD-ML/Code2World") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("GD-ML/Code2World") model = AutoModelForMultimodalLM.from_pretrained("GD-ML/Code2World", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use GD-ML/Code2World with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "GD-ML/Code2World" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "GD-ML/Code2World", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/GD-ML/Code2World
- SGLang
How to use GD-ML/Code2World with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "GD-ML/Code2World" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "GD-ML/Code2World", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "GD-ML/Code2World" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "GD-ML/Code2World", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use GD-ML/Code2World with Docker Model Runner:
docker model run hf.co/GD-ML/Code2World
Update README.md
Browse files21 unmodified lines22232425262728292531262733282930373132333435363738393 unmodified lines43444548495046525354555657585960616263474849505152536754555657715859747560616263646566672 unmodified lines70717273747576877778798081928283845 unmodified lines909192104939495969798106991001011021032 unmodified lines10610710811510911011111211311411511611711811912012112212311912012112212312412512612712812413013113212513313412612712812913014014113113213314513413513613713813914014114214314414514614714814915115215315415515615715015115215315415515615715815916016116016116216316416516616216316416521 unmodified lines```
```pythonimport osimport reimport jsonimport math
import torchfrom PIL import Image, ImageDrawfrom PIL import Imagefrom transformers import AutoProcessor, Qwen3VLForConditionalGenerationfrom playwright.sync_api import sync_playwright
from prompt_builder import SYSTEM_PROMPT, build_user_promptfrom visual_hint import build_visual_hintfrom render_utils import render_html_to_image, save_demo_outputsfrom render_utils import extract_clean_html, render_html_to_image, save_demo_outputs
# ============================================================# 1. Load model# ============================================================
MODEL_NAME = "GD-ML/Code2World"
3 unmodified lines attn_implementation="flash_attention_2", device_map="auto",)processor = AutoProcessor.from_pretrained(MODEL_NAME)
def extract_clean_html(text: str) -> str: text = text.replace("```html", "").replace("```", "") start_match = re.search(r"<!DOCTYPE html>", text, re.IGNORECASE) end_match = re.search(r"</html>", text, re.IGNORECASE)
if start_match and end_match: start_idx = start_match.start() end_idx = end_match.end() if end_idx > start_idx: return text[start_idx:end_idx]
return text.strip()processor = AutoProcessor.from_pretrained(MODEL_NAME)
# ============================================================# 2. Helper functions# ============================================================
def build_messages(image: Image.Image, instruction: str, action: dict, semantic_desc=None):def build_messages(image, instruction, action): user_prompt = build_user_prompt( instruction_str=instruction, action=action, semantic_desc=semantic_desc, )
return [ {"role": "system", "content": [{"type": "text", "text": SYSTEM_PROMPT}]}, messages = [ { "role": "system", "content": [{"type": "text", "text": SYSTEM_PROMPT}], }, { "role": "user", "content": [2 unmodified lines ], }, ] return messages
@torch.inference_mode()def generate_html(image: Image.Image, instruction: str, action: dict, semantic_desc=None, max_new_tokens: int = 8192):def generate_html(image, instruction, action, max_new_tokens=8192): messages = build_messages( image=image, instruction=instruction, action=action, semantic_desc=semantic_desc, )
inputs = processor.apply_chat_template(5 unmodified lines ) inputs = inputs.to(model.device)
generated_ids = model.generate(**inputs, max_new_tokens=max_new_tokens) generated_ids = model.generate( **inputs, max_new_tokens=max_new_tokens, )
generated_ids_trimmed = [ out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids) out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids) ]
output_text = processor.batch_decode(2 unmodified lines clean_up_tokenization_spaces=False, )[0]
return extract_clean_html(output_text) html = extract_clean_html(output_text) return html
def run_demo(case_data, output_dir="./demo_outputs"): """ case_data 只需要这些 key: - images[0] - instruction - action """ image_path = case_data["images"][0] instruction = case_data["instruction"] action = case_data["action"]
def run_demo( image_path: str, instruction: str, action: dict, step_pam: dict | None = None, semantic_desc: str | None = None, use_visual_hint: bool = True, max_new_tokens: int = 8192, output_dir: str = "./demo_outputs",): image = Image.open(image_path).convert("RGB")
if use_visual_hint: hinted_image = build_visual_hint(image, action, step_pam) hinted_image = build_visual_hint(image, action) else: hinted_image = image
html = generate_html( image=hinted_image, instruction=instruction, action=action, semantic_desc=semantic_desc, max_new_tokens=max_new_tokens, )
rendered_image = render_html_to_image(html) save_demo_outputs(output_dir, hinted_image, html, rendered_image)
save_demo_outputs( output_dir=output_dir, hinted_image=hinted_image, html=html, rendered_image=rendered_image, )
return hinted_image, html, rendered_image
# ============================================================# 3. Example case# ============================================================
if __name__ == "__main__": example_action = { "action_type": "click", "x": 540, "y": 320, } example_step_pam = { "coordinate": [540, 320] case_data = { "images": [ "/mnt/workspace/zyh/wm_ability/android_control/test_images_mini/904_7.png" ], "instruction": "Click on the Search Omio button.", "action": { "action_type": "click", "x": 540, "y": 1470 } }
run_demo( image_path="./examples/current.png", instruction="Tap the search bar to start searching.", action=example_action, step_pam=example_step_pam, output_dir="./demo_outputs", ) run_demo(case_data, output_dir="./demo_outputs")```
## CitationREADME.md+60-64