fabiopacifici-bot/open-fantasia-imagegen

Python

1

67 commits

updated Sep 18, 2026

See the code

README

πŸͺ„ Open Fantasia β€” Local Image & Video Generation

Generate images locally on your GPU using FLUX.1-schnell or Stable Diffusion, and short videos with Wan2.1 β€” no external API, no cost per image or clip.

Hippocratic License HL3-LAW-MIL-SV


PromptResult
a cat astronaut on the mooncat astronaut
a samurai cat at sunsetsamurai cat
cyberpunk city at nightcyberpunk city
a dragon breathing fire over a medieval castledragon

Generated locally with FLUX.1-schnell, low quality preset. Speed varies by GPU.


Short clips generated locally with Wan2.1 (Wan-AI/Wan2.1-T2V-1.3B, mid quality):

PromptResult
a horse standing on a rocky beach at sunset
a black cat walking along the shoreline in backlight
a black cat standing in shallow surf, yellow-green eyes
a glowing blue whale shark swimming in dark water
a neon sign glowing pink-purple at night
a golden light streak flowing on a dark navy background
a flowing gold ribbon on a dark background
a small camera robot sitting among lush green plants

Generated locally with Wan2.1, mid quality preset. ~5s clips at 480P.


Features

  • πŸš€ Local generation β€” no API keys, no cloud, no per-image cost
  • ⚑ FLUX.1-schnell β€” fast distilled model, great quality
  • 🌸 FLUX.2-klein β€” lighter experimental model
  • 🎨 Stable Diffusion 1.5 β€” classic fallback, runs on 6GB VRAM
  • ⚑ SD-Turbo β€” near-instant generation (~1-3s at 512Γ—512)
  • 🎬 Wan2.1 text-to-video β€” short MP4 clips from text (~8GB VRAM)
  • πŸ”’ Batch generation β€” generate 1–4 images per prompt (different seeds)
  • πŸ’¬ OpenClaw slash command β€” /fantasia <prompt> with inline buttons
  • πŸ” Persistent server β€” model stays in VRAM, near-instant after first load

Video Generation (Wan2.1)

Generate a short MP4 clip from a text prompt using Wan-AI/Wan2.1-T2V-1.3B (~8.19 GB VRAM, 480P, ~4 min for a 5s clip on an RTX 4090):

curl -X POST http://localhost:8765/video \
  -H "Content-Type: application/json" \
  -d '{"prompt":"a cat walking through a neon city at night","quality":"mid"}'

Returns raw video/mp4 bytes. Saved to ~/.openclaw/media/fantasia/videos/<timestamp>.mp4.

FieldDefaultNotes
qualitymidlow (480Γ—480, 49f, 20 steps) Β· mid (480Γ—832, 81f, 30 steps) Β· high (480Γ—832, 81f, 50 steps)
steps30Inference steps
num_frames8116 fps β†’ 81 β‰ˆ 5s
guidance_scale6.0Wan recommends 6.0
seed42Reproducibility

Model aliases: wan, wan13, wan2.1, wan-1.3b β†’ Wan-AI/Wan2.1-T2V-1.3B

VRAM note: The server auto-unloads the image/Qwen pipelines before loading Wan2.1 to free VRAM, and reloads them on the next image request.


Requirements

  • Python 3.10+
  • CUDA GPU β€” 8GB VRAM minimum (16GB recommended for FLUX)
  • HuggingFace account + HF_TOKEN in .env (see .env.example)
  • ~16GB disk space for FLUX.1-schnell (downloaded once)

Quick Start

git clone https://github.com/fabiopacifici-bot/open-fantasia-imagegen
cd open-fantasia-imagegen
cp .env.example .env   # add your HF_TOKEN
bash setup.sh

setup.sh will:

  1. Create a Python venv and install dependencies
  2. Download the recommended model (~16GB, one-time)
  3. Install and enable the systemd service
  4. Start the server at http://localhost:8765

Usage

/fantasia a samurai cat at sunset
/fantasia cyberpunk city --quality high
/fantasia quick sketch --quality low --count 3
/fantasia portrait --model klein
/fantasia setup        ← first-time setup

Inline buttons: Call /fantasia with no prompt to get model/quality/count selection buttons.

Direct API

# Generate an image
curl -X POST http://localhost:8765/generate \
  -H "Content-Type: application/json" \
  -d '{"prompt": "a cat in space", "quality": "low", "enhance": true, "count": 1}'

# Health check
curl http://localhost:8765/health

CLI

.venv/bin/python src/imagegen.py \
  --prompt "a samurai cat at sunset" \
  --quality low \
  --output output.png

Quality Presets

PresetResolutionStepsApprox. Speed
low512Γ—5124~1-5 min (GPU dependent)
mid768Γ—7688~3-10 min (GPU dependent)
high1024Γ—102420~10-20 min (GPU dependent)

Note: Speed varies significantly by GPU. FLUX runs in BF16 precision. Use torchao autoquant to reduce VRAM usage and improve throughput.


Models

FlagModelVRAMNotes
schnell (default)black-forest-labs/FLUX.1-schnell~16GBBest quality, BF16 precision
kleinblack-forest-labs/FLUX.2-klein-base-9B~16GBExperimental, lighter
sd15stable-diffusion-v1-5/stable-diffusion-v1-5~4GBFast, classic
turbostabilityai/sd-turbo~4GBNear-instant, ~1-3s at 512Γ—512

Server Management

# Start / stop / restart
systemctl --user start fantasia.service
systemctl --user stop fantasia.service
systemctl --user restart fantasia.service

# Status & logs
systemctl --user status fantasia.service
journalctl --user -u fantasia.service -f

Output images are saved to ~/.openclaw/media/fantasia/.


Project Structure

open-fantasia-imagegen/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ server.py       # FastAPI inference server
β”‚   └── imagegen.py     # Pipeline loader + generation logic
β”œβ”€β”€ assets/             # README demo images
β”œβ”€β”€ setup.sh            # First-time setup script
β”œβ”€β”€ .env.example        # Environment variable template
β”œβ”€β”€ requirements.txt
└── .specs/             # Plans, docs, debugging notes

License

MIT

Roadmap

v1.3 β€” Turbo mode βœ…

  • sd-turbo available as --model turbo (stabilityai/sd-turbo)
  • ~1-3s generation at 512Γ—512 on CUDA

v2.0 β€” Image Editing

  • Instruction-based image editing via Qwen2.5-VL
  • New endpoint: POST /edit β€” { "image": "<path>", "instruction": "make the sky purple" }
  • Slash command: /fantasia edit <image> <instruction>

fabiopacifici-bot/open-fantasia-imagegen

Python

1

67 commits

updated Sep 18, 2026

See the code

README

πŸͺ„ Open Fantasia β€” Local Image & Video Generation

Generate images locally on your GPU using FLUX.1-schnell or Stable Diffusion, and short videos with Wan2.1 β€” no external API, no cost per image or clip.

Hippocratic License HL3-LAW-MIL-SV


PromptResult
a cat astronaut on the mooncat astronaut
a samurai cat at sunsetsamurai cat
cyberpunk city at nightcyberpunk city
a dragon breathing fire over a medieval castledragon

Generated locally with FLUX.1-schnell, low quality preset. Speed varies by GPU.


Short clips generated locally with Wan2.1 (Wan-AI/Wan2.1-T2V-1.3B, mid quality):

PromptResult
a horse standing on a rocky beach at sunset
a black cat walking along the shoreline in backlight
a black cat standing in shallow surf, yellow-green eyes
a glowing blue whale shark swimming in dark water
a neon sign glowing pink-purple at night
a golden light streak flowing on a dark navy background
a flowing gold ribbon on a dark background
a small camera robot sitting among lush green plants

Generated locally with Wan2.1, mid quality preset. ~5s clips at 480P.


Features

  • πŸš€ Local generation β€” no API keys, no cloud, no per-image cost
  • ⚑ FLUX.1-schnell β€” fast distilled model, great quality
  • 🌸 FLUX.2-klein β€” lighter experimental model
  • 🎨 Stable Diffusion 1.5 β€” classic fallback, runs on 6GB VRAM
  • ⚑ SD-Turbo β€” near-instant generation (~1-3s at 512Γ—512)
  • 🎬 Wan2.1 text-to-video β€” short MP4 clips from text (~8GB VRAM)
  • πŸ”’ Batch generation β€” generate 1–4 images per prompt (different seeds)
  • πŸ’¬ OpenClaw slash command β€” /fantasia <prompt> with inline buttons
  • πŸ” Persistent server β€” model stays in VRAM, near-instant after first load

Video Generation (Wan2.1)

Generate a short MP4 clip from a text prompt using Wan-AI/Wan2.1-T2V-1.3B (~8.19 GB VRAM, 480P, ~4 min for a 5s clip on an RTX 4090):

curl -X POST http://localhost:8765/video \
  -H "Content-Type: application/json" \
  -d '{"prompt":"a cat walking through a neon city at night","quality":"mid"}'

Returns raw video/mp4 bytes. Saved to ~/.openclaw/media/fantasia/videos/<timestamp>.mp4.

FieldDefaultNotes
qualitymidlow (480Γ—480, 49f, 20 steps) Β· mid (480Γ—832, 81f, 30 steps) Β· high (480Γ—832, 81f, 50 steps)
steps30Inference steps
num_frames8116 fps β†’ 81 β‰ˆ 5s
guidance_scale6.0Wan recommends 6.0
seed42Reproducibility

Model aliases: wan, wan13, wan2.1, wan-1.3b β†’ Wan-AI/Wan2.1-T2V-1.3B

VRAM note: The server auto-unloads the image/Qwen pipelines before loading Wan2.1 to free VRAM, and reloads them on the next image request.


Requirements

  • Python 3.10+
  • CUDA GPU β€” 8GB VRAM minimum (16GB recommended for FLUX)
  • HuggingFace account + HF_TOKEN in .env (see .env.example)
  • ~16GB disk space for FLUX.1-schnell (downloaded once)

Quick Start

git clone https://github.com/fabiopacifici-bot/open-fantasia-imagegen
cd open-fantasia-imagegen
cp .env.example .env   # add your HF_TOKEN
bash setup.sh

setup.sh will:

  1. Create a Python venv and install dependencies
  2. Download the recommended model (~16GB, one-time)
  3. Install and enable the systemd service
  4. Start the server at http://localhost:8765

Usage

/fantasia a samurai cat at sunset
/fantasia cyberpunk city --quality high
/fantasia quick sketch --quality low --count 3
/fantasia portrait --model klein
/fantasia setup        ← first-time setup

Inline buttons: Call /fantasia with no prompt to get model/quality/count selection buttons.

Direct API

# Generate an image
curl -X POST http://localhost:8765/generate \
  -H "Content-Type: application/json" \
  -d '{"prompt": "a cat in space", "quality": "low", "enhance": true, "count": 1}'

# Health check
curl http://localhost:8765/health

CLI

.venv/bin/python src/imagegen.py \
  --prompt "a samurai cat at sunset" \
  --quality low \
  --output output.png

Quality Presets

PresetResolutionStepsApprox. Speed
low512Γ—5124~1-5 min (GPU dependent)
mid768Γ—7688~3-10 min (GPU dependent)
high1024Γ—102420~10-20 min (GPU dependent)

Note: Speed varies significantly by GPU. FLUX runs in BF16 precision. Use torchao autoquant to reduce VRAM usage and improve throughput.


Models

FlagModelVRAMNotes
schnell (default)black-forest-labs/FLUX.1-schnell~16GBBest quality, BF16 precision
kleinblack-forest-labs/FLUX.2-klein-base-9B~16GBExperimental, lighter
sd15stable-diffusion-v1-5/stable-diffusion-v1-5~4GBFast, classic
turbostabilityai/sd-turbo~4GBNear-instant, ~1-3s at 512Γ—512

Server Management

# Start / stop / restart
systemctl --user start fantasia.service
systemctl --user stop fantasia.service
systemctl --user restart fantasia.service

# Status & logs
systemctl --user status fantasia.service
journalctl --user -u fantasia.service -f

Output images are saved to ~/.openclaw/media/fantasia/.


Project Structure

open-fantasia-imagegen/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ server.py       # FastAPI inference server
β”‚   └── imagegen.py     # Pipeline loader + generation logic
β”œβ”€β”€ assets/             # README demo images
β”œβ”€β”€ setup.sh            # First-time setup script
β”œβ”€β”€ .env.example        # Environment variable template
β”œβ”€β”€ requirements.txt
└── .specs/             # Plans, docs, debugging notes

License

MIT

Roadmap

v1.3 β€” Turbo mode βœ…

  • sd-turbo available as --model turbo (stabilityai/sd-turbo)
  • ~1-3s generation at 512Γ—512 on CUDA

v2.0 β€” Image Editing

  • Instruction-based image editing via Qwen2.5-VL
  • New endpoint: POST /edit β€” { "image": "<path>", "instruction": "make the sky purple" }
  • Slash command: /fantasia edit <image> <instruction>