| from pathlib import Path | |
| from huggingface_hub import snapshot_download | |
| from xjpeg import XJPEG | |
| snapshot = Path(snapshot_download( | |
| "migtissera/x-jpeg", | |
| allow_patterns=["model.safetensors", "config.json"], | |
| )) | |
| codec = XJPEG(snapshot / "model.safetensors") | |
| result = codec.compress("photo.png", output="photo.jpg", target_bpp=0.5) | |
| print({ | |
| "bytes": result.size_bytes, | |
| "bpp": result.bpp, | |
| "rgb_ms_ssim": result.msssim, | |
| "backend": result.backend, | |
| }) | |