Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions backend/app/generator_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ class GeneratorService:
def __init__(self, ppt_service: PPTService):
self.ppt_service = ppt_service

def apply_theme_preset(self, path: str, preset: str, output_path: str | None = None) -> tuple[str, ThemeConfig]:
prs = Presentation(path)
req = GenerateRequest(topic="theme-apply", preset=preset)
theme = self._select_theme(req, [])
self.ppt_service.apply_theme_to_presentation(prs, theme)
save_path = output_path or self.ppt_service._default_output(path, f"preset-{theme.name}")
prs.save(save_path)
return save_path, theme

def generate(self, req: GenerateRequest) -> tuple[str, List[OutlineSlide], ThemeConfig]:
if os.getenv("FAKE_LLM_RESPONSES", "0") == "1":
outline = self._fake_llm_outline(req)
Expand Down
32 changes: 32 additions & 0 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles

from .chat_service import ChatPlanner
Expand All @@ -12,6 +13,7 @@
GenerateRequest,
GenerateResponse,
ThemeApplyRequest,
ThemePresetApplyRequest,
UpdateRequest,
)
from .ppt_service import PPTService
Expand Down Expand Up @@ -78,6 +80,19 @@ def preview_ppt(path: str):
raise HTTPException(status_code=400, detail=str(e))


@app.get("/api/ppt/download")
def download_ppt(path: str):
try:
p = Path(path)
if not p.exists() or not p.is_file():
raise HTTPException(status_code=404, detail="PPT file not found")
return FileResponse(path=str(p), filename=p.name, media_type="application/vnd.openxmlformats-officedocument.presentationml.presentation")
except HTTPException:
raise
except Exception as e:
raise HTTPException(status_code=400, detail=str(e))


@app.post("/api/ppt/update")
def update_ppt(req: UpdateRequest):
try:
Expand Down Expand Up @@ -116,3 +131,20 @@ def apply_theme(req: ThemeApplyRequest):
}
except Exception as e:
raise HTTPException(status_code=400, detail=str(e))


@app.post("/api/theme/apply-preset")
def apply_theme_preset(req: ThemePresetApplyRequest):
try:
output, theme = generator_service.apply_theme_preset(req.path, req.preset, req.output_path)
return {
"output_path": output,
"theme": {
"name": theme.name,
"font_name": theme.font_name,
"title_size_pt": theme.title_size_pt,
"body_size_pt": theme.body_size_pt,
},
}
except Exception as e:
raise HTTPException(status_code=400, detail=str(e))
6 changes: 6 additions & 0 deletions backend/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ class ThemeApplyRequest(BaseModel):
output_path: Optional[str] = None


class ThemePresetApplyRequest(BaseModel):
path: str
preset: str
output_path: Optional[str] = None


class ChatResponse(BaseModel):
plan: List[EditInstruction]
output_path: str
Expand Down
6 changes: 6 additions & 0 deletions backend/app/ppt_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def apply_edits(self, path: str, edits: List[EditInstruction], output_path: str
shape = slide.shapes[edit.shape_index]
if hasattr(shape, "text"):
shape.text = edit.new_text

# Re-apply inferred theme after text edits so color/font style is not lost
# when certain PPT text boxes reset run formatting.
theme = self.infer_theme_for_presentation(prs)
self.apply_theme_to_presentation(prs, theme)

save_path = output_path or self._default_output(path, "edited")
prs.save(save_path)
return save_path
Expand Down
Loading
Loading