tileupscale 0.6.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.
Files changed (52) hide show
  1. tileupscale-0.6.0.dist-info/METADATA +172 -0
  2. tileupscale-0.6.0.dist-info/RECORD +52 -0
  3. tileupscale-0.6.0.dist-info/WHEEL +5 -0
  4. tileupscale-0.6.0.dist-info/entry_points.txt +2 -0
  5. tileupscale-0.6.0.dist-info/licenses/LICENSE +21 -0
  6. tileupscale-0.6.0.dist-info/licenses/NOTICE +6 -0
  7. tileupscale-0.6.0.dist-info/top_level.txt +1 -0
  8. upscale/__init__.py +30 -0
  9. upscale/__main__.py +3 -0
  10. upscale/about.py +170 -0
  11. upscale/algorithms/__init__.py +166 -0
  12. upscale/algorithms/classical.py +82 -0
  13. upscale/algorithms/plugins/__init__.py +52 -0
  14. upscale/algorithms/plugins/texture_residual.py +117 -0
  15. upscale/algorithms/plugins/vectorize_scale.py +450 -0
  16. upscale/alpha_policy.py +140 -0
  17. upscale/api/__init__.py +19 -0
  18. upscale/api/compare_routes.py +256 -0
  19. upscale/api/deps.py +18 -0
  20. upscale/api/jobs.py +535 -0
  21. upscale/api/media_routes.py +257 -0
  22. upscale/api/models_routes.py +107 -0
  23. upscale/api/system_routes.py +210 -0
  24. upscale/backends/__init__.py +27 -0
  25. upscale/backends/onnx_rt.py +291 -0
  26. upscale/benchmark.py +96 -0
  27. upscale/checkpoint.py +259 -0
  28. upscale/cli.py +634 -0
  29. upscale/compare.py +204 -0
  30. upscale/config.py +56 -0
  31. upscale/engine.py +321 -0
  32. upscale/estimates.py +338 -0
  33. upscale/filters.py +180 -0
  34. upscale/help_content.py +95 -0
  35. upscale/infer_util.py +22 -0
  36. upscale/io_utils.py +622 -0
  37. upscale/job_prep.py +318 -0
  38. upscale/mcp_server.py +287 -0
  39. upscale/memmap_util.py +70 -0
  40. upscale/models.py +628 -0
  41. upscale/naming.py +63 -0
  42. upscale/pipeline.py +482 -0
  43. upscale/presets.py +127 -0
  44. upscale/quality.py +36 -0
  45. upscale/schema.py +315 -0
  46. upscale/server.py +893 -0
  47. upscale/speed_stats.py +273 -0
  48. upscale/suggest.py +93 -0
  49. upscale/system.py +102 -0
  50. upscale/tiling.py +430 -0
  51. upscale/web.py +118 -0
  52. upscale/weight_blend.py +75 -0
@@ -0,0 +1,172 @@
1
+ Metadata-Version: 2.4
2
+ Name: tileupscale
3
+ Version: 0.6.0
4
+ Summary: Local AI image upscaler: chained Real-ESRGAN passes to any scale, seam-free feather-blended tiles
5
+ Author: tileupscale
6
+ License: MIT
7
+ Project-URL: Homepage, https://tileupscale.dev/
8
+ Project-URL: Repository, https://github.com/wwylon/upscale
9
+ Project-URL: Issues, https://github.com/wwylon/upscale/issues
10
+ Keywords: image-upscaler,super-resolution,real-esrgan,upscaling,pytorch,onnx,mcp,cli
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: End Users/Desktop
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Multimedia :: Graphics
21
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ License-File: NOTICE
26
+ Requires-Dist: torch>=2.0
27
+ Requires-Dist: torchvision
28
+ Requires-Dist: spandrel
29
+ Requires-Dist: Pillow
30
+ Requires-Dist: tifffile
31
+ Requires-Dist: imagecodecs
32
+ Requires-Dist: psd-tools>=1.9
33
+ Requires-Dist: tqdm
34
+ Requires-Dist: click
35
+ Requires-Dist: numpy
36
+ Requires-Dist: pydantic>=2.0
37
+ Provides-Extra: ui
38
+ Requires-Dist: gradio>=4.0; extra == "ui"
39
+ Provides-Extra: server
40
+ Requires-Dist: fastapi>=0.110; extra == "server"
41
+ Requires-Dist: uvicorn[standard]>=0.27; extra == "server"
42
+ Requires-Dist: python-multipart>=0.0.9; extra == "server"
43
+ Provides-Extra: mcp
44
+ Requires-Dist: mcp>=1.0; extra == "mcp"
45
+ Provides-Extra: desktop
46
+ Requires-Dist: pywebview>=5.0; extra == "desktop"
47
+ Provides-Extra: slim
48
+ Requires-Dist: tileupscale[desktop,server]; extra == "slim"
49
+ Requires-Dist: onnxruntime>=1.17; extra == "slim"
50
+ Requires-Dist: Pillow; extra == "slim"
51
+ Requires-Dist: numpy; extra == "slim"
52
+ Requires-Dist: tifffile; extra == "slim"
53
+ Requires-Dist: imagecodecs; extra == "slim"
54
+ Requires-Dist: tqdm; extra == "slim"
55
+ Requires-Dist: click; extra == "slim"
56
+ Requires-Dist: pydantic>=2.0; extra == "slim"
57
+ Provides-Extra: dev
58
+ Requires-Dist: pytest>=7.0; extra == "dev"
59
+ Requires-Dist: ruff>=0.4; extra == "dev"
60
+ Requires-Dist: httpx>=0.27; extra == "dev"
61
+ Requires-Dist: mypy>=1.8; extra == "dev"
62
+ Provides-Extra: classical
63
+ Requires-Dist: opencv-python-headless>=4.8; extra == "classical"
64
+ Provides-Extra: vectorize
65
+ Requires-Dist: vtracer>=0.6; extra == "vectorize"
66
+ Requires-Dist: pyautotrace>=0.0.7; extra == "vectorize"
67
+ Requires-Dist: resvg_py>=0.2; extra == "vectorize"
68
+ Provides-Extra: all
69
+ Requires-Dist: tileupscale[classical,desktop,dev,mcp,server,slim,ui,vectorize]; extra == "all"
70
+ Dynamic: license-file
71
+
72
+ # tileupscale
73
+
74
+ [![CI](https://github.com/wwylon/upscale/actions/workflows/ci.yml/badge.svg)](https://github.com/wwylon/upscale/actions/workflows/ci.yml)
75
+ [![Release](https://img.shields.io/github/v/release/wwylon/upscale)](https://github.com/wwylon/upscale/releases)
76
+ [![PyPI](https://img.shields.io/pypi/v/tileupscale)](https://pypi.org/project/tileupscale/)
77
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
78
+
79
+ Local AI image upscale. Chains Real-ESRGAN passes (via [spandrel](https://github.com/chaiNNer-org/spandrel)) to reach any target scale, with feather-blended overlapping tiles so large outputs have no seams. Runs on CPU or an NVIDIA GPU; nothing leaves your machine except the one-time model download.
80
+
81
+ Homepage: [tileupscale.dev](https://tileupscale.dev/)
82
+
83
+ ![tileupscale hero](docs/assets/hero.jpg)
84
+
85
+ ![Before/after: 160px source upscaled 4x](docs/assets/demo.gif)
86
+
87
+ > PyPI distribution **tileupscale**. Import and command stay `upscale`. Not related to other projects named "upscaler" on GitHub or PyPI.
88
+
89
+ ## Install
90
+
91
+ ```bash
92
+ pip install tileupscale
93
+ pip install "tileupscale[server]" # web UI + job API
94
+ pip install "tileupscale[mcp]" # MCP tools for agents
95
+ # or: pipx install tileupscale
96
+ ```
97
+
98
+ The pip install pulls PyTorch (large, slow first install). A PyTorch-free build exists only as the Windows desktop app (ONNX Runtime); see [docs/develop.md](docs/develop.md).
99
+
100
+ From a clone:
101
+
102
+ ```bash
103
+ pip install -e .
104
+ pip install -e ".[server,mcp]"
105
+ # tip without cloning: pip install "git+https://github.com/wwylon/upscale.git"
106
+ ```
107
+
108
+ ## First win
109
+
110
+ ```bash
111
+ upscale upscale input.png output.png --scale 4 --cpu
112
+ ```
113
+
114
+ Use `--target-size 8000` for a target long edge instead of a factor, drop `--cpu` to use the GPU, and `--fast` for the quick SPAN model. Models download on first use and are hash-verified.
115
+
116
+ ```bash
117
+ upscale models list # built-in models
118
+ upscale suggest input.png # heuristic model pick
119
+ upscale serve # local web UI at http://127.0.0.1:8787/en/
120
+ upscale mcp # MCP tools over stdio
121
+ ```
122
+
123
+ Equivalent module form: `python -m upscale upscale ...`
124
+
125
+ ## Highlights
126
+
127
+ - Exact scale (`--scale`) or target long edge (`--target-size`); extra passes only when needed
128
+ - Tile size chosen from free VRAM; very large frames spill to disk between passes
129
+ - Swappable models: Real-ESRGAN family, HAT, SPAN, community weights, or your own `.pth`
130
+ - Large outputs saved as BigTIFF; alpha preserved
131
+ - Web UI in several languages; Windows desktop build uses ONNX Runtime (no PyTorch)
132
+ - No telemetry
133
+
134
+ ## Library
135
+
136
+ ```python
137
+ from upscale import UpscaleConfig, execute
138
+
139
+ execute(UpscaleConfig(input="in.png", output="out.png", scale=4, cpu=True))
140
+ ```
141
+
142
+ ## Documentation
143
+
144
+ - [CLI reference](docs/cli.md)
145
+ - [HTTP and MCP API](docs/api.md)
146
+ - [Development, desktop build, layout](docs/develop.md)
147
+ - [Android skeleton](docs/android.md)
148
+
149
+ ## Tests
150
+
151
+ Local gate (also in [CONTRIBUTING.md](CONTRIBUTING.md) / `publish.manifest.yaml`):
152
+
153
+ ```bash
154
+ uv sync --locked --extra dev --extra server --extra mcp
155
+ uv run ruff check upscale tests
156
+ uv run mypy --follow-imports=silent upscale/schema.py upscale/job_prep.py upscale/config.py upscale/naming.py upscale/api
157
+ uv run pytest -q
158
+ uv run python scripts/cpu_smoke.py
159
+ ```
160
+
161
+ GitHub Actions are disabled to save minutes; run the gate locally (or `workflow_dispatch` if re-enabled) before publish.
162
+
163
+ MIT licensed. See [CONTRIBUTING.md](CONTRIBUTING.md) and [SECURITY.md](SECURITY.md).
164
+
165
+ ## Verify
166
+
167
+ ```bash
168
+ uv run pytest -q
169
+ ```
170
+
171
+ Or: python -m manager verify upscale --tier prereq. Contract: [project.manifest.yaml](project.manifest.yaml).
172
+
@@ -0,0 +1,52 @@
1
+ tileupscale-0.6.0.dist-info/licenses/LICENSE,sha256=KzX80Ys4P_QDQxZvYVcH2zoKrfgCLZm967LuVDX-8qk,1077
2
+ tileupscale-0.6.0.dist-info/licenses/NOTICE,sha256=gy0RaYSpv9XkB2tH1qfJuYP34yof-ZXmS5tw4o2oatE,294
3
+ upscale/__init__.py,sha256=PoWjSarGpdml2TnUms-D1zkzaCoqX0MB1G_JskzLQtE,802
4
+ upscale/__main__.py,sha256=Huz0dExiaH0XTMLhfe3skkFD9-VH7ZUiWMbDR_J8TIY,28
5
+ upscale/about.py,sha256=HLh-X5AlOqAu_POQjbMGCUd6pb6qD7jl9tDlcs-N70Q,5631
6
+ upscale/alpha_policy.py,sha256=Eyf7zmhu7EpEOP1pHxHaYepZHQ3q43uWDQoQbQLdf3k,4004
7
+ upscale/benchmark.py,sha256=YzFyS48Xy3jDLZ2wx0HWab4f_XNv5nHipotbku7_1P8,2475
8
+ upscale/checkpoint.py,sha256=4jRuoqMTI_NKL44UNi1SdNKLYuwh57Pi6PhEJIiREd8,8887
9
+ upscale/cli.py,sha256=1fl4llFX_YmSkRfNKiqhI6SJA7yJaRhlrqibh66ZQYM,23628
10
+ upscale/compare.py,sha256=2ll39zuFu7fifTvQQ8W9dvWOz4-LTZZh0LE7o80-GkY,6283
11
+ upscale/config.py,sha256=HFEmobDhv-sWkyog3NZUPNEgmgbKNKLGbh-DrDt38fk,1815
12
+ upscale/engine.py,sha256=r7dIjHxIm1PIrLdBrwe0JUw9WSu0d9Pf679FemDxnx4,11062
13
+ upscale/estimates.py,sha256=vTcDuRih7BOoi9TIHhl1bPc1fkHGyGmeX-xNrQnYywg,10923
14
+ upscale/filters.py,sha256=oX5zD607Q93AEn3SMQCtv8nVVlq_B-JbzaQMJZPzLJY,6246
15
+ upscale/help_content.py,sha256=I3hx2gh8xrkQthc5OyLYbpDDJrNzGqFmcLYt0tf7IoY,2611
16
+ upscale/infer_util.py,sha256=E8nfWeAokIZXDXNm4CQpUiEJ0_Sp1f1_ZqEOCJJCivg,672
17
+ upscale/io_utils.py,sha256=tpk-nNbmeUCJ90GLymKoY2oKeoRvN-n90frgo_8udPM,20161
18
+ upscale/job_prep.py,sha256=Mvo7DRcNUF38JIiOQsCXQJQKzD-LYLG9MbvUnBzBmXM,10607
19
+ upscale/mcp_server.py,sha256=TnVXzekQTEEDl2d-WEA6nx87JeTls47xDzNfom8ywCI,9197
20
+ upscale/memmap_util.py,sha256=vVK6uef8V3q5kAmTYbyG6EIA3m7Yi_Lh0QD8FkUs2CY,1943
21
+ upscale/models.py,sha256=lIKV2Dg-Y3i9akFXi13yazuLZsqnyTkavygJ6YYmDKs,23456
22
+ upscale/naming.py,sha256=hBsHlHDtQBtKB10_mZAY8PuLCLk5dmizMyjRb5QbOso,1815
23
+ upscale/pipeline.py,sha256=71enpdHcnorh8ZPfa0My-jD-6RFxzzalOXdp9xEkvg8,16315
24
+ upscale/presets.py,sha256=XM3CW2SBAOqCutMcV5XK02_amBtm3qeKKeMNkUlS6Uw,3492
25
+ upscale/quality.py,sha256=clh6H-_vS5ivEWCwihmKKINwvM3hpodMuymc5JV9-38,1135
26
+ upscale/schema.py,sha256=VzS-TaTOj1NRCCEkXW4ZEOw3P0HCdfwreP8U0npkruQ,9987
27
+ upscale/server.py,sha256=eCirT7gcAsMVknIY2jWqlvLEVG5SBS1IdIFM2Ji7v_4,26169
28
+ upscale/speed_stats.py,sha256=r7kz4i2WJiUJ4QMZRqIe-SVKN9F_loU7sGtmp6VdwzM,7172
29
+ upscale/suggest.py,sha256=vAWIGtP5B75JvENkvkooyNnCqVDnW6FXZWsWbb83Qi8,2921
30
+ upscale/system.py,sha256=O-qukw2u09OeUohm7-8nYShQZsqdjArzxWawpWzVoeI,2991
31
+ upscale/tiling.py,sha256=ynTXiduAldhGa2uUlac4n6qOf9kFAbge1W3nuMQNkEc,14951
32
+ upscale/web.py,sha256=0fml9Ckcw0o03IJVg399ywt_qMwPm1WddRJl9Zw0-34,4227
33
+ upscale/weight_blend.py,sha256=1_TueTzt_CTIr7URJMpxMsUW-0AM78MjFdwVIwjuoW4,2484
34
+ upscale/algorithms/__init__.py,sha256=2_m51j-WrLy56vAj-ID9zF-_dNmaaYBSbpxmHqX3KIk,5018
35
+ upscale/algorithms/classical.py,sha256=qQ6HOts4E7JFdKsWNZEXeC9UhOB1etfEoEwZ1EZx0dQ,2504
36
+ upscale/algorithms/plugins/__init__.py,sha256=p0Jdu3IopidyNQD9CoyHtjk42ENN9Lm7hh45LM9l-ZA,1467
37
+ upscale/algorithms/plugins/texture_residual.py,sha256=HNCxWdPA9SgqkpUAZH9WZ2W9JFqlNSFm9YMVVxy_A5A,4286
38
+ upscale/algorithms/plugins/vectorize_scale.py,sha256=HPgPYySnq31gHYehYpvZPvYo21ttfPZDJHNEU-CmYhE,14435
39
+ upscale/api/__init__.py,sha256=JvOENBoJMXnl75f7XFYpV8nRC4m1h2_toSkNWrA0rZI,619
40
+ upscale/api/compare_routes.py,sha256=0xCljSrIPM-aAAnICgZel_ANA7yu6q4jSn9yskgMi8A,8602
41
+ upscale/api/deps.py,sha256=93PbBy8rwPMM_3hVcZPai90Jd660VTT6HPNHWhq35Ak,456
42
+ upscale/api/jobs.py,sha256=KtPCLJQEY_QBdRUj2y3vYAvR2QetlD-NFOjs5hl9r6k,20286
43
+ upscale/api/media_routes.py,sha256=x3Lr5oFNUck9rxGY17zhRByaTr87Gj-_49yJt6k_OLM,8670
44
+ upscale/api/models_routes.py,sha256=BnjA3sSE2yaFHIndskPxmSyJIkz3R-9HTn5nXg9eRMo,3563
45
+ upscale/api/system_routes.py,sha256=cdjQI_jSlu4HBY56gYIoxF2r82RCbFjGq1rr3AAbg0I,6830
46
+ upscale/backends/__init__.py,sha256=tNyl51Ke90LDyllENP-07lrUR5ggetaR7dK1PA5zw2Y,749
47
+ upscale/backends/onnx_rt.py,sha256=I2vvQR6gNHyqJEmuRk95ZPPhi7AIS81Hh-6Xe8tgr4E,10001
48
+ tileupscale-0.6.0.dist-info/METADATA,sha256=EB9w61IwISgWb2MH5n0lv122g1D1mXTkxPMkoka5QY8,6563
49
+ tileupscale-0.6.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
50
+ tileupscale-0.6.0.dist-info/entry_points.txt,sha256=rMV_QHir75526-EZjy-ymwoC8loEfIygnCJ5lNiSgM8,44
51
+ tileupscale-0.6.0.dist-info/top_level.txt,sha256=5z_wLVBn387Z360VG_Ya-kcDZ8e3DJzM8JvFfld4NHI,8
52
+ tileupscale-0.6.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ upscale = upscale.cli:cli
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Upscale contributors
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,6 @@
1
+ Third-party notices
2
+ ===================
3
+
4
+ Third-party model weights (Real-ESRGAN, HAT, SPAN, and community checkpoints)
5
+ remain under their own licenses. Review each model's license before redistribution.
6
+ OpenCV, ONNX Runtime, PyTorch, and other dependencies use their respective licenses.
@@ -0,0 +1 @@
1
+ upscale
upscale/__init__.py ADDED
@@ -0,0 +1,30 @@
1
+ """AI image upscaler — multi-pass Real-ESRGAN with feather-blended tiles."""
2
+
3
+ from .config import UpscaleConfig
4
+ from .engine import execute
5
+ from .io_utils import lanczos_resize, load_rgba, save_image
6
+ from .models import DEFAULT_WEIGHTS_DIR, MODELS, ensure_model, load_model, resolve_device
7
+ from .pipeline import compute_passes, resolve_model_scale, run, upscale_alpha
8
+ from .schema import JobSettings, NamePattern, ProgressEvent
9
+
10
+ __all__ = [
11
+ "UpscaleConfig",
12
+ "JobSettings",
13
+ "NamePattern",
14
+ "ProgressEvent",
15
+ "MODELS",
16
+ "DEFAULT_WEIGHTS_DIR",
17
+ "compute_passes",
18
+ "run",
19
+ "resolve_model_scale",
20
+ "upscale_alpha",
21
+ "execute",
22
+ "load_rgba",
23
+ "save_image",
24
+ "lanczos_resize",
25
+ "ensure_model",
26
+ "load_model",
27
+ "resolve_device",
28
+ ]
29
+
30
+ __version__ = "0.6.0"
upscale/__main__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .cli import cli
2
+
3
+ cli()
upscale/about.py ADDED
@@ -0,0 +1,170 @@
1
+ """About, license, and update-check helpers for UI / desktop."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import os
7
+ import urllib.error
8
+ import urllib.request
9
+ from importlib import metadata
10
+ from pathlib import Path
11
+ from typing import Any
12
+
13
+ from .models import DEFAULT_WEIGHTS_DIR, all_models, model_status
14
+
15
+ PROJECT_ROOT = Path(__file__).resolve().parent.parent
16
+ LICENSE_PATH = PROJECT_ROOT / "LICENSE"
17
+
18
+ # Optional: GitHub Releases API URL or a static JSON with tag_name / html_url
19
+ DEFAULT_RELEASES_URL = os.environ.get("UPSCALE_RELEASES_URL", "").strip()
20
+
21
+
22
+ def package_version() -> str:
23
+ for dist in ("tileupscale", "upscale"):
24
+ try:
25
+ return metadata.version(dist)
26
+ except metadata.PackageNotFoundError:
27
+ continue
28
+ from . import __version__
29
+
30
+ return __version__
31
+
32
+
33
+ def license_text() -> str:
34
+ if LICENSE_PATH.is_file():
35
+ return LICENSE_PATH.read_text(encoding="utf-8")
36
+ return (
37
+ "MIT License\n\n"
38
+ "Copyright (c) 2026 Upscale contributors\n\n"
39
+ "Permission is hereby granted, free of charge, to any person obtaining a copy "
40
+ "of this software..."
41
+ )
42
+
43
+
44
+ def about_payload() -> dict[str, Any]:
45
+ models_dir = Path(os.environ.get("UPSCALE_MODELS_DIR", DEFAULT_WEIGHTS_DIR))
46
+ return {
47
+ "name": "Upscale",
48
+ "version": package_version(),
49
+ "license": "MIT",
50
+ "description": (
51
+ "AI image upscaler — chained Real-ESRGAN / HAT / SPAN with "
52
+ "feather-blended tiles. Classical resize via OpenCV when available."
53
+ ),
54
+ "models_dir": str(models_dir),
55
+ "models_policy": (
56
+ "Model weights are downloaded on demand into the models folder "
57
+ "(desktop: %LOCALAPPDATA%\\Upscale\\models). They are not baked into "
58
+ "the slim installer. Optional tiny SPAN may ship later for offline first run."
59
+ ),
60
+ }
61
+
62
+
63
+ def models_disk_summary(weights_dir: Path | None = None) -> dict[str, Any]:
64
+ wdir = weights_dir or Path(os.environ.get("UPSCALE_MODELS_DIR", DEFAULT_WEIGHTS_DIR))
65
+ catalog = all_models(wdir)
66
+ installed: list[dict[str, Any]] = []
67
+ total = 0
68
+ for name, meta in sorted(catalog.items()):
69
+ st = model_status(name, wdir)
70
+ if st != "installed":
71
+ continue
72
+ url_path = (meta.get("url") or "").split("?")[0]
73
+ ext = Path(url_path).suffix or ".pth"
74
+ dest = Path(meta["path"]) if meta.get("path") else wdir / f"{name}{ext}"
75
+ size = dest.stat().st_size if dest.is_file() else int(meta.get("size_bytes") or 0)
76
+ total += size
77
+ installed.append({"name": name, "path": str(dest), "size_bytes": size})
78
+ return {
79
+ "models_dir": str(wdir),
80
+ "installed_count": len(installed),
81
+ "total_bytes": total,
82
+ "models": installed,
83
+ }
84
+
85
+
86
+ def _parse_version(tag: str) -> tuple[int, ...]:
87
+ s = tag.strip().lstrip("vV")
88
+ parts: list[int] = []
89
+ for p in s.split("."):
90
+ num = ""
91
+ for ch in p:
92
+ if ch.isdigit():
93
+ num += ch
94
+ else:
95
+ break
96
+ parts.append(int(num) if num else 0)
97
+ return tuple(parts) or (0,)
98
+
99
+
100
+ def check_for_updates(
101
+ *,
102
+ releases_url: str | None = None,
103
+ timeout: float = 8.0,
104
+ ) -> dict[str, Any]:
105
+ """Compare local version to latest release tag.
106
+
107
+ ``releases_url`` may be a GitHub Releases API endpoint
108
+ (``…/repos/OWNER/REPO/releases/latest``) or any JSON with ``tag_name``.
109
+ """
110
+ current = package_version()
111
+ url = (releases_url if releases_url is not None else DEFAULT_RELEASES_URL).strip()
112
+ if not url:
113
+ return {
114
+ "status": "unconfigured",
115
+ "current": current,
116
+ "latest": None,
117
+ "update_available": False,
118
+ "message": "Set UPSCALE_RELEASES_URL to enable update checks.",
119
+ "url": None,
120
+ }
121
+ try:
122
+ req = urllib.request.Request(
123
+ url,
124
+ headers={"Accept": "application/vnd.github+json", "User-Agent": "upscale"},
125
+ )
126
+ with urllib.request.urlopen(req, timeout=timeout) as resp:
127
+ raw = resp.read().decode("utf-8")
128
+ data = json.loads(raw)
129
+ if isinstance(data, list) and data:
130
+ data = data[0]
131
+ tag = str(data.get("tag_name") or data.get("version") or "")
132
+ html = data.get("html_url") or data.get("url")
133
+ if not tag:
134
+ return {
135
+ "status": "error",
136
+ "current": current,
137
+ "latest": None,
138
+ "update_available": False,
139
+ "message": "Release JSON missing tag_name",
140
+ "url": html,
141
+ }
142
+ newer = _parse_version(tag) > _parse_version(current)
143
+ return {
144
+ "status": "ok",
145
+ "current": current,
146
+ "latest": tag.lstrip("vV"),
147
+ "update_available": newer,
148
+ "message": (
149
+ f"Update available: {tag}" if newer else f"Up to date ({current})"
150
+ ),
151
+ "url": html,
152
+ }
153
+ except urllib.error.URLError as exc:
154
+ return {
155
+ "status": "error",
156
+ "current": current,
157
+ "latest": None,
158
+ "update_available": False,
159
+ "message": f"Could not reach releases: {exc}",
160
+ "url": None,
161
+ }
162
+ except (json.JSONDecodeError, TypeError, ValueError) as exc:
163
+ return {
164
+ "status": "error",
165
+ "current": current,
166
+ "latest": None,
167
+ "update_available": False,
168
+ "message": f"Bad releases response: {exc}",
169
+ "url": None,
170
+ }
@@ -0,0 +1,166 @@
1
+ """Classical and plugin upscale algorithms (non-neural)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+ from typing import Callable
7
+
8
+ import numpy as np
9
+
10
+ from .classical import BUILTIN_ALGORITHMS, resize_classical
11
+
12
+ AlgorithmFn = Callable[[np.ndarray, int, int], np.ndarray]
13
+
14
+ _BUILTIN_META: dict[str, tuple[str, str]] = {
15
+ "nearest": ("Nearest-neighbor", "Blocky, preserves hard edges — good for pixel art."),
16
+ "bilinear": ("Bilinear", "Smooth linear interpolation."),
17
+ "bicubic": ("Bicubic", "Smoother curves than bilinear; common photo default."),
18
+ "lanczos2": ("Lanczos-2", "Sharper Lanczos (approx.)."),
19
+ "lanczos3": ("Lanczos-3", "High-quality Lanczos — good general classical choice."),
20
+ }
21
+
22
+
23
+ @dataclass(frozen=True)
24
+ class AlgorithmInfo:
25
+ name: str
26
+ label: str
27
+ group: str # "builtin" | "paper" | "plugin"
28
+ description: str = ""
29
+
30
+
31
+ _REGISTRY: dict[str, AlgorithmFn] = {}
32
+ _META: dict[str, AlgorithmInfo] = {}
33
+ _PLUGINS_LOADED = False
34
+
35
+
36
+ def _norm_algo(name: str) -> str:
37
+ return name.strip().lower().replace(" ", "_").replace("-", "_")
38
+
39
+
40
+ def register_algorithm(
41
+ name: str,
42
+ fn: AlgorithmFn,
43
+ *,
44
+ overwrite: bool = False,
45
+ label: str | None = None,
46
+ group: str = "plugin",
47
+ description: str = "",
48
+ ) -> None:
49
+ """Register a custom algorithm for later use (paper plugins, etc.)."""
50
+ key = _norm_algo(name)
51
+ if not key:
52
+ raise ValueError("algorithm name required")
53
+ if key in _REGISTRY and not overwrite:
54
+ raise ValueError(f"algorithm already registered: {key}")
55
+ _REGISTRY[key] = fn
56
+ pretty = label or key.replace("_", " ").title()
57
+ g = group if group in ("builtin", "paper", "plugin") else "plugin"
58
+ if key in BUILTIN_ALGORITHMS:
59
+ g = "builtin"
60
+ bl, bd = _BUILTIN_META.get(key, (pretty, description))
61
+ pretty = label or bl
62
+ description = description or bd
63
+ _META[key] = AlgorithmInfo(
64
+ name=key, label=pretty, group=g, description=description or ""
65
+ )
66
+
67
+
68
+ def unregister_algorithm(name: str) -> None:
69
+ key = _norm_algo(name)
70
+ _REGISTRY.pop(key, None)
71
+ _META.pop(key, None)
72
+
73
+
74
+ def list_algorithms() -> list[str]:
75
+ """Built-ins first (stable order), then any extra plugins."""
76
+ ensure_plugins_loaded()
77
+ builtins = list(BUILTIN_ALGORITHMS)
78
+ extras = sorted(k for k in _REGISTRY if k not in BUILTIN_ALGORITHMS)
79
+ return builtins + extras
80
+
81
+
82
+ def list_algorithm_meta() -> list[AlgorithmInfo]:
83
+ """Metadata for UI / API: builtins then paper/plugin (sorted within group)."""
84
+ ensure_plugins_loaded()
85
+ out: list[AlgorithmInfo] = []
86
+ for name in BUILTIN_ALGORITHMS:
87
+ info = _META.get(name)
88
+ if info:
89
+ out.append(info)
90
+ else:
91
+ bl, bd = _BUILTIN_META.get(name, (name, ""))
92
+ out.append(AlgorithmInfo(name=name, label=bl, group="builtin", description=bd))
93
+ extras = [k for k in _REGISTRY if k not in BUILTIN_ALGORITHMS]
94
+ extras.sort(key=lambda k: (_META[k].group if k in _META else "plugin", k))
95
+ for k in extras:
96
+ out.append(
97
+ _META.get(k)
98
+ or AlgorithmInfo(name=k, label=k.replace("_", " ").title(), group="plugin")
99
+ )
100
+ return out
101
+
102
+
103
+ def get_algorithm(name: str) -> AlgorithmFn | None:
104
+ ensure_plugins_loaded()
105
+ key = _norm_algo(name)
106
+ if key in _REGISTRY:
107
+ return _REGISTRY[key]
108
+ if key in BUILTIN_ALGORITHMS:
109
+ return lambda img, tw, th, _k=key: resize_classical(_k, img, tw, th)
110
+ return None
111
+
112
+
113
+ def resize_with_algorithm(
114
+ name: str, img: np.ndarray, target_w: int, target_h: int
115
+ ) -> np.ndarray:
116
+ """Resize HWC uint8 RGB (or single-channel) with a named algorithm."""
117
+ fn = get_algorithm(name)
118
+ if fn is None:
119
+ raise ValueError(
120
+ f"Unknown algorithm {name!r}. Available: {', '.join(list_algorithms())}"
121
+ )
122
+ tw, th = int(target_w), int(target_h)
123
+ if tw < 1 or th < 1:
124
+ raise ValueError("target size must be positive")
125
+ return fn(img, tw, th)
126
+
127
+
128
+ def ensure_plugins_loaded() -> None:
129
+ """Import plugin modules once so they can register_algorithm."""
130
+ global _PLUGINS_LOADED
131
+ if _PLUGINS_LOADED:
132
+ return
133
+ _PLUGINS_LOADED = True
134
+ try:
135
+ from . import plugins as _plugins
136
+
137
+ _plugins.load_plugins()
138
+ except Exception: # noqa: BLE001
139
+ # Plugins are optional; classical built-ins still work.
140
+ pass
141
+
142
+
143
+ # Register built-ins so plugins see a full catalog
144
+ for _name in BUILTIN_ALGORITHMS:
145
+ _bl, _bd = _BUILTIN_META.get(_name, (_name, ""))
146
+ register_algorithm(
147
+ _name,
148
+ lambda img, tw, th, _n=_name: resize_classical(_n, img, tw, th),
149
+ overwrite=True,
150
+ label=_bl,
151
+ group="builtin",
152
+ description=_bd,
153
+ )
154
+
155
+ __all__ = [
156
+ "AlgorithmFn",
157
+ "AlgorithmInfo",
158
+ "BUILTIN_ALGORITHMS",
159
+ "ensure_plugins_loaded",
160
+ "get_algorithm",
161
+ "list_algorithm_meta",
162
+ "list_algorithms",
163
+ "register_algorithm",
164
+ "resize_with_algorithm",
165
+ "unregister_algorithm",
166
+ ]