360 Secure SkillHub
360 安全技能中心

PPT生成与修改

基于 python-pptx 的 Python 模块:根据结构化标题与幻灯片内容生成 .pptx,并对已有 PPT 做文本替换和图片替换,替换时保持图片位置与尺寸不变;返回新文件路径与按幻灯片分组的替换日志。图片生成默认走本地 mock 后端,其他后端仅为预留扩展点。

zicheng354-tech
zicheng354-tech
热度 42.63
最近更新 2026-05-11 17:43:19
分类:效率依赖:代码执行 / 读写文件应用场景:演示设计 / 自动化脚本 / 报告撰写

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add ppt-generate-and-edit
Metadata
name
ppt-generate-and-edit
description
Generate and edit PowerPoint files with python-pptx, including slide creation, text replacement, and image replacement while preserving layout. Use when the user asks to create PPTs from structured content, update existing PPT content, or perform country/theme replacement in slides.

PPT Generate And Edit

Purpose

Provide a reusable Python skill for AI agents to:

  • Create PPT files from structured input.
  • Update existing PPT files with text/image replacement.
  • Keep image layout stable (same position and size) during replacement.

Inputs

create_ppt

  • title: presentation title.
  • slides: array of slide objects:
    • title: slide title.
    • content: string or list of paragraphs.
    • image_prompt (optional): prompt for image generation.

update_ppt

  • ppt_path: source .pptx path.
  • replace_rules:
    • text_replace: dictionary for text replacement.
    • image_replace: dictionary for image replacement strategy.

Outputs

create_ppt

  • Returns generated .pptx file path.

update_ppt

  • Returns:
    • new_ppt_path: new .pptx output path.
    • replace_log: replacement details grouped by slide.

Module Structure

  • main.py: external API for agent calls and demo entry.
  • ppt_generator.py: PPT creation.
  • ppt_editor.py: PPT text/image replacement.
  • image_service.py: image generation abstraction (mock + extension points).
  • utils.py: logging and path helpers.

Usage

from ppt_skill.main import create_ppt, update_ppt

slides = [
    {
        "title": "Brazil Overview",
        "content": ["Brazil is the largest country in South America."],
        "image_prompt": "Brazil skyline and national flag",
    }
]

ppt_path = create_ppt(title="Brazil Briefing", slides=slides)

result = update_ppt(
    ppt_path=ppt_path,
    replace_rules={
        "text_replace": {"Brazil": "Chile"},
        "image_replace": {"__all__": {"prompt": "Chile skyline and national flag"}},
    },
)
print(result["new_ppt_path"])

Notes

  • Current generate_image() uses mock backend by default.
  • DALL·E and Stable Diffusion integration points are reserved as TODO.
  • Keep API fields stable for downstream agent compatibility.