Multimedia Upscale (lexigram-multimedia-upscale)
Image and video super-resolution for the Lexigram Framework — local reference-server backends (real-esrgan, hat).
Overview
Section titled “Overview”lexigram-multimedia-upscale upscales images 2x or 4x with Real-ESRGAN or HAT reference servers, and registers a VideoUpscaleService for frame-level video upscaling when a VideoProcessor is available in the container.
Full documentation: docs.lexigram.dev
Install
Section titled “Install”uv add lexigram-multimedia-upscale# Optional extrasuv add "lexigram-multimedia-upscale[real-esrgan-server]" # Real-ESRGAN server depsuv add "lexigram-multimedia-upscale[hat-server]" # HAT server depsQuick Start
Section titled “Quick Start”from lexigram import Applicationfrom lexigram.di.module import Module, modulefrom lexigram.multimedia.upscale import UpscaleModulefrom lexigram.contracts.multimedia import UpscaleProvider, UpscaleRequest, MediaAsset
@module(imports=[UpscaleModule.configure()])class AppModule(Module): pass
async def main() -> None: async with Application.boot(modules=[AppModule]) as app: upscale = await app.container.resolve(UpscaleProvider) asset = MediaAsset(mime_type="image/png", provider="local", bytes_data=b"<png>") result = await upscale.upscale(UpscaleRequest(asset=asset, scale_factor=4)) if result.is_ok(): upscaled = result.unwrap() # MediaAsset — upscaled image bytes or URI
if __name__ == "__main__": import asyncio
asyncio.run(main())Configuration
Section titled “Configuration”Zero-config usage: Call
UpscaleModule.configure()with no arguments to use thereal-esrganbackend athttp://localhost:5400.
Option 1 — YAML file
Section titled “Option 1 — YAML file”multimedia: upscale: backend: "hat"Option 2 — Profiles + Environment Variables
Section titled “Option 2 — Profiles + Environment Variables”export LEX_PROFILE=productionexport LEX_MULTIMEDIA__UPSCALE__BACKEND=real-esrganOption 3 — Python
Section titled “Option 3 — Python”from lexigram.multimedia.upscale import UpscaleModulefrom lexigram.multimedia.upscale.config import UpscaleConfig
UpscaleModule.configure( config=UpscaleConfig(backend="hat"))The upscale factor is a per-request parameter —
UpscaleRequest(asset=..., scale_factor=Literal[2, 4]), default4. It is not part ofUpscaleConfig.
Config reference
Section titled “Config reference”| Field | Default | Env var | Description |
|---|---|---|---|
backend | "real-esrgan" | LEX_MULTIMEDIA__UPSCALE__BACKEND | real-esrgan, hat |
real_esrgan_base_url | "http://localhost:5400" | LEX_MULTIMEDIA__UPSCALE__REAL_ESRGAN_BASE_URL | Real-ESRGAN server URL |
hat_base_url | "http://localhost:5401" | LEX_MULTIMEDIA__UPSCALE__HAT_BASE_URL | HAT server URL |
timeout | 30.0 | LEX_MULTIMEDIA__UPSCALE__TIMEOUT | Request timeout in seconds |
Module Factory Methods
Section titled “Module Factory Methods”| Method | Description |
|---|---|
UpscaleModule.configure(config) | Configure with explicit upscale config |
UpscaleModule.stub() | Real module pinned to the default real-esrgan backend for tests |
Key Features
Section titled “Key Features”- Two backends —
real-esrgan,hatreference servers - Video upscaling —
VideoUpscaleServicefor frame-level video super-resolution (whenVideoProcessoris available) - Reference servers —
lexigram-upscale-real-esrgan-serveandlexigram-upscale-hat-serveconsole scripts run each local model server - Result-based —
upscale() -> Result[MediaAsset, MultimediaError]; errors are domain values, not exceptions
Testing
Section titled “Testing”from lexigram import Applicationfrom lexigram.multimedia.upscale import UpscaleModule
async def test_boot(): async with Application.boot(modules=[UpscaleModule.stub()]) as app: assert app.container is not NoneKey Source Files
Section titled “Key Source Files”| File | What it contains |
|---|---|
src/lexigram/multimedia/upscale/module.py | UpscaleModule.configure() and .stub() |
src/lexigram/multimedia/upscale/config.py | UpscaleConfig |
src/lexigram/multimedia/upscale/di/provider.py | UpscaleGenerationProvider — registers UpscaleProvider, wires task handlers |
src/lexigram/multimedia/upscale/providers/ | Backend implementations (real_esrgan, hat) |
src/lexigram/multimedia/upscale/servers/ | Reference-server entry points (lexigram-upscale-*-serve) |
src/lexigram/multimedia/upscale/video_upscale_service.py | VideoUpscaleService — frame-level video upscaling |
src/lexigram/multimedia/upscale/tasks.py | Background upscale task handlers |
src/lexigram/multimedia/upscale/exceptions.py | UpscaleError hierarchy |