Termux-Diffusion
Production On-Device AI Image Generation Framework for Android Termux & Samsung Galaxy
Dual-Engine Architecture (Python & Node.js / TypeScript) with Native Bionic ARM64 Tensor Acceleration
1. System Overview
termux-diffusion is an enterprise-grade, on-device AI text-to-image synthesis pipeline designed specifically for Android Termux environments and Samsung Galaxy hardware.
Unlike desktop-centric WebUI ports that require heavy containerization (e.g., PRoot Linux / Ubuntu) or suffer from memory exhaustion under the Android Low Memory Killer (LMK), termux-diffusion executes directly against native Android Bionic libc with ARM64 NEON SIMD vectorization and GGML quantized tensor weights.
2. Automated Bootstrap & Installation
Option A: One-Line Zero-Touch Bootstrap (Recommended)
Run the platform bootstrap script in Termux to automatically verify toolchains, storage permissions, and native engine binaries:
Python Runtime
curl -sL https://raw.githubusercontent.com/uno-km/termux-diffusion/main/docs/install.sh | bash
Node.js / TypeScript Runtime
curl -sL https://raw.githubusercontent.com/uno-km/termux-diffusion/main/docs/install-node.sh | bash
Option B: Package Manager Installation
Python (PyPI)
pip install termux-diffusion && termux-diffusion-install
Node.js (npm)
npm install -g termux-diffusion && npx termux-diffusion install
3. Core Architectural Capabilities
- Zero-PRoot Native Bionic Execution: Executes natively on ARM64 without container overhead, achieving maximum memory efficiency.
- Integrated Model Hub: Built-in streaming downloader with automatic checksum verification and cache persistence.
- Power & WakeLock Management (
TermuxWakeLock): Automatically holds Android CPU WakeLock during inference, preventing kernel suspension when the screen turns off. - Low-Memory & LMK Guard: Inspects physical memory and Android zRAM (Samsung RAM Plus) before allocating tensor weight buffers.
- Samsung Gallery Integration: Automatically persists generated outputs to
~/storage/pictures/TermuxDiffusion/and triggersandroid.intent.action.MEDIA_SCANNER_SCAN_FILEfor instant indexing in Samsung Gallery. - big.LITTLE Core Affinity Tuning: Auto-detects Exynos (e.g., 1380, 1480, 2400) and Snapdragon cluster topologies to maintain high sustained clock rates without thermal throttling.
- Hardware Compute Selection: Explicit compute backend targeting via
device="cpu"ordevice="gpu".
4. Built-in Model Hub Presets
| Preset | Model & Quantization | Size | Latency Baseline (Exynos 1380) | Recommended Workload |
|---|---|---|---|---|
"realistic" |
Realistic Vision V6.0 B1 (Q4_K) | 1.62 GB | ~25 min (10 steps) | High-fidelity photorealism (portraits, skin textures, lighting) |
"speed" |
Stable Diffusion 1.5 Base (Q4_1) | 1.59 GB | ~15 min (10 steps) | General-purpose drafting and composition |
"sdxs" |
SDXS 512-0.9 Mobile (Q4_0) | 450 MB | ~2.5 min (2 steps) | Ultra-low latency mobile prototyping |
"turbo" |
SD Turbo (Q4_0) | 1.20 GB | ~4 min (1 step) | Single-step real-time inference |
"anime" |
DreamShaper 8 (Q4_K) | 1.65 GB | ~20 min (10 steps) | 2D / 2.5D stylized illustration and animation art |
5. Usage & Integration
Python API
from termux_diffusion import generate
result = generate(
prompt="RAW photo, portrait of a happy smiling young Korean man in his 30s wearing glasses and hoodie, working on laptop, photorealistic, cinematic",
model="realistic",
device="cpu",
steps=10,
cfg_scale=4.0,
output="developer.png"
)
print(f"Output Path: {result.path}")
print(f"Android MediaStore: {result.gallery_path}")
print(f"Elapsed Time: {result.elapsed_sec:.2f}s")
Node.js / TypeScript API
const { generate } = require('termux-diffusion');
async function main() {
const result = await generate({
prompt: 'cyberpunk cat with neon collar in rainy alley, 8k, photorealistic',
model: 'speed',
device: 'cpu',
steps: 10,
output: 'cyber_cat.png'
});
console.log(`Output Path: ${result.path}`);
console.log(`Android MediaStore: ${result.galleryPath}`);
}
main().catch(console.error);
6. Custom Models & Hugging Face Resolution
1. Direct Hugging Face Repository Identifier
Pass any repository ID and .gguf filename. The framework resolves, streams, caches, and executes the weights:
generate(
"1girl, anime masterpiece, vibrant colors",
model="second-state/DreamShaper-8-GGUF/dreamshaper-8-Q4_k.gguf"
)
2. Local File Reference
generate(
"fantasy landscape at sunrise",
model="~/storage/downloads/custom_model.gguf"
)
3. Alias Registration (register_model)
from termux_diffusion import register_model, generate
register_model("waifu", repo_id="second-state/DreamShaper-8-GGUF", filename="dreamshaper-8-Q4_k.gguf")
generate("anime portrait", model="waifu")
7. Pre-flight Diagnostic Tool
Verify system packages, architecture, available memory, and native engine status:
# Python
termux-diffusion-doctor
# Node.js
npx termux-diffusion doctor
8. License
Released under the MIT License. Maintained by uno-km.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file termux_diffusion-1.0.0.tar.gz.
File metadata
- Download URL: termux_diffusion-1.0.0.tar.gz
- Upload date:
- Size: 23.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
028e2d36a2fe26ab9c5c4191ffd8d12c4b794f27bf51ad527fcbe7b7adb55f4b
|
|
| MD5 |
af06216fdb404219f90b3e92812eb59b
|
|
| BLAKE2b-256 |
a6203fb05dd34b7dcc32f4222f0fc6e2359d27ad32e2e83e060a21357098b83f
|
File details
Details for the file termux_diffusion-1.0.0-py3-none-any.whl.
File metadata
- Download URL: termux_diffusion-1.0.0-py3-none-any.whl
- Upload date:
- Size: 21.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13c1e3db136e99c53f3eeb51937d0edb0154dfb7dea9f93d40c39ce35e132004
|
|
| MD5 |
f7dc7d5cf9b86e322081f89b8c6796bd
|
|
| BLAKE2b-256 |
6394d3343857d99d10a13a421ed02bff72757fb101ea532f35f44454afa74b48
|