nllg / EdiTikZ-4B

huggingface.co
Total runs: 30
24-hour runs: 0
7-day runs: 0
30-day runs: 0
Model's Last Updated: September 08 2026
image-text-to-text

Introduction of EdiTikZ-4B

Model Details of EdiTikZ-4B

Model Card for EdiTikZ-4B

EdiTikZ-4B is a multimodal language model for instruction-guided editing and reconstruction of scientific figures represented as TikZ/LaTeX code.

It is based on Qwen3.5-4B and was trained with multi-task supervised fine-tuning (SFT) on DaEdiTikZ and DaTikZ-V4 for scientific figure editing and reconstruction.

Installation
pip install torch==2.7.1 transformers==5.3.0 accelerate==1.12.0 pillow
Usage
import torch
from PIL import Image
from transformers import AutoModelForImageTextToText, AutoProcessor

model_id = "nllg/EdiTikZ-4B"
fixed_image_size = 448
fixed_pixels = fixed_image_size * fixed_image_size

processor = AutoProcessor.from_pretrained(
    model_id,
    use_fast=False,
    min_pixels=fixed_pixels,
    max_pixels=fixed_pixels,
    trust_remote_code=True,
)

model = AutoModelForImageTextToText.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="auto",
    trust_remote_code=True,
)
model.eval()

tokenizer = processor.tokenizer
if tokenizer.pad_token_id is None:
    tokenizer.pad_token_id = tokenizer.eos_token_id

model.config.eos_token_id = tokenizer.eos_token_id
model.config.pad_token_id = tokenizer.pad_token_id
if getattr(model, "generation_config", None) is not None:
    model.generation_config.eos_token_id = tokenizer.eos_token_id
    model.generation_config.pad_token_id = tokenizer.pad_token_id

def build_editing_prompt(instruction: str) -> str:
    return (
        "<TASK_EDITING>\n"
        "This is an image of a scientific figure. Reconstruct it in TikZ and "
        "apply the following changes:\n"
        f"{instruction.strip()}\n"
        "Wrap your code using \\documentclass[tikz]{standalone}, and include "
        "\\begin{document} ... \\end{document}. Only output valid LaTeX code "
        "with no extra text."
    )

def build_reconstruction_prompt() -> str:
    return (
        "<TASK_RECONSTRUCTION>\n"
        "This is an image of a scientific figure. Reconstruct it in TikZ.\n"
        "Wrap your code using \\documentclass[tikz]{standalone}, and include "
        "\\begin{document} ... \\end{document}. Only output valid LaTeX code "
        "with no extra text."
    )

def load_image(image_path: str) -> Image.Image:
    image = Image.open(image_path).convert("RGB")
    if image.size != (fixed_image_size, fixed_image_size):
        image = image.resize(
            (fixed_image_size, fixed_image_size),
            Image.Resampling.BICUBIC,
        )
    return image

@torch.inference_mode()
def generate_tikz(image_path: str, prompt: str) -> str:
    image = load_image(image_path)
    messages = [
        {
            "role": "user",
            "content": [
                {"type": "image", "image": image},
                {"type": "text", "text": prompt},
            ],
        }
    ]

    text = processor.apply_chat_template(
        messages,
        tokenize=False,
        add_generation_prompt=True,
        enable_thinking=False,
    )
    inputs = processor(
        text=[text],
        images=[image],
        padding=False,
        return_tensors="pt",
    )
    model_device = next(model.parameters()).device
    inputs = {name: value.to(model_device) for name, value in inputs.items()}

    generated_ids = model.generate(
        **inputs,
        max_new_tokens=2048,
        do_sample=True,
        temperature=0.2,
        top_p=0.9,
        top_k=50,
        repetition_penalty=1.0,
        use_cache=True,
        eos_token_id=tokenizer.eos_token_id,
        pad_token_id=tokenizer.pad_token_id,
    )
    generated_ids = generated_ids[:, inputs["input_ids"].shape[1]:]
    return processor.batch_decode(
        generated_ids,
        skip_special_tokens=True,
        clean_up_tokenization_spaces=False,
    )[0].strip()

image_path = "path/to/source_figure.png"
editing_instruction = (
    "The thick black polyline consisting of a horizontal segment along the "
    "bottom edge and a diagonal segment connecting the bottom-middle to the "
    "center of the grid is removed. A thick black outline with rounded corners "
    "is added around the entire 3x2 grid, replacing the sharp corners of the "
    "original rectangular boundary."
)

# Instruction-guided editing
edited_tikz = generate_tikz(
    image_path,
    build_editing_prompt(editing_instruction),
)
print(edited_tikz)

# Image-to-TikZ reconstruction
# reconstructed_tikz = generate_tikz(image_path, build_reconstruction_prompt())
# print(reconstructed_tikz)
Faster batched inference with vLLM
pip install vllm==0.25.0 pillow
from PIL import Image
from transformers import AutoProcessor
from vllm import LLM, SamplingParams

model_id = "nllg/EdiTikZ-4B"
fixed_image_size = 448
fixed_pixels = fixed_image_size * fixed_image_size

processor = AutoProcessor.from_pretrained(
    model_id,
    use_fast=False,
    min_pixels=fixed_pixels,
    max_pixels=fixed_pixels,
    trust_remote_code=True,
)

llm = LLM(
    model=model_id,
    dtype="bfloat16",
    trust_remote_code=True,
    limit_mm_per_prompt={"image": 1},
    # tensor_parallel_size=2,  # Uncomment for multi-GPU tensor parallelism.
)

def make_request(image_path: str, instruction: str) -> dict:
    image = Image.open(image_path).convert("RGB")
    if image.size != (fixed_image_size, fixed_image_size):
        image = image.resize(
            (fixed_image_size, fixed_image_size),
            Image.Resampling.BICUBIC,
        )

    prompt = (
        "<TASK_EDITING>\n"
        "This is an image of a scientific figure. Reconstruct it in TikZ and "
        "apply the following changes:\n"
        f"{instruction.strip()}\n"
        "Wrap your code using \\documentclass[tikz]{standalone}, and include "
        "\\begin{document} ... \\end{document}. Only output valid LaTeX code "
        "with no extra text."
    )
    messages = [
        {
            "role": "user",
            "content": [
                {"type": "image"},
                {"type": "text", "text": prompt},
            ],
        }
    ]
    formatted_prompt = processor.apply_chat_template(
        messages,
        tokenize=False,
        add_generation_prompt=True,
        enable_thinking=False,
    )
    return {
        "prompt": formatted_prompt,
        "multi_modal_data": {"image": image},
    }

examples = [
    {
        "image_path": "path/to/source_figure_1.png",
        "instruction": "first_editing_instruction",
    },
    {
        "image_path": "path/to/source_figure_2.png",
        "instruction": "second_editing_instruction",
    },
]

requests = [
    make_request(item["image_path"], item["instruction"])
    for item in examples
]

sampling_params = SamplingParams(
    max_tokens=2048,
    temperature=0.2,
    top_p=0.9,
    top_k=50,
    repetition_penalty=1.0,
)

outputs = llm.generate(
    requests,
    sampling_params=sampling_params,
    use_tqdm=True,
)

for output in outputs:
    print(output.outputs[0].text.strip())

Runs of nllg EdiTikZ-4B on huggingface.co

30
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs

More Information About EdiTikZ-4B huggingface.co Model

More EdiTikZ-4B license Visit here:

https://choosealicense.com/licenses/apache-2.0

EdiTikZ-4B huggingface.co

EdiTikZ-4B huggingface.co is an AI model on huggingface.co that provides EdiTikZ-4B's model effect (), which can be used instantly with this nllg EdiTikZ-4B model. huggingface.co supports a free trial of the EdiTikZ-4B model, and also provides paid use of the EdiTikZ-4B. Support call EdiTikZ-4B model through api, including Node.js, Python, http.

EdiTikZ-4B huggingface.co Url

https://huggingface.co/nllg/EdiTikZ-4B

nllg EdiTikZ-4B online free

EdiTikZ-4B huggingface.co is an online trial and call api platform, which integrates EdiTikZ-4B's modeling effects, including api services, and provides a free online trial of EdiTikZ-4B, you can try EdiTikZ-4B online for free by clicking the link below.

nllg EdiTikZ-4B online free url in huggingface.co:

https://huggingface.co/nllg/EdiTikZ-4B

EdiTikZ-4B install

EdiTikZ-4B is an open source model from GitHub that offers a free installation service, and any user can find EdiTikZ-4B on GitHub to install. At the same time, huggingface.co provides the effect of EdiTikZ-4B install, users can directly use EdiTikZ-4B installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

EdiTikZ-4B install url in huggingface.co:

https://huggingface.co/nllg/EdiTikZ-4B

Url of EdiTikZ-4B

EdiTikZ-4B huggingface.co Url

Provider of EdiTikZ-4B huggingface.co

nllg
ORGANIZATIONS

Other API from nllg

huggingface.co

Total runs: 3.7K
Run Growth: -1.8K
Growth Rate: -49.59%
Updated:March 17 2025
huggingface.co

Total runs: 59
Run Growth: 4
Growth Rate: 6.78%
Updated:September 10 2026
huggingface.co

Total runs: 33
Run Growth: 0
Growth Rate: 0.00%
Updated:March 10 2026
huggingface.co

Total runs: 28
Run Growth: -15
Growth Rate: -53.57%
Updated:September 10 2026
huggingface.co

Total runs: 17
Run Growth: 0
Growth Rate: 0.00%
Updated:March 10 2026
huggingface.co

Total runs: 14
Run Growth: 0
Growth Rate: 0.00%
Updated:December 04 2024
huggingface.co

Total runs: 11
Run Growth: -2
Growth Rate: -18.18%
Updated:August 23 2022
huggingface.co

Total runs: 11
Run Growth: 0
Growth Rate: 0.00%
Updated:March 10 2026
huggingface.co

Total runs: 10
Run Growth: 0
Growth Rate: 0.00%
Updated:December 04 2024
huggingface.co

Total runs: 9
Run Growth: -13
Growth Rate: -144.44%
Updated:August 23 2022
huggingface.co

Total runs: 9
Run Growth: -8
Growth Rate: -88.89%
Updated:November 16 2022
huggingface.co

Total runs: 8
Run Growth: 0
Growth Rate: 0.00%
Updated:March 10 2026
huggingface.co

Total runs: 8
Run Growth: -7
Growth Rate: -87.50%
Updated:October 05 2022
huggingface.co

Total runs: 7
Run Growth: -1
Growth Rate: -14.29%
Updated:October 05 2022
huggingface.co

Total runs: 5
Run Growth: 0
Growth Rate: 0.00%
Updated:August 30 2024
huggingface.co

Total runs: 5
Run Growth: -4
Growth Rate: -80.00%
Updated:October 05 2022
huggingface.co

Total runs: 5
Run Growth: 0
Growth Rate: 0.00%
Updated:February 16 2026
huggingface.co

Total runs: 3
Run Growth: 0
Growth Rate: 0.00%
Updated:February 28 2024
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated:August 07 2025
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated:November 09 2023
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated:November 09 2023
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated:November 09 2023