"""Package initialization for the alt text generator app.""" from pathlib import Path from flask import Flask from .cache import AltTextCache from .config import load_settings from .immich import ImmichClient from .openai_client import AltTextGenerator def create_app() -> Flask: """Create and configure the Flask application.""" package_path = Path(__file__).resolve().parent project_root = package_path.parent app = Flask( __name__, template_folder=str(project_root / "templates"), static_folder=str(project_root / "static"), ) settings = load_settings() app.config.update(settings) secret_key = app.config.get("SECRET_KEY") or "dev-secret-key" app.config["SECRET_KEY"] = secret_key db_path = app.config.get("ALT_TEXT_DB") if not db_path: db_path = str(Path(app.instance_path) / "alt_text_cache.db") app.config["ALT_TEXT_DB"] = db_path Path(app.instance_path).mkdir(parents=True, exist_ok=True) app.immich_client = ImmichClient( base_url=app.config["IMMICH_API_URL"], api_key=app.config["IMMICH_API_KEY"], ) app.alt_text_cache = AltTextCache(db_path) app.alt_text_generator = AltTextGenerator( api_key=app.config["OPENAI_API_KEY"], model=app.config.get("OPENAI_MODEL", "gpt-4o-mini"), ) from . import routes # pragma: no cover app.register_blueprint(routes.bp) return app