from __future__ import annotations import os from pathlib import Path from src.llm.gemma_client import generate_slides_json from src.ppt.deck_generator import compile_presentation from src.ppt.template_loader import parse_template_style from src.utils.validators import validate_template def _resolve_template_path(template_input) -> Path: if template_input is None: raise ValueError("Please upload a `.pptx` template file.") if isinstance(template_input, (str, Path)): return validate_template(template_input) # Gradio file objects generally expose `.name` with the temp file path. file_name = getattr(template_input, "name", None) if file_name: return validate_template(file_name) raise ValueError("Unsupported template input format. Upload a `.pptx` file.") def customize_presentation(template_input, user_input: str) -> str: if not user_input or not user_input.strip(): raise ValueError("Please provide presentation topic/content notes.") template_path = _resolve_template_path(template_input) style_profile = parse_template_style(template_path) backend = os.getenv("MODEL_BACKEND", "transformers") slides_json = generate_slides_json(user_input.strip(), backend=backend) output_path = compile_presentation( slides_payload=slides_json, template_path=template_path, style_profile=style_profile, ) return output_path