termux-diffusion 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- termux_diffusion/__init__.py +74 -0
- termux_diffusion/cli.py +112 -0
- termux_diffusion/core.py +240 -0
- termux_diffusion/exceptions.py +35 -0
- termux_diffusion/hub.py +332 -0
- termux_diffusion/installer.py +206 -0
- termux_diffusion/platform.py +220 -0
- termux_diffusion/py.typed +1 -0
- termux_diffusion-1.0.0.dist-info/LICENSE +21 -0
- termux_diffusion-1.0.0.dist-info/METADATA +199 -0
- termux_diffusion-1.0.0.dist-info/RECORD +14 -0
- termux_diffusion-1.0.0.dist-info/WHEEL +5 -0
- termux_diffusion-1.0.0.dist-info/entry_points.txt +4 -0
- termux_diffusion-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"""Platform inspection, Samsung Galaxy hardware detection, memory checks, and Android OS bridges."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import os
|
|
5
|
+
import platform
|
|
6
|
+
import shutil
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Dict, Optional, Tuple
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger("termux_diffusion.platform")
|
|
13
|
+
|
|
14
|
+
# Android Termux standard paths
|
|
15
|
+
TERMUX_PREFIX = os.environ.get("PREFIX", "/data/data/com.termux/files/usr")
|
|
16
|
+
TERMUX_HOME = os.environ.get("HOME", "/data/data/com.termux/files/home")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def is_android_termux() -> bool:
|
|
20
|
+
"""Check whether the current runtime environment is native Android Termux."""
|
|
21
|
+
if os.environ.get("TERMUX_VERSION") or os.environ.get("TERMUX_APP_PID"):
|
|
22
|
+
return True
|
|
23
|
+
if os.path.exists("/data/data/com.termux"):
|
|
24
|
+
return True
|
|
25
|
+
if os.path.exists(f"{TERMUX_PREFIX}/bin/pkg"):
|
|
26
|
+
return True
|
|
27
|
+
return False
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def is_arm64() -> bool:
|
|
31
|
+
"""Check whether the host CPU architecture is 64-bit ARM (aarch64 / arm64)."""
|
|
32
|
+
machine = platform.machine().lower()
|
|
33
|
+
return machine in ("aarch64", "arm64", "armv8l", "armv8b")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def get_default_cache_dir() -> Path:
|
|
37
|
+
"""Return default cache directory for models and downloaded assets."""
|
|
38
|
+
custom_cache = os.environ.get("TERMUX_DIFFUSION_CACHE")
|
|
39
|
+
if custom_cache:
|
|
40
|
+
path = Path(os.path.expanduser(custom_cache)).resolve()
|
|
41
|
+
else:
|
|
42
|
+
path = Path(os.path.expanduser("~/.cache/termux-diffusion")).resolve()
|
|
43
|
+
path.mkdir(parents=True, exist_ok=True)
|
|
44
|
+
return path
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def get_galaxy_gallery_dir() -> Path:
|
|
48
|
+
"""Resolve and ensure the Samsung Galaxy / Android media pictures directory."""
|
|
49
|
+
# Preferred: ~/storage/pictures/TermuxDiffusion
|
|
50
|
+
user_pictures = Path(os.path.expanduser("~/storage/pictures/TermuxDiffusion"))
|
|
51
|
+
if user_pictures.parent.exists():
|
|
52
|
+
user_pictures.mkdir(parents=True, exist_ok=True)
|
|
53
|
+
return user_pictures
|
|
54
|
+
|
|
55
|
+
# Secondary: /storage/emulated/0/Pictures/TermuxDiffusion
|
|
56
|
+
sdcard_pictures = Path("/storage/emulated/0/Pictures/TermuxDiffusion")
|
|
57
|
+
try:
|
|
58
|
+
sdcard_pictures.mkdir(parents=True, exist_ok=True)
|
|
59
|
+
return sdcard_pictures
|
|
60
|
+
except (PermissionError, OSError):
|
|
61
|
+
pass
|
|
62
|
+
|
|
63
|
+
# Fallback to local workspace output directory
|
|
64
|
+
fallback = get_default_cache_dir() / "outputs"
|
|
65
|
+
fallback.mkdir(parents=True, exist_ok=True)
|
|
66
|
+
return fallback
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def export_to_android_gallery(source_image_path: Path, destination_name: Optional[str] = None) -> Path:
|
|
70
|
+
"""Copy rendered image to Samsung Gallery directory and broadcast media scanner intent.
|
|
71
|
+
|
|
72
|
+
This ensures that images generated by termux-diffusion appear immediately in
|
|
73
|
+
the Samsung Gallery app without requiring a reboot.
|
|
74
|
+
"""
|
|
75
|
+
source_image_path = Path(source_image_path).resolve()
|
|
76
|
+
if not source_image_path.exists():
|
|
77
|
+
raise FileNotFoundError(f"Source image does not exist: {source_image_path}")
|
|
78
|
+
|
|
79
|
+
dest_dir = get_galaxy_gallery_dir()
|
|
80
|
+
if destination_name is None:
|
|
81
|
+
destination_name = source_image_path.name
|
|
82
|
+
|
|
83
|
+
dest_path = dest_dir / destination_name
|
|
84
|
+
shutil.copy2(source_image_path, dest_path)
|
|
85
|
+
logger.info("Exported AI image to Samsung Gallery path: %s", dest_path)
|
|
86
|
+
|
|
87
|
+
# Broadcast media scanner intent if on Android
|
|
88
|
+
_trigger_media_scanner(dest_path)
|
|
89
|
+
return dest_path
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _trigger_media_scanner(image_path: Path) -> None:
|
|
93
|
+
"""Broadcast android.intent.action.MEDIA_SCANNER_SCAN_FILE so Galaxy Gallery indexes the file."""
|
|
94
|
+
if not is_android_termux():
|
|
95
|
+
return
|
|
96
|
+
|
|
97
|
+
am_binary = shutil.which("am") or shutil.which("termux-am")
|
|
98
|
+
if not am_binary:
|
|
99
|
+
return
|
|
100
|
+
|
|
101
|
+
file_uri = f"file://{image_path.resolve()}"
|
|
102
|
+
try:
|
|
103
|
+
subprocess.run(
|
|
104
|
+
[am_binary, "broadcast", "-a", "android.intent.action.MEDIA_SCANNER_SCAN_FILE", "-d", file_uri],
|
|
105
|
+
capture_output=True,
|
|
106
|
+
timeout=3.0,
|
|
107
|
+
check=False
|
|
108
|
+
)
|
|
109
|
+
except Exception as exc:
|
|
110
|
+
logger.debug("Media scanner broadcast note: %s", exc)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def get_optimal_thread_count() -> int:
|
|
114
|
+
"""Calculate the optimal number of inference threads for Galaxy Exynos / Snapdragon CPUs.
|
|
115
|
+
|
|
116
|
+
In big.LITTLE architectures (e.g. 4 Performance + 4 Efficiency cores), running on all 8
|
|
117
|
+
cores causes severe thermal throttling and cache thrashing. Using the performance cluster
|
|
118
|
+
count (typically 4 threads) yields faster inference and lower heat.
|
|
119
|
+
"""
|
|
120
|
+
total_cores = os.cpu_count() or 4
|
|
121
|
+
if total_cores >= 8:
|
|
122
|
+
return 4
|
|
123
|
+
elif total_cores >= 6:
|
|
124
|
+
return 4
|
|
125
|
+
elif total_cores >= 4:
|
|
126
|
+
return 4
|
|
127
|
+
return max(1, total_cores)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def get_memory_info() -> Dict[str, int]:
|
|
131
|
+
"""Inspect /proc/meminfo to retrieve RAM and Samsung RAM Plus (zRAM swap) metrics in MB."""
|
|
132
|
+
metrics = {
|
|
133
|
+
"mem_total_mb": 0,
|
|
134
|
+
"mem_available_mb": 0,
|
|
135
|
+
"swap_total_mb": 0,
|
|
136
|
+
"swap_free_mb": 0,
|
|
137
|
+
"effective_total_mb": 0,
|
|
138
|
+
"effective_available_mb": 0,
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if not os.path.exists("/proc/meminfo"):
|
|
142
|
+
# Fallback for mock/test environments
|
|
143
|
+
metrics["mem_total_mb"] = 6144
|
|
144
|
+
metrics["mem_available_mb"] = 3072
|
|
145
|
+
metrics["swap_total_mb"] = 4096
|
|
146
|
+
metrics["swap_free_mb"] = 4096
|
|
147
|
+
metrics["effective_total_mb"] = 10240
|
|
148
|
+
metrics["effective_available_mb"] = 7168
|
|
149
|
+
return metrics
|
|
150
|
+
|
|
151
|
+
try:
|
|
152
|
+
with open("/proc/meminfo", "r", encoding="utf-8") as f:
|
|
153
|
+
for line in f:
|
|
154
|
+
parts = line.split(":")
|
|
155
|
+
if len(parts) == 2:
|
|
156
|
+
key = parts[0].strip()
|
|
157
|
+
val_str = parts[1].strip().split()[0]
|
|
158
|
+
if val_str.isdigit():
|
|
159
|
+
val_kb = int(val_str)
|
|
160
|
+
val_mb = val_kb // 1024
|
|
161
|
+
if key == "MemTotal":
|
|
162
|
+
metrics["mem_total_mb"] = val_mb
|
|
163
|
+
elif key == "MemAvailable":
|
|
164
|
+
metrics["mem_available_mb"] = val_mb
|
|
165
|
+
elif key == "SwapTotal":
|
|
166
|
+
metrics["swap_total_mb"] = val_mb
|
|
167
|
+
elif key == "SwapFree":
|
|
168
|
+
metrics["swap_free_mb"] = val_mb
|
|
169
|
+
except Exception as e:
|
|
170
|
+
logger.debug("Failed reading /proc/meminfo: %s", e)
|
|
171
|
+
|
|
172
|
+
metrics["effective_total_mb"] = metrics["mem_total_mb"] + metrics["swap_total_mb"]
|
|
173
|
+
metrics["effective_available_mb"] = metrics["mem_available_mb"] + metrics["swap_free_mb"]
|
|
174
|
+
return metrics
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def check_memory_safety(required_mb: int = 1500) -> Tuple[bool, str]:
|
|
178
|
+
"""Verify if available memory is sufficient for model loading without triggering Android LMK."""
|
|
179
|
+
mem = get_memory_info()
|
|
180
|
+
avail = mem["effective_available_mb"]
|
|
181
|
+
if avail < required_mb:
|
|
182
|
+
return False, (
|
|
183
|
+
f"Available memory ({avail} MB) is below the recommended threshold ({required_mb} MB). "
|
|
184
|
+
f"Please enable Samsung RAM Plus (Settings -> Battery and device care -> Memory -> RAM Plus) "
|
|
185
|
+
f"or close background apps to avoid Low Memory Killer (LMK) termination."
|
|
186
|
+
)
|
|
187
|
+
return True, f"Memory check passed: {avail} MB available (RAM + zRAM)."
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
class TermuxWakeLock:
|
|
191
|
+
"""Context manager to hold Android CPU WakeLock during long-running AI inference."""
|
|
192
|
+
|
|
193
|
+
def __init__(self, enabled: bool = True):
|
|
194
|
+
self.enabled = enabled
|
|
195
|
+
self._acquired = False
|
|
196
|
+
|
|
197
|
+
def __enter__(self):
|
|
198
|
+
if not self.enabled or not is_android_termux():
|
|
199
|
+
return self
|
|
200
|
+
|
|
201
|
+
wake_lock_bin = shutil.which("termux-wake-lock")
|
|
202
|
+
if wake_lock_bin:
|
|
203
|
+
try:
|
|
204
|
+
subprocess.run([wake_lock_bin], capture_output=True, timeout=2.0, check=False)
|
|
205
|
+
self._acquired = True
|
|
206
|
+
logger.debug("Acquired Termux CPU WakeLock.")
|
|
207
|
+
except Exception as e:
|
|
208
|
+
logger.debug("Failed acquiring WakeLock: %s", e)
|
|
209
|
+
return self
|
|
210
|
+
|
|
211
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
212
|
+
if self._acquired:
|
|
213
|
+
wake_unlock_bin = shutil.which("termux-wake-unlock")
|
|
214
|
+
if wake_unlock_bin:
|
|
215
|
+
try:
|
|
216
|
+
subprocess.run([wake_unlock_bin], capture_output=True, timeout=2.0, check=False)
|
|
217
|
+
logger.debug("Released Termux CPU WakeLock.")
|
|
218
|
+
except Exception as e:
|
|
219
|
+
logger.debug("Failed releasing WakeLock: %s", e)
|
|
220
|
+
self._acquired = False
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Marker file for PEP 561.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 uno-km (쌩초보코딩단)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: termux-diffusion
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Production On-Device AI Image Generation Framework for Android Termux & Samsung Galaxy (Dual-Engine Python & Node.js)
|
|
5
|
+
Home-page: https://github.com/uno-km/termux-diffusion
|
|
6
|
+
Author: uno-km (쌩초보코딩단)
|
|
7
|
+
Author-email: "uno-km (쌩초보코딩단)" <hosequelbo@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/uno-km/termux-diffusion
|
|
10
|
+
Project-URL: Documentation, https://uno-km.github.io/termux-diffusion/
|
|
11
|
+
Project-URL: npm Package, https://www.npmjs.com/package/termux-diffusion
|
|
12
|
+
Project-URL: Bug Tracker, https://github.com/uno-km/termux-diffusion/issues
|
|
13
|
+
Project-URL: Source, https://github.com/uno-km/termux-diffusion
|
|
14
|
+
Keywords: stable-diffusion,diffusion,termux,android,samsung-galaxy,edge-ai,on-device-ai,image-generation,gguf,arm64,bionic-libc,snapdragon,exynos,text-to-image,txt2img,mobile-ai,quantization,generative-ai,vulkan,opencl,offline-ai,private-ai,ai-art,comfyui-alternative,webui-alternative
|
|
15
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
19
|
+
Classifier: Operating System :: Android
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
26
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
27
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
28
|
+
Requires-Python: >=3.8
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
|
|
32
|
+
# Termux-Diffusion
|
|
33
|
+
|
|
34
|
+
**Production On-Device AI Image Generation Framework for Android Termux & Samsung Galaxy**
|
|
35
|
+
*Dual-Engine Architecture (Python & Node.js / TypeScript) with Native Bionic ARM64 Tensor Acceleration*
|
|
36
|
+
|
|
37
|
+
[](https://pypi.org/project/termux-diffusion/)
|
|
38
|
+
[](https://www.npmjs.com/package/termux-diffusion)
|
|
39
|
+
[](https://pypi.org/project/termux-diffusion/)
|
|
40
|
+
[](https://www.npmjs.com/package/termux-diffusion)
|
|
41
|
+
[-green.svg)](https://github.com/uno-km/termux-diffusion)
|
|
42
|
+
[](LICENSE)
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 1. System Overview
|
|
47
|
+
|
|
48
|
+
`termux-diffusion` is an enterprise-grade, on-device AI text-to-image synthesis pipeline designed specifically for Android Termux environments and Samsung Galaxy hardware.
|
|
49
|
+
|
|
50
|
+
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.
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 2. Automated Bootstrap & Installation
|
|
55
|
+
|
|
56
|
+
### Option A: One-Line Zero-Touch Bootstrap (Recommended)
|
|
57
|
+
|
|
58
|
+
Run the platform bootstrap script in Termux to automatically verify toolchains, storage permissions, and native engine binaries:
|
|
59
|
+
|
|
60
|
+
#### Python Runtime
|
|
61
|
+
```bash
|
|
62
|
+
curl -sL https://raw.githubusercontent.com/uno-km/termux-diffusion/main/docs/install.sh | bash
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### Node.js / TypeScript Runtime
|
|
66
|
+
```bash
|
|
67
|
+
curl -sL https://raw.githubusercontent.com/uno-km/termux-diffusion/main/docs/install-node.sh | bash
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
### Option B: Package Manager Installation
|
|
73
|
+
|
|
74
|
+
#### Python (PyPI)
|
|
75
|
+
```bash
|
|
76
|
+
pip install termux-diffusion && termux-diffusion-install
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
#### Node.js (npm)
|
|
80
|
+
```bash
|
|
81
|
+
npm install -g termux-diffusion && npx termux-diffusion install
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 3. Core Architectural Capabilities
|
|
87
|
+
|
|
88
|
+
* **Zero-PRoot Native Bionic Execution:** Executes natively on ARM64 without container overhead, achieving maximum memory efficiency.
|
|
89
|
+
* **Integrated Model Hub:** Built-in streaming downloader with automatic checksum verification and cache persistence.
|
|
90
|
+
* **Power & WakeLock Management (`TermuxWakeLock`):** Automatically holds Android CPU WakeLock during inference, preventing kernel suspension when the screen turns off.
|
|
91
|
+
* **Low-Memory & LMK Guard:** Inspects physical memory and Android zRAM (Samsung RAM Plus) before allocating tensor weight buffers.
|
|
92
|
+
* **Samsung Gallery Integration:** Automatically persists generated outputs to `~/storage/pictures/TermuxDiffusion/` and triggers `android.intent.action.MEDIA_SCANNER_SCAN_FILE` for instant indexing in Samsung Gallery.
|
|
93
|
+
* **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.
|
|
94
|
+
* **Hardware Compute Selection:** Explicit compute backend targeting via `device="cpu"` or `device="gpu"`.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## 4. Built-in Model Hub Presets
|
|
99
|
+
|
|
100
|
+
| Preset | Model & Quantization | Size | Latency Baseline (Exynos 1380) | Recommended Workload |
|
|
101
|
+
| :--- | :--- | :---: | :---: | :--- |
|
|
102
|
+
| **`"realistic"`** | Realistic Vision V6.0 B1 (Q4_K) | 1.62 GB | ~25 min (10 steps) | High-fidelity photorealism (portraits, skin textures, lighting) |
|
|
103
|
+
| **`"speed"`** | Stable Diffusion 1.5 Base (Q4_1) | 1.59 GB | ~15 min (10 steps) | General-purpose drafting and composition |
|
|
104
|
+
| **`"sdxs"`** | SDXS 512-0.9 Mobile (Q4_0) | **450 MB** | **~2.5 min (2 steps)** | Ultra-low latency mobile prototyping |
|
|
105
|
+
| **`"turbo"`** | SD Turbo (Q4_0) | 1.20 GB | ~4 min (1 step) | Single-step real-time inference |
|
|
106
|
+
| **`"anime"`** | DreamShaper 8 (Q4_K) | 1.65 GB | ~20 min (10 steps) | 2D / 2.5D stylized illustration and animation art |
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## 5. Usage & Integration
|
|
111
|
+
|
|
112
|
+
### Python API
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from termux_diffusion import generate
|
|
116
|
+
|
|
117
|
+
result = generate(
|
|
118
|
+
prompt="RAW photo, portrait of a happy smiling young Korean man in his 30s wearing glasses and hoodie, working on laptop, photorealistic, cinematic",
|
|
119
|
+
model="realistic",
|
|
120
|
+
device="cpu",
|
|
121
|
+
steps=10,
|
|
122
|
+
cfg_scale=4.0,
|
|
123
|
+
output="developer.png"
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
print(f"Output Path: {result.path}")
|
|
127
|
+
print(f"Android MediaStore: {result.gallery_path}")
|
|
128
|
+
print(f"Elapsed Time: {result.elapsed_sec:.2f}s")
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Node.js / TypeScript API
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
const { generate } = require('termux-diffusion');
|
|
135
|
+
|
|
136
|
+
async function main() {
|
|
137
|
+
const result = await generate({
|
|
138
|
+
prompt: 'cyberpunk cat with neon collar in rainy alley, 8k, photorealistic',
|
|
139
|
+
model: 'speed',
|
|
140
|
+
device: 'cpu',
|
|
141
|
+
steps: 10,
|
|
142
|
+
output: 'cyber_cat.png'
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
console.log(`Output Path: ${result.path}`);
|
|
146
|
+
console.log(`Android MediaStore: ${result.galleryPath}`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
main().catch(console.error);
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## 6. Custom Models & Hugging Face Resolution
|
|
155
|
+
|
|
156
|
+
### 1. Direct Hugging Face Repository Identifier
|
|
157
|
+
Pass any repository ID and `.gguf` filename. The framework resolves, streams, caches, and executes the weights:
|
|
158
|
+
```python
|
|
159
|
+
generate(
|
|
160
|
+
"1girl, anime masterpiece, vibrant colors",
|
|
161
|
+
model="second-state/DreamShaper-8-GGUF/dreamshaper-8-Q4_k.gguf"
|
|
162
|
+
)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### 2. Local File Reference
|
|
166
|
+
```python
|
|
167
|
+
generate(
|
|
168
|
+
"fantasy landscape at sunrise",
|
|
169
|
+
model="~/storage/downloads/custom_model.gguf"
|
|
170
|
+
)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### 3. Alias Registration (`register_model`)
|
|
174
|
+
```python
|
|
175
|
+
from termux_diffusion import register_model, generate
|
|
176
|
+
|
|
177
|
+
register_model("waifu", repo_id="second-state/DreamShaper-8-GGUF", filename="dreamshaper-8-Q4_k.gguf")
|
|
178
|
+
generate("anime portrait", model="waifu")
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## 7. Pre-flight Diagnostic Tool
|
|
184
|
+
|
|
185
|
+
Verify system packages, architecture, available memory, and native engine status:
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
# Python
|
|
189
|
+
termux-diffusion-doctor
|
|
190
|
+
|
|
191
|
+
# Node.js
|
|
192
|
+
npx termux-diffusion doctor
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## 8. License
|
|
198
|
+
|
|
199
|
+
Released under the **MIT License**. Maintained by **uno-km**.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
termux_diffusion/__init__.py,sha256=W7ZaFDqFF5MRCzlhtOKjT4yj_PXgDRswsIbrMhHQtLI,1736
|
|
2
|
+
termux_diffusion/cli.py,sha256=KPIlBN1ahruftqRNwG3-e7TAYnC6WjbPK5TZAwvvBsU,4149
|
|
3
|
+
termux_diffusion/core.py,sha256=rZPiXrlD9p9EQKBEL78iu6Nvpcdjl_8cEpPboi8g8nE,8855
|
|
4
|
+
termux_diffusion/exceptions.py,sha256=3p-dDVdbJImyhUyKwcv_wsuuGldBUBe_9ccA_9g2rgk,1032
|
|
5
|
+
termux_diffusion/hub.py,sha256=K6DO1rGGQ1o-kmh05XIEhPyCWVBwDtRBqSW79p_mG3g,13038
|
|
6
|
+
termux_diffusion/installer.py,sha256=zHEyfVxldCTV8dA-Gui9t6YIugpVulrBP_bnKC3h1ZQ,7631
|
|
7
|
+
termux_diffusion/platform.py,sha256=izwn2akbhvdvq_DuYddv0fLZrIzEJcv2gmvXjR73tNc,8338
|
|
8
|
+
termux_diffusion/py.typed,sha256=bWew9mHgMy8LqMu7RuqQXFXLBxh2CRx0dUbSx-3wE48,27
|
|
9
|
+
termux_diffusion-1.0.0.dist-info/LICENSE,sha256=Ek5JuH4HK-oMetVBul6Ovr7D6MVfNkPrSOpWqIwiCXI,1084
|
|
10
|
+
termux_diffusion-1.0.0.dist-info/METADATA,sha256=FxhuVYr9BpYwsTNjoG4-7K2t7MX0H1W7sILOoaQWdcw,8080
|
|
11
|
+
termux_diffusion-1.0.0.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
|
|
12
|
+
termux_diffusion-1.0.0.dist-info/entry_points.txt,sha256=8vBahKNnbeneyBq3Jgu-ZfeeX5NsK09iG9pJ_CUaIt0,189
|
|
13
|
+
termux_diffusion-1.0.0.dist-info/top_level.txt,sha256=3rMTnjMa0GVaZgixdY5fn-Drj3LkxJ-jQW3KjzkWodA,17
|
|
14
|
+
termux_diffusion-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
termux_diffusion
|