sd-text-fix / docs /DEVELOPMENT.md
Kazzze's picture
Update to current version
2a261b0 verified
|
Raw History Blame Contribute Delete
3.45 kB

Development

Layout

text_fix/            the core: core.py (find, erase, write), fonts.py; web.py (the server side of the editor)
ui/                  the editor: React + TypeScript + Tailwind; ui/dist is the build the hosts serve
scripts/             AUTOMATIC1111 / Forge / reForge: routes, saving, the model pass, the gallery button
javascript/          host page script: the icon under Generate, the button under the gallery, the editor's window
style.css            styles of those buttons
comfy_nodes.py       ComfyUI node
comfy_web/           ComfyUI page script: the Open editor button on the node
__init__.py          ComfyUI entry point
fonts/bundled/       the bundled fonts and their licenses
docs/                this documentation and its pictures

Constraints

  • Python stays 3.9-compatible: List / Optional from typing, no lowercase generics.
  • Host page script (javascript/) is ES5 style: no arrow functions, no template literals. comfy_web/ and ui/ are modern JavaScript and TypeScript.
  • The editor's parts are shadcn-style components on Radix (ui/src/components/ui/): reuse them before adding new ones. No new UI or CSS frameworks.
  • ui/dist is committed: users install without Node.js. Rebuild it with every change to ui/src.
  • No new Python dependencies. numpy, opencv-python and Pillow are what both hosts ship.
  • The core takes and returns RGB uint8 arrays and imports nothing from a host.
  • New inputs of the ComfyUI node go at the end of optional: a saved workflow keeps its widget values by position.

Building the editor

cd ui
npm install
npm run build        # type check, then ui/dist
npm run dev          # Vite on port 5175, with /text_fix proxied to a WebUI on 7860

Running a change

AUTOMATIC1111 / Forge / reForge. Reload UI in the page footer is enough: the script drops the imported text_fix package on reload, so changes in the core are picked up without restarting the process. Refresh the browser page afterwards.

ComfyUI. Restart it. Link or clone the folder into ComfyUI/custom_nodes.

The editor. After npm run build, close and open the editor again: each opening loads the page afresh.

The core alone. It runs in any Python that has the three packages:

import numpy as np
from PIL import Image
import text_fix

rgb = np.asarray(Image.open("image.png").convert("RGB"))
for selection in text_fix.find_all(rgb):
    print(selection.quad, selection.color)
selection = text_fix.locate(rgb, 550, 724)            # the text at a point
out = text_fix.replace(rgb, selection, "POLICE", text_fix.Look())
Image.fromarray(out).save("out.png")
Image.fromarray(text_fix.preview(rgb, [selection])).save("found.png")

Checking a change

There is no test suite yet. Before a change to the core is taken, it is run on a few images of different kinds and the results are looked at: thin text and bold text, light on dark and dark on light, text on a plate of its own, bent text, several lines. For each: what a click finds, what the search finds, and what is left after erasing.

Changes to the editor are checked in a running host, in both: the A1111 family and ComfyUI. The routes can also be driven with FastAPI's TestClient and a stand-in Host, without a model.

Git

Work goes on a feature branch (feat/..., fix/...), not on main.