Decouple core photo cleaning logic for CLI and API reuse #2

Closed
opened 2026-09-10 23:01:08 +02:00 by tilltheend · 2 comments
Owner

Parent

Parent Map: #1 (Garment Photo Cleaner Web App [Map])

Question

How should the core processing logic in unwrap_clothes.py be decoupled or modularized so both the existing CLI and the new FastAPI backend in app.py share the exact same encoding, prompt construction, OpenRouter API client, and Lanczos resolution restoration?

## Parent Parent Map: #1 (Garment Photo Cleaner Web App [Map]) ## Question How should the core processing logic in `unwrap_clothes.py` be decoupled or modularized so both the existing CLI and the new FastAPI backend in `app.py` share the exact same encoding, prompt construction, OpenRouter API client, and Lanczos resolution restoration?
tilltheend added the
ready-for-agent
wayfinder:task
labels 2026-09-10 23:01:09 +02:00
tilltheend self-assigned this 2026-09-10 23:12:05 +02:00
Author
Owner

Resolution

Core photo processing and OpenRouter API interaction logic has been extracted into a reusable module .

Architectural decisions

  1. Dual input support: and helper functions accept both file paths () and in-memory raw bytes (), enabling the upcoming FastAPI web endpoint to stream image uploads directly without temporary disk files.
  2. In-memory Lanczos restore: resamples image bytes in memory back to source aspect ratio and pixel dimensions using Pillow's Lanczos filter.
  3. Structured return: returns a dataclass containing image bytes, media type, OpenRouter billing cost, dimensions, and rescale indicators.
  4. CLI backward compatibility: retains identical CLI argument parsing, console output formats, exit codes, and re-exports symbols for backward compatibility.
  5. Test coverage: Comprehensive unit and integration test suite in and passing 20/20 test cases.
## Resolution Core photo processing and OpenRouter API interaction logic has been extracted into a reusable module . ### Architectural decisions 1. **Dual input support**: and helper functions accept both file paths () and in-memory raw bytes (), enabling the upcoming FastAPI web endpoint to stream image uploads directly without temporary disk files. 2. **In-memory Lanczos restore**: resamples image bytes in memory back to source aspect ratio and pixel dimensions using Pillow's Lanczos filter. 3. **Structured return**: returns a dataclass containing image bytes, media type, OpenRouter billing cost, dimensions, and rescale indicators. 4. **CLI backward compatibility**: retains identical CLI argument parsing, console output formats, exit codes, and re-exports symbols for backward compatibility. 5. **Test coverage**: Comprehensive unit and integration test suite in and passing 20/20 test cases.
Author
Owner

Resolution

Core photo processing and OpenRouter API interaction logic has been extracted into a reusable module cleaner.py.

Architectural decisions

  1. Dual input support: clean_garment and helper functions accept both file paths (str) and in-memory raw bytes (bytes), enabling the upcoming FastAPI web endpoint to stream image uploads directly without temporary disk files.
  2. In-memory Lanczos restore: restore_resolution_bytes resamples image bytes in memory back to source aspect ratio and pixel dimensions using Pillow Lanczos filter.
  3. Structured return: clean_garment returns a CleanResult dataclass containing image bytes, media type, OpenRouter billing cost, dimensions, and rescale indicators.
  4. CLI backward compatibility: unwrap_clothes.py retains identical CLI argument parsing, console output formats, exit codes, and re-exports symbols for backward compatibility.
  5. Test coverage: Comprehensive unit and integration test suite in tests/test_cleaner.py and tests/test_unwrap_clothes.py passing 20/20 test cases.
## Resolution Core photo processing and OpenRouter API interaction logic has been extracted into a reusable module `cleaner.py`. ### Architectural decisions 1. **Dual input support**: `clean_garment` and helper functions accept both file paths (`str`) and in-memory raw bytes (`bytes`), enabling the upcoming FastAPI web endpoint to stream image uploads directly without temporary disk files. 2. **In-memory Lanczos restore**: `restore_resolution_bytes` resamples image bytes in memory back to source aspect ratio and pixel dimensions using Pillow Lanczos filter. 3. **Structured return**: `clean_garment` returns a `CleanResult` dataclass containing image bytes, media type, OpenRouter billing cost, dimensions, and rescale indicators. 4. **CLI backward compatibility**: `unwrap_clothes.py` retains identical CLI argument parsing, console output formats, exit codes, and re-exports symbols for backward compatibility. 5. **Test coverage**: Comprehensive unit and integration test suite in `tests/test_cleaner.py` and `tests/test_unwrap_clothes.py` passing 20/20 test cases.
Sign in to join this conversation.
No description provided.