Skip to content

vra/sanana

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

20 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽจ sanana

Turn your photos into Ghibli-style illustrations in one command

PyPI Python License CI

English | ๐ŸŒ ไธญๆ–‡ๆ–‡ๆกฃ

sanana is a local, privacy-first image editor that transforms ordinary photos into cartoon-style illustrations โ€” think Studio Ghibli, anime, or hand-drawn aesthetics. It runs entirely on your own machine using CPU only, with no image ever leaving your computer.

โš ๏ธ Disclaimer: sanana is a third-party, community-driven Python wrapper โ€” it is not an official product of Alibaba or the MNN team. The underlying inference engine (MNN) and the diffusion model (MNN-Sana-Edit-V2) are developed by Alibaba; this repository only provides a convenient CLI and Python API around them.

๐Ÿ“ Prompt limitation: The model was trained with a fixed prompt, so custom --prompt values have no effect on the output style. The model only knows one style (cartoon/Ghibli-like), and changing the prompt will not switch to a different aesthetic.

Under the hood, sanana is powered by Alibaba MNN, a high-performance deep-learning inference engine, and the MNN-Sana-Edit-V2 diffusion model. The model is distilled to produce high-quality results in just 10 inference steps, making it fast enough for everyday use on regular laptops and desktops. On first run, the ~1.2GB model is downloaded automatically from ModelScope โ€” after that, everything works offline.

sanana is also the Python desktop companion to the official MNN Chat mobile apps: the same Sana model runs on both Android and iOS, so you can edit photos on your phone or computer with identical results.

# One-shot โ€” run without installing anything (requires uv)
uvx sanana photo.jpg

# Or install permanently with uv
uv tool install sanana
sanana photo.jpg

โœจ Showcase

Original ๐Ÿช„ sanana Magic

๐Ÿš€ Quick Start

# Run once without installing (requires uv)
uvx sanana photo.jpg

# Or install permanently
uv tool install sanana
sanana photo.jpg

The model (~1.2GB) will be downloaded automatically on first run.


๐Ÿ”ฅ Highlights

๐ŸŽจ Cartoon Style Transfer Photos โ†’ Ghibli/anime illustrations in one command
๐Ÿ  Fully Local No internet, no cloud upload, absolute privacy
๐Ÿ Python Native pybind11 C++ extension, inference inside Python process
๐Ÿ’ป CPU-only MNN high-performance engine, runs on ordinary machines
โšก 10 Steps MNN-Sana-Edit-V2 knowledge-distilled model, high quality with few steps
๐Ÿ“ Fixed Prompt Model trained on a single style; custom prompts do not change the output

๐Ÿ“ฑ Mobile Apps

The same MNN-Sana-Edit-V2 model also runs on mobile devices:


๐Ÿ“ฆ Installation

Option 1: uv (Recommended)

# Run once without installing
uvx sanana photo.jpg

# Or install permanently
uv tool install sanana

Option 2: pip

pip install sanana

This automatically clones and builds MNN (requires git, cmake, C++ compiler).

Option 3: From Source

git clone https://github.com/vra/sanana.git
cd sanana
uv sync
source .venv/bin/activate
sanana photo.jpg

๐ŸŽฎ Usage

CLI

# Minimal
sanana photo.jpg

# Custom output
sanana photo.jpg -o output.jpg

# Custom prompt (note: has no effect on output style)
sanana photo.jpg --prompt "Ghibli style"

# Full args
sanana photo.jpg \
  -o out.jpg \
  --prompt "Convert to Ghibli style" \
  --steps 10 \
  --seed 42 \
  --width 512 \
  --height 512
Argument Description Default
input Input image path Required
-o, --output Output path input_stem_cartoon.jpg
--prompt Style prompt Convert to a cartoon-style illustration
--steps Inference steps 10
--seed Random seed 42
--width/--height Output size 512x512

Python API

from sanana import edit_image

# One-shot
edit_image("./photo.jpg", steps=10, seed=42)
from sanana import SanaEditor

# Advanced: reuse model for batch processing
editor = SanaEditor(backend="cpu", memory_mode=2)
editor.load()

for img in ["a.jpg", "b.jpg", "c.jpg"]:
    editor.run(
        input_image=img,
        output_image=img.replace(".jpg", "_cartoon.jpg"),
        steps=10,
    )

โš™๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  ๐Ÿ Python Layer                            โ”‚
โ”‚     sanana (CLI / API)                      โ”‚
โ”‚            โ†“ import                         โ”‚
โ”‚     sanana._sana_diffusion                  โ”‚
โ”‚     (pybind11 C++ Extension)                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                     โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  ๐Ÿ”ง C++ Layer (MNN)                         โ”‚
โ”‚     SanaLlm โ”€โ”€โ†’ SanaDiffusion โ”€โ”€โ†’ Image     โ”‚
โ”‚     (Text Encode) (Flow Matching Denoise)   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  • Text Encoding: Qwen3-0.6B LLM processes the prompt
  • Feature Bridging: Connector โ†’ Projector maps to DiT space
  • VAE Encode: Input image โ†’ Latent (img2img)
  • DiT Denoise: Euler sampling + Flow Shift, 10 steps
  • VAE Decode: Latent โ†’ Final image

๐Ÿ–ฅ๏ธ Performance

Apple MacBook Pro M3 (CPU, 512ร—512, 10 steps):

Stage Time
LLM Text Encoding ~1.5 s
VAE Encode ~3 s
DiT Denoise (10 steps) ~22 s
VAE Decode ~5 s
Total ~32 s

๐Ÿงฉ Requirements

Platform Status Notes
macOS (Apple Silicon / Intel) โœ… Supported Best performance on M1/M2/M3
Linux (x86_64 / ARM64) โœ… Supported Tested on Ubuntu 22.04+
Windows (x86_64) โš ๏ธ Experimental Requires Visual Studio + OpenCV, CI unstable
  • Python: 3.10+
  • Compiler: Clang/GCC/MSVC (C++17)
  • Tools: git, cmake

โ“ FAQ

Q: MNN not found during install?
A: setup.py auto-clones and builds MNN. Just ensure git, cmake, and a C++ compiler are installed.

Q: First run is slow?
A: The model (~1.2GB) is downloaded on first use. Subsequent runs are fast.

Q: GPU support?
A: CPU by default. Use backend="metal" for Metal (macOS), requires MNN built with GPU flags.

Q: Commercial use?
A: Code is Apache-2.0. Model files follow the original publisher's license.


๐Ÿค Contributing

Issues and PRs welcome! See CONTRIBUTING.md.

๐Ÿ“œ Changelog

See CHANGELOG.md.

๐Ÿ“„ License

Code: Apache-2.0.
Model: MNN-Sana-Edit-V2 belongs to its original publisher.


If this project helps you, please give it a โญ Star!

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors