MCPcopy
hub / github.com/potamides/DeTikZify

github.com/potamides/DeTikZify @v0.3.0 sqlite

repository ↗ · DeepWiki ↗ · release v0.3.0 ↗
421 symbols 1,643 edges 56 files 45 documented · 11%
README

DeTikZify

Synthesizing Graphics Programs for Scientific Figures and Sketches with TikZ OpenReview arXiv Hugging Face Colab

Creating high-quality scientific figures can be time-consuming and challenging, even though sketching ideas on paper is relatively easy. Furthermore, recreating existing figures that are not stored in formats preserving semantic information is equally complex. To tackle this problem, we introduce DeTikZify, a novel multimodal language model that automatically synthesizes scientific figures as semantics-preserving TikZ graphics programs based on sketches and existing figures. We also introduce an MCTS-based inference algorithm that enables DeTikZify to iteratively refine its outputs without the need for additional training.

https://github.com/potamides/DeTikZify/assets/53401822/203d2853-0b5c-4a2b-9d09-3ccb65880cd3

News

Installation

[!TIP] If you encounter difficulties with installation or inference on your own hardware, consider visiting our Hugging Face Space (please note that restarting the space can take up to 30 minutes). Should you experience long queues, you have the option to duplicate it with a paid private GPU runtime or run it locally with Docker. Additionally, you can try our demo on Google Colab. However, setting up the environment there might take some time, and the free tier only supports inference for the 1b models.

The Python package of DeTikZify can be easily installed using pip:

pip install 'detikzify[legacy] @ git+https://github.com/potamides/DeTikZify'

The [legacy] extra is only required if you plan to use the DeTikZifyv1 models. If you only plan to use DeTikZifyv2 you can remove it. If your goal is to run the included examples, it is easier to clone the repository and install it in editable mode like this: sh git clone https://github.com/potamides/DeTikZify pip install -e DeTikZify[examples] In addition, DeTikZify requires a full TeX Live 2023 installation, ghostscript, and poppler which you have to install through your package manager or via other means.

Usage

[!TIP] For interactive use and general usage tips, we recommend checking out our web UI, which can be started directly from the command line (use --help for a list of all options): sh python -m detikzify.webui --light

If all required dependencies are installed, the full range of DeTikZify features such as compiling, rendering, and saving TikZ graphics, and MCTS-based inference can be accessed through its programming interface:

DeTikZify Example

from operator import itemgetter

from detikzify.model import load
from detikzify.infer import DetikzifyPipeline

image = "https://w.wiki/A7Cc"
pipeline = DetikzifyPipeline(*load(
    model_name_or_path="nllg/detikzify-v2.5-8b",
    device_map="auto",
    torch_dtype="bfloat16",
))

# generate a single TikZ program
fig = pipeline.sample(image=image)

# if it compiles, rasterize it and show it
if fig.is_rasterizable:
    fig.rasterize().show()

# run MCTS for 10 minutes and generate multiple TikZ programs
figs = set()
for score, fig in pipeline.simulate(image=image, timeout=600):
    figs.add((score, fig))

# save the best TikZ program
best = sorted(figs, key=itemgetter(0))[-1][1]
best.save("fig.tex")

Through TikZero adapters and TikZero+ it is also possible to synthesize graphics programs conditioned on text (cf. our paper for details). Note that this currently only supported through the programming interface:

TikZero+ Example

from detikzify.model import load
from detikzify.infer import DetikzifyPipeline

caption = "A multi-layer perceptron with two hidden layers."
pipeline = DetikzifyPipeline(*load(
    model_name_or_path="nllg/tikzero-plus-10b",
    device_map="auto",
    torch_dtype="bfloat16",
))

# generate a single TikZ program
fig = pipeline.sample(text=caption)

# if it compiles, rasterize it and show it
if fig.is_rasterizable:
    fig.rasterize().show()

TikZero Example

from detikzify.model import load, load_adapter
from detikzify.infer import DetikzifyPipeline

caption = "A multi-layer perceptron with two hidden layers."
pipeline = DetikzifyPipeline(
    *load_adapter(
        *load(
            model_name_or_path="nllg/detikzify-v2-8b",
            device_map="auto",
            torch_dtype="bfloat16",
        ),
        adapter_name_or_path="nllg/tikzero-adapter",
    )
)

# generate a single TikZ program
fig = pipeline.sample(text=caption)

# if it compiles, rasterize it and show it
if fig.is_rasterizable:
    fig.rasterize().show()

More involved examples, for example for evaluation and tra

Core symbols most depended-on inside this repo

update
called by 16
detikzify/evaluate/imagesim.py
load
called by 13
detikzify/evaluate/__init__.py
from_pretrained
called by 13
detikzify/model/configuration_detikzify.py
expand
called by 13
detikzify/util/image.py
open
called by 12
detikzify/evaluate/kid.py
load_dataset
called by 11
detikzify/dataset/__init__.py
from_pretrained
called by 8
detikzify/model/v1/processing_detikzify.py
rasterize
called by 7
detikzify/infer/tikz.py

Shape

Method 280
Function 72
Class 69

Languages

Python100%

Modules by API surface

detikzify/infer/generate.py39 symbols
detikzify/model/modeling_detikzify.py35 symbols
detikzify/model/adapter/modeling_adapter.py29 symbols
examples/refine.py20 symbols
detikzify/util/generation.py19 symbols
detikzify/util/trainer.py18 symbols
detikzify/model/v1/modeling_detikzify.py18 symbols
detikzify/train/adapter/pretrain.py17 symbols
detikzify/webui/helpers.py15 symbols
detikzify/infer/tikz.py14 symbols
detikzify/evaluate/imagesim.py12 symbols
detikzify/evaluate/kid.py11 symbols

Dependencies from manifests, versioned

torch2.7.1 · 1×
torchvision0.22.1 · 1×

For agents

$ claude mcp add DeTikZify \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact