upscale 0.5.1__tar.gz → 0.5.2__tar.gz

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 (93) hide show
  1. {upscale-0.5.1 → upscale-0.5.2}/NOTICE +6 -6
  2. {upscale-0.5.1/upscale.egg-info → upscale-0.5.2}/PKG-INFO +18 -6
  3. {upscale-0.5.1 → upscale-0.5.2}/README.md +17 -5
  4. {upscale-0.5.1 → upscale-0.5.2}/pyproject.toml +1 -1
  5. upscale-0.5.2/tests/test_deep_review_fixes.py +163 -0
  6. upscale-0.5.2/tests/test_slim_import.py +42 -0
  7. {upscale-0.5.1 → upscale-0.5.2}/upscale/__init__.py +1 -1
  8. upscale-0.5.2/upscale/alpha_policy.py +140 -0
  9. {upscale-0.5.1 → upscale-0.5.2}/upscale/api/__init__.py +2 -0
  10. {upscale-0.5.1 → upscale-0.5.2}/upscale/api/compare_routes.py +14 -1
  11. {upscale-0.5.1 → upscale-0.5.2}/upscale/api/jobs.py +23 -4
  12. upscale-0.5.2/upscale/api/media_routes.py +257 -0
  13. {upscale-0.5.1 → upscale-0.5.2}/upscale/api/system_routes.py +11 -1
  14. {upscale-0.5.1 → upscale-0.5.2}/upscale/backends/onnx_rt.py +31 -5
  15. {upscale-0.5.1 → upscale-0.5.2}/upscale/checkpoint.py +8 -7
  16. {upscale-0.5.1 → upscale-0.5.2}/upscale/cli.py +30 -4
  17. {upscale-0.5.1 → upscale-0.5.2}/upscale/compare.py +3 -1
  18. {upscale-0.5.1 → upscale-0.5.2}/upscale/engine.py +83 -110
  19. {upscale-0.5.1 → upscale-0.5.2}/upscale/help_content.py +1 -0
  20. {upscale-0.5.1 → upscale-0.5.2}/upscale/io_utils.py +6 -0
  21. upscale-0.5.2/upscale/memmap_util.py +70 -0
  22. {upscale-0.5.1 → upscale-0.5.2}/upscale/pipeline.py +14 -17
  23. {upscale-0.5.1 → upscale-0.5.2}/upscale/server.py +4 -167
  24. {upscale-0.5.1 → upscale-0.5.2}/upscale/tiling.py +72 -34
  25. {upscale-0.5.1 → upscale-0.5.2}/upscale/web.py +2 -2
  26. upscale-0.5.2/upscale/weight_blend.py +75 -0
  27. {upscale-0.5.1 → upscale-0.5.2/upscale.egg-info}/PKG-INFO +18 -6
  28. {upscale-0.5.1 → upscale-0.5.2}/upscale.egg-info/SOURCES.txt +5 -0
  29. upscale-0.5.1/tests/test_slim_import.py +0 -30
  30. {upscale-0.5.1 → upscale-0.5.2}/LICENSE +0 -0
  31. {upscale-0.5.1 → upscale-0.5.2}/setup.cfg +0 -0
  32. {upscale-0.5.1 → upscale-0.5.2}/tests/test_about.py +0 -0
  33. {upscale-0.5.1 → upscale-0.5.2}/tests/test_algorithms.py +0 -0
  34. {upscale-0.5.1 → upscale-0.5.2}/tests/test_api.py +0 -0
  35. {upscale-0.5.1 → upscale-0.5.2}/tests/test_api_queue_gpu_bench.py +0 -0
  36. {upscale-0.5.1 → upscale-0.5.2}/tests/test_cancel.py +0 -0
  37. {upscale-0.5.1 → upscale-0.5.2}/tests/test_checkpoint_quality.py +0 -0
  38. {upscale-0.5.1 → upscale-0.5.2}/tests/test_cli.py +0 -0
  39. {upscale-0.5.1 → upscale-0.5.2}/tests/test_compare_zip_api.py +0 -0
  40. {upscale-0.5.1 → upscale-0.5.2}/tests/test_crop.py +0 -0
  41. {upscale-0.5.1 → upscale-0.5.2}/tests/test_estimates.py +0 -0
  42. {upscale-0.5.1 → upscale-0.5.2}/tests/test_filters.py +0 -0
  43. {upscale-0.5.1 → upscale-0.5.2}/tests/test_help_security.py +0 -0
  44. {upscale-0.5.1 → upscale-0.5.2}/tests/test_io.py +0 -0
  45. {upscale-0.5.1 → upscale-0.5.2}/tests/test_locales.py +0 -0
  46. {upscale-0.5.1 → upscale-0.5.2}/tests/test_mcp.py +0 -0
  47. {upscale-0.5.1 → upscale-0.5.2}/tests/test_models_registry.py +0 -0
  48. {upscale-0.5.1 → upscale-0.5.2}/tests/test_naming.py +0 -0
  49. {upscale-0.5.1 → upscale-0.5.2}/tests/test_onnx_backend.py +0 -0
  50. {upscale-0.5.1 → upscale-0.5.2}/tests/test_output_path.py +0 -0
  51. {upscale-0.5.1 → upscale-0.5.2}/tests/test_passes.py +0 -0
  52. {upscale-0.5.1 → upscale-0.5.2}/tests/test_pause.py +0 -0
  53. {upscale-0.5.1 → upscale-0.5.2}/tests/test_pipeline_mmap.py +0 -0
  54. {upscale-0.5.1 → upscale-0.5.2}/tests/test_resume_checkpoint_api.py +0 -0
  55. {upscale-0.5.1 → upscale-0.5.2}/tests/test_run_server_thread.py +0 -0
  56. {upscale-0.5.1 → upscale-0.5.2}/tests/test_schema.py +0 -0
  57. {upscale-0.5.1 → upscale-0.5.2}/tests/test_seamless_wh.py +0 -0
  58. {upscale-0.5.1 → upscale-0.5.2}/tests/test_security_models.py +0 -0
  59. {upscale-0.5.1 → upscale-0.5.2}/tests/test_speed_stats.py +0 -0
  60. {upscale-0.5.1 → upscale-0.5.2}/tests/test_spill_cancel.py +0 -0
  61. {upscale-0.5.1 → upscale-0.5.2}/tests/test_strip_checkpoint.py +0 -0
  62. {upscale-0.5.1 → upscale-0.5.2}/tests/test_strip_vs_full.py +0 -0
  63. {upscale-0.5.1 → upscale-0.5.2}/tests/test_suggest_presets.py +0 -0
  64. {upscale-0.5.1 → upscale-0.5.2}/tests/test_tiling.py +0 -0
  65. {upscale-0.5.1 → upscale-0.5.2}/upscale/__main__.py +0 -0
  66. {upscale-0.5.1 → upscale-0.5.2}/upscale/about.py +0 -0
  67. {upscale-0.5.1 → upscale-0.5.2}/upscale/algorithms/__init__.py +0 -0
  68. {upscale-0.5.1 → upscale-0.5.2}/upscale/algorithms/classical.py +0 -0
  69. {upscale-0.5.1 → upscale-0.5.2}/upscale/algorithms/plugins/__init__.py +0 -0
  70. {upscale-0.5.1 → upscale-0.5.2}/upscale/algorithms/plugins/texture_residual.py +0 -0
  71. {upscale-0.5.1 → upscale-0.5.2}/upscale/algorithms/plugins/vectorize_scale.py +0 -0
  72. {upscale-0.5.1 → upscale-0.5.2}/upscale/api/deps.py +0 -0
  73. {upscale-0.5.1 → upscale-0.5.2}/upscale/api/models_routes.py +0 -0
  74. {upscale-0.5.1 → upscale-0.5.2}/upscale/backends/__init__.py +0 -0
  75. {upscale-0.5.1 → upscale-0.5.2}/upscale/benchmark.py +0 -0
  76. {upscale-0.5.1 → upscale-0.5.2}/upscale/config.py +0 -0
  77. {upscale-0.5.1 → upscale-0.5.2}/upscale/estimates.py +0 -0
  78. {upscale-0.5.1 → upscale-0.5.2}/upscale/filters.py +0 -0
  79. {upscale-0.5.1 → upscale-0.5.2}/upscale/infer_util.py +0 -0
  80. {upscale-0.5.1 → upscale-0.5.2}/upscale/job_prep.py +0 -0
  81. {upscale-0.5.1 → upscale-0.5.2}/upscale/mcp_server.py +0 -0
  82. {upscale-0.5.1 → upscale-0.5.2}/upscale/models.py +0 -0
  83. {upscale-0.5.1 → upscale-0.5.2}/upscale/naming.py +0 -0
  84. {upscale-0.5.1 → upscale-0.5.2}/upscale/presets.py +0 -0
  85. {upscale-0.5.1 → upscale-0.5.2}/upscale/quality.py +0 -0
  86. {upscale-0.5.1 → upscale-0.5.2}/upscale/schema.py +0 -0
  87. {upscale-0.5.1 → upscale-0.5.2}/upscale/speed_stats.py +0 -0
  88. {upscale-0.5.1 → upscale-0.5.2}/upscale/suggest.py +0 -0
  89. {upscale-0.5.1 → upscale-0.5.2}/upscale/system.py +0 -0
  90. {upscale-0.5.1 → upscale-0.5.2}/upscale.egg-info/dependency_links.txt +0 -0
  91. {upscale-0.5.1 → upscale-0.5.2}/upscale.egg-info/entry_points.txt +0 -0
  92. {upscale-0.5.1 → upscale-0.5.2}/upscale.egg-info/requires.txt +0 -0
  93. {upscale-0.5.1 → upscale-0.5.2}/upscale.egg-info/top_level.txt +0 -0
@@ -1,6 +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.
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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: upscale
3
- Version: 0.5.1
3
+ Version: 0.5.2
4
4
  Summary: Local AI image upscaler: chained Real-ESRGAN passes to any scale, seam-free feather-blended tiles
5
5
  Author: upscale
6
6
  License: MIT
@@ -72,6 +72,8 @@ Dynamic: license-file
72
72
  # upscale
73
73
 
74
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/upscale)](https://pypi.org/project/upscale/)
75
77
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
76
78
 
77
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.
@@ -85,7 +87,10 @@ Local AI image upscale. Chains Real-ESRGAN passes (via [spandrel](https://github
85
87
  ## Install
86
88
 
87
89
  ```bash
88
- pip install "git+https://github.com/wwylon/upscale.git" # or: pipx install git+https://github.com/wwylon/upscale.git
90
+ pip install upscale
91
+ pip install "upscale[server]" # web UI + job API
92
+ pip install "upscale[mcp]" # MCP tools for agents
93
+ # or: pipx install upscale
89
94
  ```
90
95
 
91
96
  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).
@@ -94,8 +99,8 @@ From a clone:
94
99
 
95
100
  ```bash
96
101
  pip install -e .
97
- pip install -e ".[server]" # web UI + job API
98
- pip install -e ".[mcp]" # MCP tools for agents
102
+ pip install -e ".[server,mcp]"
103
+ # tip without cloning: pip install "git+https://github.com/wwylon/upscale.git"
99
104
  ```
100
105
 
101
106
  ## First win
@@ -141,9 +146,16 @@ execute(UpscaleConfig(input="in.png", output="out.png", scale=4, cpu=True))
141
146
 
142
147
  ## Tests
143
148
 
149
+ Local gate (also in [CONTRIBUTING.md](CONTRIBUTING.md) / `publish.manifest.yaml`):
150
+
144
151
  ```bash
145
- pip install -e ".[dev,server,mcp]"
146
- pytest
152
+ uv sync --locked --extra dev --extra server --extra mcp
153
+ uv run ruff check upscale tests
154
+ uv run mypy --follow-imports=silent upscale/schema.py upscale/job_prep.py upscale/config.py upscale/naming.py upscale/api
155
+ uv run pytest -q
156
+ uv run python scripts/cpu_smoke.py
147
157
  ```
148
158
 
159
+ GitHub Actions are disabled to save minutes; run the gate locally (or `workflow_dispatch` if re-enabled) before publish.
160
+
149
161
  MIT licensed. See [CONTRIBUTING.md](CONTRIBUTING.md) and [SECURITY.md](SECURITY.md).
@@ -1,6 +1,8 @@
1
1
  # upscale
2
2
 
3
3
  [![CI](https://github.com/wwylon/upscale/actions/workflows/ci.yml/badge.svg)](https://github.com/wwylon/upscale/actions/workflows/ci.yml)
4
+ [![Release](https://img.shields.io/github/v/release/wwylon/upscale)](https://github.com/wwylon/upscale/releases)
5
+ [![PyPI](https://img.shields.io/pypi/v/upscale)](https://pypi.org/project/upscale/)
4
6
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
5
7
 
6
8
  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.
@@ -14,7 +16,10 @@ Local AI image upscale. Chains Real-ESRGAN passes (via [spandrel](https://github
14
16
  ## Install
15
17
 
16
18
  ```bash
17
- pip install "git+https://github.com/wwylon/upscale.git" # or: pipx install git+https://github.com/wwylon/upscale.git
19
+ pip install upscale
20
+ pip install "upscale[server]" # web UI + job API
21
+ pip install "upscale[mcp]" # MCP tools for agents
22
+ # or: pipx install upscale
18
23
  ```
19
24
 
20
25
  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).
@@ -23,8 +28,8 @@ From a clone:
23
28
 
24
29
  ```bash
25
30
  pip install -e .
26
- pip install -e ".[server]" # web UI + job API
27
- pip install -e ".[mcp]" # MCP tools for agents
31
+ pip install -e ".[server,mcp]"
32
+ # tip without cloning: pip install "git+https://github.com/wwylon/upscale.git"
28
33
  ```
29
34
 
30
35
  ## First win
@@ -70,9 +75,16 @@ execute(UpscaleConfig(input="in.png", output="out.png", scale=4, cpu=True))
70
75
 
71
76
  ## Tests
72
77
 
78
+ Local gate (also in [CONTRIBUTING.md](CONTRIBUTING.md) / `publish.manifest.yaml`):
79
+
73
80
  ```bash
74
- pip install -e ".[dev,server,mcp]"
75
- pytest
81
+ uv sync --locked --extra dev --extra server --extra mcp
82
+ uv run ruff check upscale tests
83
+ uv run mypy --follow-imports=silent upscale/schema.py upscale/job_prep.py upscale/config.py upscale/naming.py upscale/api
84
+ uv run pytest -q
85
+ uv run python scripts/cpu_smoke.py
76
86
  ```
77
87
 
88
+ GitHub Actions are disabled to save minutes; run the gate locally (or `workflow_dispatch` if re-enabled) before publish.
89
+
78
90
  MIT licensed. See [CONTRIBUTING.md](CONTRIBUTING.md) and [SECURITY.md](SECURITY.md).
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "upscale"
7
- version = "0.5.1"
7
+ version = "0.5.2"
8
8
  description = "Local AI image upscaler: chained Real-ESRGAN passes to any scale, seam-free feather-blended tiles"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -0,0 +1,163 @@
1
+ """Regression tests for the 2026-11-19 deep-review wave."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from pathlib import Path
7
+
8
+ import numpy as np
9
+ import pytest
10
+ from fastapi.testclient import TestClient
11
+ from png_fixtures import TINY_PNG
12
+
13
+ from upscale.checkpoint import list_checkpoints
14
+ from upscale.compare import build_variants
15
+ from upscale.job_prep import MAX_OUTPUT_PIXELS
16
+ from upscale.server import app
17
+
18
+
19
+ @pytest.fixture
20
+ def client():
21
+ return TestClient(app)
22
+
23
+
24
+ def test_list_checkpoints_corrupt_json(tmp_path: Path):
25
+ ck = tmp_path / "checkpoints"
26
+ ck.mkdir()
27
+ (ck / "strip.json").write_text("{not-json", encoding="utf-8")
28
+ assert list_checkpoints(tmp_path) == []
29
+
30
+
31
+ def test_batch_algorithm_naming_token(tmp_path: Path):
32
+ """When --algorithm is set, name patterns should use the algorithm token."""
33
+ from upscale.config import UpscaleConfig
34
+ from upscale.naming import resolve_output_path
35
+
36
+ cfg = UpscaleConfig(algorithm="lanczos3", model="RealESRGAN_x4plus", scale=2.0)
37
+ model_token = cfg.algorithm if cfg.algorithm else cfg.model
38
+ out = resolve_output_path(
39
+ tmp_path,
40
+ stem="a",
41
+ scale=2,
42
+ model=model_token,
43
+ ext="png",
44
+ )
45
+ assert out is not None
46
+ assert "lanczos3" in out.name
47
+ assert "RealESRGAN" not in out.name
48
+
49
+
50
+ def test_filter_variants_use_classical():
51
+ variants = build_variants(filters=["edge"], base_model="RealESRGAN_x4plus")
52
+ assert len(variants) == 1
53
+ assert variants[0]["kind"] == "filter"
54
+ assert variants[0]["algorithm"] == "lanczos3"
55
+
56
+
57
+ def test_compare_rejects_svg(client: TestClient):
58
+ r = client.post(
59
+ "/api/compare",
60
+ data={
61
+ "body": json.dumps(
62
+ {
63
+ "models": ["RealESRGAN_x4plus"],
64
+ "crop": {"x": 0, "y": 0, "w": 8, "h": 8},
65
+ "scale": 2,
66
+ }
67
+ )
68
+ },
69
+ files={"file": ("icon.svg", b"<svg/>", "image/svg+xml")},
70
+ )
71
+ assert r.status_code == 400
72
+
73
+
74
+ def test_suggest_rejects_svg(client: TestClient):
75
+ r = client.post(
76
+ "/api/suggest",
77
+ files={"file": ("icon.svg", b"<svg/>", "image/svg+xml")},
78
+ )
79
+ assert r.status_code == 400
80
+
81
+
82
+ def test_suggest_accepts_png(client: TestClient):
83
+ import io
84
+
85
+ from PIL import Image
86
+
87
+ buf = io.BytesIO()
88
+ Image.fromarray(np.random.randint(0, 255, (64, 64, 3), dtype=np.uint8)).save(
89
+ buf, format="PNG"
90
+ )
91
+ r = client.post(
92
+ "/api/suggest",
93
+ files={"file": ("sample.png", buf.getvalue(), "image/png")},
94
+ )
95
+ assert r.status_code == 200
96
+ body = r.json()
97
+ assert "model" in body
98
+ assert "kind" in body
99
+
100
+
101
+ def test_create_job_scale_megapixel_reject(client: TestClient):
102
+ huge_scale = (MAX_OUTPUT_PIXELS // 64) + 10
103
+ r = client.post(
104
+ "/api/jobs",
105
+ data={"settings": json.dumps({"scale": float(huge_scale)})},
106
+ files={"file": ("tiny.png", TINY_PNG, "image/png")},
107
+ )
108
+ assert r.status_code == 400
109
+ assert "pixel" in r.text.lower() or "exceed" in r.text.lower() or "budget" in r.text.lower()
110
+
111
+
112
+ def test_api_estimate_still_works(client: TestClient):
113
+ r = client.post(
114
+ "/api/estimate",
115
+ json={"src_w": 64, "src_h": 64, "scale": 4.0, "model": "RealESRGAN_x4plus"},
116
+ )
117
+ assert r.status_code == 200
118
+ assert "seconds" in r.json()
119
+
120
+
121
+ def test_api_preflight(client: TestClient):
122
+ r = client.post(
123
+ "/api/preflight",
124
+ json={
125
+ "src_w": 64,
126
+ "src_h": 64,
127
+ "scale": 4.0,
128
+ "model": "RealESRGAN_x4plus",
129
+ "device": "cpu",
130
+ },
131
+ )
132
+ assert r.status_code == 200
133
+ body = r.json()
134
+ assert "ok" in body
135
+ assert "checks" in body
136
+ assert "target_w" in body
137
+
138
+
139
+ def test_alpha_policy_lanczos():
140
+ from upscale.alpha_policy import upsample_alpha
141
+
142
+ a = np.full((8, 8), 200, dtype=np.uint8)
143
+ out = upsample_alpha(a, scale=2.0, target_w=16, target_h=16, sr_alpha=False)
144
+ assert out.shape == (16, 16)
145
+ assert out.dtype == np.uint8
146
+
147
+
148
+ def test_help_backends_topic(client: TestClient):
149
+ r = client.get("/api/help/backends")
150
+ assert r.status_code == 200
151
+ md = r.json()["markdown"]
152
+ assert "ONNX" in md or "Torch" in md
153
+
154
+
155
+ def test_memmap_util_spill(tmp_path: Path):
156
+ from upscale.memmap_util import is_memmap, materialize, spill_uint8_rows
157
+
158
+ arr = np.arange(12, dtype=np.uint8).reshape(3, 4)
159
+ dest = tmp_path / "x.bin"
160
+ spill_uint8_rows(arr, dest, chunk=2)
161
+ assert dest.stat().st_size == 12
162
+ assert not is_memmap(arr)
163
+ assert materialize(arr).shape == arr.shape
@@ -0,0 +1,42 @@
1
+ """B1: server import path must not require torch when UPSCALE_BACKEND=onnx."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+ from types import ModuleType
7
+
8
+
9
+ def test_server_imports_without_torch(monkeypatch):
10
+ monkeypatch.setenv("UPSCALE_BACKEND", "onnx")
11
+ # Block torch if not already imported; if already imported, still exercise onnx backend path.
12
+ if "torch" not in sys.modules:
13
+ blocker = ModuleType("torch")
14
+
15
+ def _fail(*_a, **_k):
16
+ raise ImportError("torch blocked for slim import test")
17
+
18
+ blocker.__getattr__ = lambda _n: (_ for _ in ()).throw(ImportError("blocked")) # type: ignore[attr-defined]
19
+ sys.modules["torch"] = blocker
20
+
21
+ # Fresh import of modules that used to pull torch at top level
22
+ # Snapshot and restore afterwards: later tests patch the original module objects, and a
23
+ # leaked fresh ``upscale.pipeline`` makes ``from .pipeline import run`` bypass their patches.
24
+ import upscale as pkg
25
+
26
+ names = [n for n in sys.modules if n.startswith("upscale.pipeline") or n.startswith("upscale.server")]
27
+ saved = {n: sys.modules[n] for n in names}
28
+ saved_attrs = {a: getattr(pkg, a) for a in ("pipeline", "server") if hasattr(pkg, a)}
29
+ for name in names:
30
+ del sys.modules[name]
31
+ try:
32
+ import upscale.pipeline as pipeline
33
+ import upscale.server as server
34
+
35
+ assert pipeline.compute_passes(4, 4) == 1
36
+ assert server.app.title == "Upscale"
37
+ finally:
38
+ for name in [n for n in sys.modules if n.startswith("upscale.pipeline") or n.startswith("upscale.server")]:
39
+ del sys.modules[name]
40
+ sys.modules.update(saved)
41
+ for attr, mod in saved_attrs.items():
42
+ setattr(pkg, attr, mod)
@@ -27,4 +27,4 @@ __all__ = [
27
27
  "resolve_device",
28
28
  ]
29
29
 
30
- __version__ = "0.5.1"
30
+ __version__ = "0.5.2"
@@ -0,0 +1,140 @@
1
+ """Alpha-channel upsampling policy shared by Torch and ONNX backends.
2
+
3
+ Default is Lanczos (classical). Neural SR of alpha is optional, Torch-only,
4
+ and expensive: the alpha plane is expanded to 3ch, run through the same
5
+ tiled SR path as RGB, then averaged back to a single channel.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from typing import Any
11
+
12
+ import numpy as np
13
+
14
+ from .io_utils import lanczos_resize
15
+
16
+
17
+ def upsample_alpha_lanczos(
18
+ alpha: np.ndarray,
19
+ *,
20
+ target_w: int,
21
+ target_h: int,
22
+ ) -> np.ndarray:
23
+ """Classical Lanczos resize of a single-channel alpha plane."""
24
+ a = np.asarray(alpha)
25
+ if a.ndim == 3:
26
+ a = a[:, :, 0]
27
+ a = np.ascontiguousarray(a, dtype=np.uint8)
28
+ if a.shape[1] == target_w and a.shape[0] == target_h:
29
+ return a
30
+ return lanczos_resize(a, target_w, target_h)
31
+
32
+
33
+ def upsample_alpha_sr(
34
+ alpha: np.ndarray,
35
+ *,
36
+ scale: float,
37
+ descriptor: Any,
38
+ device: Any,
39
+ fp16: bool,
40
+ tile: int,
41
+ overlap: int,
42
+ show_progress: bool = False,
43
+ model_scale: int | None = None,
44
+ disk_intermediate_threshold: int | None = None,
45
+ cancel_event: Any = None,
46
+ pause_event: Any = None,
47
+ target_w: int | None = None,
48
+ target_h: int | None = None,
49
+ infer_fn: Any = None,
50
+ ) -> np.ndarray:
51
+ """Neural SR of alpha via grayscale→RGB stack then channel mean.
52
+
53
+ Prefer :func:`upsample_alpha_lanczos` for soft/semi-transparent edges;
54
+ this path is for hard mattes where SR edge detail matters and the user
55
+ opted in with ``--sr-alpha``.
56
+ """
57
+ from .pipeline import DEFAULT_DISK_INTERMEDIATE_THRESHOLD, run
58
+
59
+ a = np.asarray(alpha)
60
+ if a.ndim == 3:
61
+ a = a[:, :, 0]
62
+ a = np.ascontiguousarray(a, dtype=np.uint8)
63
+ rgb = np.stack([a, a, a], axis=-1)
64
+ thr = (
65
+ DEFAULT_DISK_INTERMEDIATE_THRESHOLD
66
+ if disk_intermediate_threshold is None
67
+ else disk_intermediate_threshold
68
+ )
69
+ out = run(
70
+ rgb,
71
+ scale=scale,
72
+ descriptor=descriptor,
73
+ device=device,
74
+ fp16=fp16,
75
+ tile=tile,
76
+ overlap=overlap,
77
+ show_progress=show_progress,
78
+ model_scale=model_scale,
79
+ disk_intermediate_threshold=thr,
80
+ cancel_event=cancel_event,
81
+ pause_event=pause_event,
82
+ strength=1.0,
83
+ target_w=target_w,
84
+ target_h=target_h,
85
+ infer_fn=infer_fn,
86
+ )
87
+ return out.mean(axis=-1).round().astype(np.uint8)
88
+
89
+
90
+ def upsample_alpha(
91
+ alpha: np.ndarray,
92
+ *,
93
+ scale: float,
94
+ target_w: int,
95
+ target_h: int,
96
+ sr_alpha: bool = False,
97
+ descriptor: Any = None,
98
+ device: Any = None,
99
+ fp16: bool = False,
100
+ tile: int = 256,
101
+ overlap: int = 32,
102
+ show_progress: bool = False,
103
+ model_scale: int | None = None,
104
+ disk_intermediate_threshold: int | None = None,
105
+ cancel_event: Any = None,
106
+ pause_event: Any = None,
107
+ infer_fn: Any = None,
108
+ allow_sr: bool = True,
109
+ ) -> np.ndarray:
110
+ """Resolve alpha to ``target_w×target_h``.
111
+
112
+ When ``sr_alpha`` is False, or SR is disallowed / unavailable, uses Lanczos
113
+ to the target size. When ``sr_alpha`` and ``allow_sr`` and a descriptor or
114
+ ``infer_fn`` is present, runs neural SR (may produce a padded canvas that
115
+ finalize unwraps).
116
+ """
117
+ if (
118
+ sr_alpha
119
+ and allow_sr
120
+ and scale > 1.0
121
+ and (descriptor is not None or infer_fn is not None)
122
+ ):
123
+ return upsample_alpha_sr(
124
+ alpha,
125
+ scale=scale,
126
+ descriptor=descriptor,
127
+ device=device,
128
+ fp16=fp16,
129
+ tile=tile,
130
+ overlap=overlap,
131
+ show_progress=show_progress,
132
+ model_scale=model_scale,
133
+ disk_intermediate_threshold=disk_intermediate_threshold,
134
+ cancel_event=cancel_event,
135
+ pause_event=pause_event,
136
+ target_w=target_w,
137
+ target_h=target_h,
138
+ infer_fn=infer_fn,
139
+ )
140
+ return upsample_alpha_lanczos(alpha, target_w=target_w, target_h=target_h)
@@ -8,6 +8,7 @@ from fastapi import FastAPI
8
8
  def include_routers(app: FastAPI) -> None:
9
9
  from .compare_routes import router as compare_router
10
10
  from .jobs import router as jobs_router
11
+ from .media_routes import router as media_router
11
12
  from .models_routes import router as models_router
12
13
  from .system_routes import router as system_router
13
14
 
@@ -15,3 +16,4 @@ def include_routers(app: FastAPI) -> None:
15
16
  app.include_router(compare_router)
16
17
  app.include_router(models_router)
17
18
  app.include_router(system_router)
19
+ app.include_router(media_router)
@@ -165,7 +165,20 @@ async def api_compare(
165
165
  run_id = uuid.uuid4().hex
166
166
  run_dir = D.JOBS_ROOT / f"compare-{run_id}"
167
167
  run_dir.mkdir(parents=True, exist_ok=True)
168
- suffix = Path(file.filename or "input.png").suffix or ".png"
168
+ from upscale.io_utils import is_vector_input, require_raster_suffix
169
+
170
+ try:
171
+ suffix = require_raster_suffix(file.filename)
172
+ except ValueError as exc:
173
+ shutil.rmtree(run_dir, ignore_errors=True)
174
+ raise HTTPException(400, str(exc)) from exc
175
+ if is_vector_input(file.filename, file.content_type):
176
+ shutil.rmtree(run_dir, ignore_errors=True)
177
+ raise HTTPException(
178
+ 400,
179
+ "Vector images are not supported. "
180
+ "Rasterize to PNG, TIFF, or another supported bitmap format first.",
181
+ )
169
182
  input_path = run_dir / f"input{suffix}"
170
183
  content = await file.read()
171
184
  if len(content) > D.MAX_UPLOAD_BYTES:
@@ -35,9 +35,6 @@ async def create_job(
35
35
  js = js.model_copy(update={"scale": 4.0})
36
36
  if (js.width is None) ^ (js.height is None):
37
37
  raise HTTPException(400, "Specify both width and height, or neither.")
38
- # Soft output pixel budget (matches job_prep.MAX_OUTPUT_PIXELS intent).
39
- if js.width is not None and js.height is not None and js.width * js.height > 200_000_000:
40
- raise HTTPException(400, "Output dimensions exceed the pixel budget.")
41
38
  if js.scale is not None and js.scale > 64:
42
39
  raise HTTPException(400, "Scale exceeds the allowed maximum (64).")
43
40
 
@@ -54,7 +51,9 @@ async def create_job(
54
51
  job_dir = D.JOBS_ROOT / job_id
55
52
  job_dir.mkdir(parents=True, exist_ok=True)
56
53
 
57
- from upscale.io_utils import is_vector_input, require_raster_suffix
54
+ from upscale.config import UpscaleConfig
55
+ from upscale.io_utils import is_vector_input, probe_image_size, require_raster_suffix
56
+ from upscale.job_prep import resolve_scale_and_targets
58
57
 
59
58
  try:
60
59
  suffix = require_raster_suffix(file.filename)
@@ -85,6 +84,26 @@ async def create_job(
85
84
  shutil.rmtree(job_dir, ignore_errors=True)
86
85
  raise HTTPException(400, "Could not read uploaded image") from None
87
86
 
87
+ # Reject oversize outputs at create time (scale / target / W×H), matching job_prep.
88
+ try:
89
+ iw, ih = probe_image_size(input_path)
90
+ crop = js.crop
91
+ cw, ch = iw, ih
92
+ if crop is not None:
93
+ cw = max(1, min(int(crop.w), iw))
94
+ ch = max(1, min(int(crop.h), ih))
95
+ cfg_probe = UpscaleConfig(
96
+ scale=js.scale,
97
+ target_size=js.target_size,
98
+ width=js.width,
99
+ height=js.height,
100
+ )
101
+ resolve_scale_and_targets(cfg_probe, cw, ch)
102
+ except Exception as exc: # noqa: BLE001 — UsageError / OSError / ValueError
103
+ shutil.rmtree(job_dir, ignore_errors=True)
104
+ msg = str(exc) or "Invalid output sizing."
105
+ raise HTTPException(400, msg) from exc
106
+
88
107
  job = D.JobRecord(id=job_id, job_dir=job_dir, input_path=input_path, settings=js)
89
108
  (job_dir / "settings.json").write_text(
90
109
  js.model_dump_json(exclude_none=True), encoding="utf-8"