front page + decoder fixes, png encoding optimizations + avif plugin dropped (its worse than the default avif of PIL)
Browse files- requirements_docker.txt +2 -3
- server.py +6 -6
requirements_docker.txt
CHANGED
|
@@ -2,10 +2,9 @@ fastapi
|
|
| 2 |
uvicorn[standard]
|
| 3 |
python-multipart
|
| 4 |
numpy
|
| 5 |
-
Pillow
|
| 6 |
pandas
|
| 7 |
numba
|
| 8 |
matplotlib
|
| 9 |
opencv-python-headless
|
| 10 |
-
optuna
|
| 11 |
-
pillow-avif-plugin
|
|
|
|
| 2 |
uvicorn[standard]
|
| 3 |
python-multipart
|
| 4 |
numpy
|
| 5 |
+
Pillow>=11.3
|
| 6 |
pandas
|
| 7 |
numba
|
| 8 |
matplotlib
|
| 9 |
opencv-python-headless
|
| 10 |
+
optuna
|
|
|
server.py
CHANGED
|
@@ -163,9 +163,9 @@ def generate_multlist(bit_count, min_val, max_val, mode="Stable_Uniform"):
|
|
| 163 |
DEMO_MULT_LIST = generate_multlist(7, -255, 255, "Stable_Uniform")
|
| 164 |
|
| 165 |
|
| 166 |
-
def _png_b64(img: Image.Image) -> str:
|
| 167 |
buf = io.BytesIO()
|
| 168 |
-
img.save(buf, format="PNG")
|
| 169 |
return "data:image/png;base64," + base64.b64encode(buf.getvalue()).decode()
|
| 170 |
|
| 171 |
|
|
@@ -296,8 +296,8 @@ async def stream_compress(image: UploadFile = File(...), downsample_initialize:
|
|
| 296 |
img = Image.open(io.BytesIO(raw)).convert("RGB")
|
| 297 |
|
| 298 |
def gen():
|
| 299 |
-
for ev in
|
| 300 |
-
|
| 301 |
if ev["event"] == "frame":
|
| 302 |
yield json.dumps({"image": _png_b64(ev["image"])}) + "\n"
|
| 303 |
|
|
@@ -309,8 +309,8 @@ async def decode(file: UploadFile = File(...)):
|
|
| 309 |
raw = await file.read()
|
| 310 |
|
| 311 |
try:
|
| 312 |
-
dec_res = PBC3.decompress(bytes(raw))
|
| 313 |
-
img = dec_res.image
|
| 314 |
elapsed = dec_res.encode_seconds
|
| 315 |
except Exception as exc:
|
| 316 |
return JSONResponse({"error": f"Decode failed: {exc}"}, status_code=400)
|
|
|
|
| 163 |
DEMO_MULT_LIST = generate_multlist(7, -255, 255, "Stable_Uniform")
|
| 164 |
|
| 165 |
|
| 166 |
+
def _png_b64(img: Image.Image, compress_level: int = 6) -> str:
|
| 167 |
buf = io.BytesIO()
|
| 168 |
+
img.save(buf, format="PNG", compress_level=compress_level)
|
| 169 |
return "data:image/png;base64," + base64.b64encode(buf.getvalue()).decode()
|
| 170 |
|
| 171 |
|
|
|
|
| 296 |
img = Image.open(io.BytesIO(raw)).convert("RGB")
|
| 297 |
|
| 298 |
def gen():
|
| 299 |
+
for ev in PBC3.compress_stream(img, auto_downsample_init=_truthy(downsample_initialize),
|
| 300 |
+
patch_count=600, frame_every=25):
|
| 301 |
if ev["event"] == "frame":
|
| 302 |
yield json.dumps({"image": _png_b64(ev["image"])}) + "\n"
|
| 303 |
|
|
|
|
| 309 |
raw = await file.read()
|
| 310 |
|
| 311 |
try:
|
| 312 |
+
dec_res = PBC3.decompress(bytes(raw))
|
| 313 |
+
img = dec_res.image.convert("RGB")
|
| 314 |
elapsed = dec_res.encode_seconds
|
| 315 |
except Exception as exc:
|
| 316 |
return JSONResponse({"error": f"Decode failed: {exc}"}, status_code=400)
|