physicsrob/torchwright-doom-e1m1
334
1"""Minimal runnable example for this checkpoint.2 3This is complete executable code, not pseudocode. It loads an ordinary4Hugging Face text-generation checkpoint, runs the bundled E1M1 prompt, executes5the cursor and pixel commands emitted by the model, and writes ``frame.png``.6It imports no TorchWright or DOOM implementation.7 8The loop below is all of the post-processing. The transformer emits every9cursor direction, cursor coordinate, palette index, and run width. This program10only remembers the cursor, looks up RGB in DOOM's static 256-color palette, and11asks Pillow to paint those pixels. It contains no map data, geometry, visibility12tests, texture sampling, lighting calculations, or logic for choosing what gets13drawn or in what order.14 15This short path is intended to make the mechanism easy to inspect. For16canonical reproduction, download the checkpoint repository and use:17 18 python infer.py --model . --prompt examples/e1m1_prompt.txt --output out19 python tools/txt_to_png.py --input out/output.txt --output out/frame.png20 21That path validates the bundle, preserves the exact generated token IDs,22records termination and memory information, and validates the decoder inputs.23See ``README.md`` for details.24"""25 26import json27from pathlib import Path28 29from huggingface_hub import hf_hub_download30from PIL import Image31from transformers import pipeline32 33MODEL = "physicsrob/torchwright-doom-e1m1"34SCREEN = (320, 200)35 36prompt = Path(hf_hub_download(MODEL, "examples/e1m1_prompt.txt")).read_text()37colors = json.loads(Path(hf_hub_download(MODEL, "doom_palette.json")).read_text())[38 "colors"39]40 41generate = pipeline(42 "text-generation", model=MODEL, device_map="auto", trust_remote_code=False43)44output = generate(prompt, return_full_text=False)[0]["generated_text"]45 46image = Image.new("RGB", SCREEN)47x = y = 048advance_x = False49 50for token in output.split():51 command, _, arguments = token.rstrip(")").partition("(")52 if command == "setCursorDirectionX":53 advance_x = True54 elif command == "setCursorDirectionY":55 advance_x = False56 elif command == "setCursorX":57 x = int(arguments)58 elif command == "setCursorY":59 y = int(arguments)60 elif command == "pixel":61 color, width = map(int, arguments.split(","))62 image.paste(tuple(colors[color]), (x, y, x + width, y + 1))63 if advance_x:64 x += width65 else:66 y += 167 68image.save("frame.png")69 