agentleFS
Seeed-ProjectsSeeed-Projects/Seeed-Jetson-DevelopTool/skills/codex/local-llm-text-to-image/AGENTS.md

Seeed-Jetson-DevelopTool / local-llm-text-to-image

AGENTS.md57 starsChanged 4 months agoMITView on GitHub

Run local text-to-image generation on Jetson Orin NX 16GB using Stable Diffusion. Covers three approaches — KerasCV, Hugging Face diffusers, and NVIDIA Jetson Containers (AUTOMATIC1111 WebUI). Includes a Flask API for on-demand image generation. Requires JetPack 5.1.1+.

  • Deletes or force-pushes
  • Installs packages

The file

We split this AGENTS.md into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Run one phase at a time. After each phase:

    line 14
  2. Very specific:

    If output contains [STOP] → stop, consult the failure decision tree.

    line 16
  3. Very specific:

    If output ends with [OK] → tell the user "Phase N complete" and proceed.

    line 17

≈ “Common” is an estimate: at least 1 in 5 of the 40,246 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Text-to-Image with Stable Diffusion on Jetson

Generate images from text prompts locally on Jetson using Stable Diffusion. Three deployment paths: KerasCV with TensorFlow, Hugging Face diffusers with PyTorch, and NVIDIA's containerized AUTOMATIC1111 WebUI.


Execution model

Run one phase at a time. After each phase:

  • Relay all output to the user.
  • If output contains [STOP] → stop, consult the failure decision tree.
  • If output ends with [OK] → tell the user "Phase N complete" and proceed.

Prerequisites

RequirementDetail
HardwareJetson Orin NX 16GB (e.g. reComputer J4012)
JetPack5.1.1+
Storage~20 GB free (models are large)
RAM tipsDisable desktop GUI to save ~800 MB. Consider disabling ZRAM and using swap.

Path A — KerasCV Stable Diffusion

Phase A1 — Create virtual environment and install TensorFlow (~10 min)

sudo apt install python3.8-venv
python3 -m venv kerasStableEnvironment
source kerasStableEnvironment/bin/activate
cd kerasStableEnvironment
pip install -U pip
pip install -U numpy grpcio absl-py py-cpuinfo psutil portpicker six mock requests gast h5py astor termcolor protobuf keras-applications keras-preprocessing wrapt google-pasta setuptools testresources

Install TensorFlow for your JetPack version (example for JP 5.1.1):

pip install --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v511 tensorflow==2.12.0+nv23.05

Verify:

python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

[OK] when GPU device is listed.

Phase A2 — Install PyTorch and KerasCV (~5 min)

sudo apt install libopenblas-dev
pip install --no-cache https://developer.download.nvidia.com/compute/redist/jp/v511/pytorch/torch-2.0.0+nv23.05-cp38-cp38-linux_aarch64.whl
pip install keras-cv==0.5.1 keras==2.12.0 Pillow

Verify PyTorch CUDA:

python -c "import torch; print(torch.cuda.is_available())"

[OK] when both return True/GPU.

Phase A3 — Generate an image (~2–5 min)

cat > generate_image.py << 'PYEOF'
import keras_cv
import keras
from PIL import Image

keras.mixed_precision.set_global_policy("mixed_float16")
model = keras_cv.models.StableDiffusion(img_width=512, img_height=512, jit_compile=True)
prompt = "a cute magical flying dog, fantasy art, golden color, high quality"
image = model.text_to_image(prompt, num_steps=25, batch_size=1)
Image.fromarray(image[0]).save("keras_generate_image.png")
print("Image saved: keras_generate_image.png")
PYEOF
python generate_image.py

[OK] when keras_generate_image.png is created.


Path B — Hugging Face Diffusers

Phase B1 — Create virtual environment and install PyTorch (~5 min)

python3 -m venv huggingfaceTesting
source huggingfaceTesting/bin/activate
cd huggingfaceTesting
sudo apt install libopenblas-dev
pip install --no-cache https://developer.download.nvidia.com/compute/redist/jp/v511/pytorch/torch-2.0.0+nv23.05-cp38-cp38-linux_aarch64.whl
pip install diffusers transformers accelerate

[OK] when all packages install.

Phase B2 — Generate with Stable Diffusion v1.5 (~5–10 min first run)

cat > stableDiffusion.py << 'PYEOF'
from diffusers import StableDiffusionPipeline
import torch

model_id = "runwayml/stable-diffusion-v1-5"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe = pipe.to("cuda")
prompt = "a master jedi cat in star wars holding a lightsaber, cinematic lighting"
image = pipe(prompt).images[0]
image.save("cat_jedi.png")
print("Image saved: cat_jedi.png")
PYEOF
python stableDiffusion.py

First run downloads model checkpoints (~4 GB).

[OK] when cat_jedi.png is created.

Phase B3 — Try SDXL-Turbo (optional, faster)

cat > sdxl_turbo.py << 'PYEOF'
from diffusers import AutoPipelineForText2Image
import torch

pipe = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16")
pipe.to("cuda")
prompt = "full body, cat dressed as a Viking, with weapon, hyper-detail, cinematic"
image = pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0.0).images[0]
image.save("sdxl-turbo.png")
print("Image saved: sdxl-turbo.png")
PYEOF
python sdxl_turbo.py

[OK] when image is generated (~30 s).


Path C — NVIDIA Jetson Containers (AUTOMATIC1111 WebUI)

Phase C1 — Install Jetson Containers (~3 min)

git clone https://github.com/dusty-nv/jetson-containers
cd jetson-containers
sudo apt update
sudo apt install -y python3-pip
pip3 install -r requirements.txt

[OK] when requirements install.

Phase C2 — Run Stable Diffusion WebUI container (~10–20 min first run)

cd jetson-containers
./run.sh $(./autotag stable-diffusion-webui)

Accept the container pull when prompted. The container downloads the model and starts the WebUI on port 7860.

Open browser: http://<jetson-ip>:7860

[OK] when the AUTOMATIC1111 WebUI loads with a checkpoint selected. [STOP] if no checkpoint appears — check disk space with df -h.

Phase C3 — Add Stable Diffusion XL model (optional)

CONTAINERS_DIR=~/jetson-containers
MODEL_DIR=$CONTAINERS_DIR/data/models/stable-diffusion/models/Stable-diffusion/
sudo chown -R $USER $MODEL_DIR
wget -P $MODEL_DIR https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors

Refresh the checkpoint dropdown in the WebUI.

[OK] when SDXL model appears in the dropdown.


Failure decision tree

SymptomAction
TensorFlow GPU not detectedVerify JetPack version matches TF wheel. Check CUDA: nvcc --version.
PyTorch torch.cuda.is_available() returns FalseReinstall PyTorch wheel matching your JetPack. Check nvidia-smi.
OOM during image generationReduce image size (e.g. 256x256). Disable desktop GUI. Enable swap.
Model download failsCheck disk space: df -h. Clear cache: rm -rf ~/.cache/huggingface.
AUTOMATIC1111 no checkpointDisk full. Free space and restart container.
Container gets killedNot enough RAM/swap. Add swap: sudo fallocate -l 8G /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile.
Flask API not accessibleCheck firewall: sudo ufw allow 8080. Verify Flask is running on 0.0.0.0.
pip install keras-cv failsCheck Python version matches (3.8 for JP 5.1.1). Try pip install --no-cache-dir.

Reference files

  • references/source.body.md — Full Seeed Wiki tutorial with all three deployment paths, Flask API code, screenshots, and additional model examples from Civitai (reference only)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.