""" Headless UGC ad generator (end-to-end test harness). Runs the full pipeline without the WebUI so you can test/debug with real keys. Examples: uv run python scripts/generate_ugc.py --url https://store.com/products/thing uv run python scripts/generate_ugc.py --title "Glow Serum" --image a.jpg --image b.jpg \\ --platform instagram --avatar generative --variants 2 Set keys via env or .env (GEMINI_API_KEY, FAL_KEY, an LLM key in config.toml). """ import argparse import os import sys from uuid import uuid4 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) from app.models.schema import UGCVideoParams, VideoAspect # noqa: E402 from app.services import cost # noqa: E402 from app.services import product as product_service # noqa: E402 from app.services import task as tm # noqa: E402 def main() -> int: ap = argparse.ArgumentParser(description="Generate a UGC e-com ad") ap.add_argument("--url", default="", help="Product URL to import") ap.add_argument("--title", default="", help="Manual product title") ap.add_argument("--desc", default="", help="Manual product description") ap.add_argument("--image", action="append", default=[], help="Local product image (repeatable)") ap.add_argument("--aspect", default="9:16", choices=["9:16", "1:1", "16:9"]) ap.add_argument("--platform", default="tiktok") ap.add_argument("--tone", default="energetic") ap.add_argument("--avatar", default="", help="Avatar engine (heygen|creatify|generative|'')") ap.add_argument("--broll", default="", help="B-roll engine (seedance|veo|stock|'')") ap.add_argument("--variants", type=int, default=1) ap.add_argument("--no-avatar", action="store_true") ap.add_argument("--max-cost", type=float, default=0.0) ap.add_argument("--estimate-only", action="store_true") args = ap.parse_args() if args.url: product = product_service.import_from_url(args.url) elif args.title or args.image: product = product_service.from_manual( title=args.title, description=args.desc, image_paths=args.image ) else: ap.error("provide --url, or --title/--image") print(f"product: title={product.title!r} features={len(product.features)} images={len(product.image_paths)}") params = UGCVideoParams( product_title=product.title, product_description=product.description, product_features=product.features, product_images=product.image_paths, video_aspect=VideoAspect(args.aspect), target_platform=args.platform, ad_tone=args.tone, avatar_provider=args.avatar, broll_provider=args.broll, avatar_enabled=not args.no_avatar, video_count=args.variants, max_cost_usd=args.max_cost, ) est = cost.estimate_plan(params, product) print(f"estimated cost: ${est['total']} {est['items']}") if args.estimate_only: return 0 task_id = str(uuid4()) result = tm.start_ugc(task_id=task_id, params=params) if not result or not result.get("videos"): print("FAILED: no videos produced (see logs above)") return 1 print("\nDONE. Videos:") for v in result["videos"]: print(f" {v}") return 0 if __name__ == "__main__": raise SystemExit(main())