Files
photools3/src/photools3/cli.py
T
mathias2784 6a12144e39
Tests / test_and_lint (push) Successful in 12s
Logging (#16)
Reviewed-on: #16
Co-authored-by: Mathias <mathias2784@web.de>
2026-10-03 08:24:17 +00:00

70 lines
1.7 KiB
Python

import logging
from pathlib import Path
from typing import Annotated
import typer
from utils.logging_config import LoggingSettings
from photools3.llm_session import (
LlmSessionCaptionsAndKeywords,
LlmSessionQuality,
)
from photools3.photo import Photo
app = typer.Typer(help="PhotoTools3: A CLI for image processing.")
LoggingSettings()
logger = logging.getLogger(__name__)
@app.callback(invoke_without_command=True)
def main(
ctx: typer.Context,
version: bool | None = typer.Option(None, "--version", is_eager=True),
):
"""
Main entry point for PhotoTools3 CLI.
"""
if version:
typer.echo("photools3 version 0.1.0")
raise typer.Exit()
if ctx.invoked_subcommand is None:
typer.echo(ctx.get_help())
raise typer.Exit()
@app.command("keywords")
def keywords(
file_path: Annotated[Path, typer.Argument(..., help="Path to the image file")],
):
session = LlmSessionCaptionsAndKeywords()
_run_llm_task(file_path, session)
@app.command("quality")
def quality(
file_path: Annotated[Path, typer.Argument(..., help="Path to the image file")],
):
session = LlmSessionQuality()
_run_llm_task(file_path, session)
def _run_llm_task(
file_path: Path, session: LlmSessionCaptionsAndKeywords | LlmSessionQuality
):
try:
logger.info(f"Processing: {file_path}")
photo = Photo(file_path)
result = session.call([photo])
logger.info(result)
except FileNotFoundError:
logger.error(f"Error: File '{file_path}' does not exist.")
raise typer.Exit(code=1)
except Exception as e: # noqa: BLE001
raise typer.Exit(code=1)
logger.error(f"Error processing image: {e}")
if __name__ == "__main__":
app()