# -*- coding: utf-8 -*- """Step 5b: 批量生成 22 张 PPT 配图(Agnes API, agnes-image-2.0-flash)""" import json, os, sys, time, urllib.request, urllib.error sys.stdout.reconfigure(encoding='utf-8') BASE = r"D:\workspace\cfc\ppt-output" OUT_DIR = os.path.join(BASE, "images") API_URL = "https://apihub.agnes-ai.cn/v1/images/generations" TOKEN = "sk-MyLS4uAAWAIGnJLK2UKuFrL1GotnsFX1XqJ57MZq0n208sNb" MODEL = "agnes-image-2.0-flash" os.makedirs(OUT_DIR, exist_ok=True) # ---- 22 张配图定义:slide_no, card_idx, usage, placement, prompt ---- STYLE = ("Warm, premium flat illustration with soft 3D depth, family health AI platform theme. " "Color palette: deep tech navy blue background (#0A1A2F) with warm orange (#FF8C42) accents " "and soft golden light glow. Clean, minimalist. No text, no words, no letters, no numbers, no logos. 1024x1024.") COMPOSITION = { "full-bleed": "Scene fills the entire canvas edge-to-edge with balanced composition.", "right-half": "Main subject on the left side, large empty negative space on the right side for text overlay.", "inline": "Centered composition, balanced, suitable for a small card illustration.", } IMAGES = [ (1, 0, "hero-background", "full-bleed", "A warm family scene: parents and child sitting together in golden sunlight reading a health report on a tablet, happy and relaxed."), (3, 0, "hero-background", "right-half", "A family silhouette connected to floating digital health service icons (heart, pulse line, shield) via soft glowing threads, warm orange light."), (4, 0, "inline-illustration", "inline", "Scattered fragmented data puzzle pieces with a heart shape slowly emerging from the fragments."), (5, 0, "inline-illustration", "inline", "A parent holding a smartphone managing family health tasks, floating checklists and heart icons around the phone."), (6, 2, "inline-illustration", "inline", "AI agent service architecture: a friendly robot connected to a glowing knowledge base and data streams."), (8, 0, "hero-background", "right-half", "National policy documents and rising technology trend curves converging into a bright future gateway, tech blue tones."), (10, 1, "inline-illustration", "inline", "A confused parent looking at a thick professional medical report full of complex charts they cannot understand."), (11, 0, "hero-background", "right-half", "A soaring upward growth curve over a vast open city skyline, representing a trillion-yuan market opportunity, blue and orange tones."), (13, 2, "inline-illustration", "inline", "Competitive landscape map with one distinctive position highlighted by a warm orange beacon among blue competitors."), (14, 2, "inline-illustration", "inline", "Three-sided marketplace: families, planners, and activity providers connected by a glowing triangle platform."), (15, 0, "hero-background", "right-half", "Five-element energy system: five colored energy orbs (orange, pink, indigo, green, gold) circulating in a harmonious ring, warm orange dominant."), (16, 0, "inline-illustration", "inline", "Fragmented family health data scattered across devices (phone, tablet, paper reports) with disconnected wires, pain point mood."), (17, 1, "inline-illustration", "inline", "A five-dimensional energy dashboard sandbox: circular gauges with five colored energy rings glowing softly."), (18, 1, "inline-illustration", "inline", "A family health data flywheel loop: data, analysis, plan, action, improvement rotating in a continuous glowing cycle."), (19, 0, "hero-background", "right-half", "A glowing shield protecting flowing data streams, representing technology and data moats, tech navy blue dominant."), (20, 2, "inline-illustration", "inline", "Five-element mutual generation and restriction: five colored circles connected by curved arrows in dynamic balance."), (21, 0, "inline-illustration", "inline", "An AI health advisor avatar gently connecting to family data points floating around a home."), (22, 1, "inline-illustration", "inline", "Three-party network flywheel: families, planners, partners spinning together in a growing wheel."), (23, 0, "hero-background", "right-half", "Real achievements: a certificate of growth results with an upward progress curve and warm orange and blue tones."), (24, 1, "inline-illustration", "inline", "AI extracting key metrics from a thick report: a magnifying glass over dense pages revealing bright glowing key indicators."), (25, 0, "inline-illustration", "inline", "Authoritative academic institution endorsement: a laurel wreath and seal over a rising chart, trustworthy mood."), (26, 2, "hero-background", "full-bleed", "Warm family silhouettes walking toward an ascending path of light, echoing the cover, warm orange and blue tones."), ] def generate_one(idx, slide, card, usage, placement, desc): prompt = desc + " " + COMPOSITION[placement] + " " + STYLE body = json.dumps({"model": MODEL, "prompt": prompt, "size": "1024x1024", "n": 1}).encode("utf-8") req = urllib.request.Request(API_URL, data=body, headers={ "Content-Type": "application/json", "Authorization": "Bearer " + TOKEN, }) with urllib.request.urlopen(req, timeout=120) as resp: data = json.loads(resp.read().decode("utf-8")) url = data["data"][0]["url"] fname = os.path.join(OUT_DIR, f"slide_{slide:02d}_{card}.png") urllib.request.urlretrieve(url, fname) return fname def main(): todo = [] for slide, card, usage, placement, desc in IMAGES: fname = os.path.join(OUT_DIR, f"slide_{slide:02d}_{card}.png") if os.path.exists(fname) and os.path.getsize(fname) > 1024: print(f"[skip] {fname} exists") continue todo.append((slide, card, usage, placement, desc)) print(f"[todo] {len(todo)} images to generate") for idx, (slide, card, usage, placement, desc) in enumerate(todo, 1): for attempt in range(3): try: fname = generate_one(idx, slide, card, usage, placement, desc) print(f"[{idx}/{len(todo)}] OK slide_{slide:02d}_{card}.png ({os.path.getsize(fname)} bytes)") break except Exception as e: print(f"[{idx}/{len(todo)}] slide_{slide:02d}_{card} attempt {attempt+1} failed: {e}") time.sleep(5) else: print(f"[{idx}/{len(todo)}] FAILED slide_{slide:02d}_{card} after 3 attempts") if __name__ == "__main__": main()