AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He
Add MiniMax image backend support
hugohe39dd16514e22b
diff --git a/.env.example b/.env.exampleindex 1d580be0..3e3d6aa9 100644--- a/.env.example+++ b/.env.example@@ -38,6 +38,14 @@# OPENAI_MODEL=gpt-image-1# OPENAI_BASE_URL=http://127.0.0.1:3000/v1+# ─────────────────────────────────────────────────────────────+# Example: MiniMax / MiniMax 示例+# ─────────────────────────────────────────────────────────────+# IMAGE_BACKEND=minimax+# MINIMAX_API_KEY=your-minimax-key+# MINIMAX_MODEL=image-01+# MINIMAX_BASE_URL=https://api.minimaxi.com/v1/image_generation+# ─────────────────────────────────────────────────────────────# Example: Qwen / 通义生图示例# ─────────────────────────────────────────────────────────────@@ -78,6 +86,10 @@# IDEOGRAM_MODEL=ideogram-v3# IDEOGRAM_BASE_URL=https://api.ideogram.ai#+# MINIMAX_API_KEY=your-minimax-key+# MINIMAX_MODEL=image-01+# MINIMAX_BASE_URL=https://api.minimaxi.com/v1/image_generation+## SILICONFLOW_API_KEY=your-siliconflow-key# SILICONFLOW_MODEL=Qwen/Qwen-Image# SILICONFLOW_BASE_URL=https://api.siliconflow.cn/v1/images/generationsdiff --git a/skills/ppt-master/scripts/docs/image.md b/skills/ppt-master/scripts/docs/image.mdindex 459bacf3..b7810eff 100644--- a/skills/ppt-master/scripts/docs/image.md+++ b/skills/ppt-master/scripts/docs/image.md@@ -17,12 +17,13 @@ python3 scripts/image_gen.py --list-backendsSupport tiers:- Core: `gemini`, `openai`, `qwen`, `zhipu`, `volcengine`- Extended: `stability`, `bfl`, `ideogram`-- Experimental: `siliconflow`, `fal`, `replicate`+- Experimental: `minimax`, `siliconflow`, `fal`, `replicate`Backend selection:```bashpython3 scripts/image_gen.py "A cat" --backend openai+python3 scripts/image_gen.py "A cinematic portrait" --backend minimaxpython3 scripts/image_gen.py "A product launch hero image" --backend qwenpython3 scripts/image_gen.py "科技感背景图" --backend zhipupython3 scripts/image_gen.py "A product KV in cinematic style" --backend volcengine@@ -54,7 +55,7 @@ export GEMINI_MODEL=gemini-3.1-flash-image-previewCurrent process environment wins over `.env`.-Use provider-specific keys only, such as `GEMINI_API_KEY`, `OPENAI_API_KEY`, `QWEN_API_KEY`, `ZHIPU_API_KEY`, `VOLCENGINE_API_KEY`, `FAL_KEY`, or `REPLICATE_API_TOKEN`.+Use provider-specific keys only, such as `GEMINI_API_KEY`, `OPENAI_API_KEY`, `MINIMAX_API_KEY`, `QWEN_API_KEY`, `ZHIPU_API_KEY`, `VOLCENGINE_API_KEY`, `FAL_KEY`, or `REPLICATE_API_TOKEN`.`IMAGE_API_KEY`, `IMAGE_MODEL`, and `IMAGE_BASE_URL` are intentionally unsupported.diff --git a/skills/ppt-master/scripts/image_backends/backend_minimax.py b/skills/ppt-master/scripts/image_backends/backend_minimax.pynew file mode 100644index 00000000..1be33ba2--- /dev/null+++ b/skills/ppt-master/scripts/image_backends/backend_minimax.py@@ -0,0 +1,197 @@+#!/usr/bin/env python3+"""+MiniMax image generation backend.++Configuration keys:+ MINIMAX_API_KEY (required)+ MINIMAX_BASE_URL (optional)+ MINIMAX_MODEL (optional)+"""++import base64+import os+import time++import requests++from image_backends.backend_common import (+ MAX_RETRIES,+ detect_image_extension,+ http_error,+ is_rate_limit_error,+ normalize_image_size,+ require_api_key,+ resolve_output_path,+ retry_delay,+ save_image_bytes,+)+++DEFAULT_ENDPOINT = "https://api.minimaxi.com/v1/image_generation"+DEFAULT_MODEL = "image-01"++ASPECT_RATIO_SIZE_MAP = {+ "512px": {+ "1:1": (512, 512),+ "16:9": (640, 360),+ "4:3": (576, 432),+ "3:2": (624, 416),+ "2:3": (416, 624),+ "3:4": (432, 576),+ "9:16": (360, 640),+ "21:9": (672, 288),+ },+ "1K": {+ "1:1": (1024, 1024),+ "16:9": (1280, 720),+ "4:3": (1152, 864),+ "3:2": (1248, 832),+ "2:3": (832, 1248),+ "3:4": (864, 1152),+ "9:16": (720, 1280),+ "21:9": (1344, 576),+ },+ "2K": {+ "1:1": (2048, 2048),+ "16:9": (2048, 1152),+ "4:3": (2048, 1536),+ "3:2": (2048, 1368),+ "2:3": (1368, 2048),+ "3:4": (1536, 2048),+ "9:16": (1152, 2048),+ "21:9": (2048, 880),+ },+ "4K": {+ "1:1": (2048, 2048),+ "16:9": (2048, 1152),+ "4:3": (2048, 1536),+ "3:2": (2048, 1368),+ "2:3": (1368, 2048),+ "3:4": (1536, 2048),+ "9:16": (1152, 2048),+ "21:9": (2048, 880),+ },+}+++def _resolve_url(base_url: str) -> str:+ """Resolve the MiniMax image generation endpoint."""+ base = base_url.rstrip("/")+ if base.endswith("/image_generation"):+ return base+ return base + "/v1/image_generation"+++def _resolve_dimensions(aspect_ratio: str, image_size: str) -> tuple[int, int]:+ """Resolve width and height from the unified aspect_ratio/image_size pair."""+ normalized = normalize_image_size(image_size)+ dimensions = (ASPECT_RATIO_SIZE_MAP.get(normalized) or {}).get(aspect_ratio)+ if not dimensions:+ supported = sorted(ASPECT_RATIO_SIZE_MAP["1K"])+ raise ValueError(+ f"Unsupported aspect ratio '{aspect_ratio}' for MiniMax backend. "+ f"Supported: {supported}"+ )+ return dimensions+++def _extract_image_bytes(payload: dict) -> bytes | None:+ """Extract image bytes from a MiniMax response payload."""+ data = payload.get("data") or {}+ image_base64 = data.get("image_base64") or []+ if image_base64:+ return base64.b64decode(image_base64[0])+ return None+++def _generate_image(api_key: str, prompt: str, negative_prompt: str = None,+ aspect_ratio: str = "1:1", image_size: str = "1K",+ output_dir: str = None, filename: str = None,+ model: str = DEFAULT_MODEL, base_url: str = DEFAULT_ENDPOINT) -> str:+ """Generate one image with the MiniMax backend."""+ width, height = _resolve_dimensions(aspect_ratio, image_size)+ url = _resolve_url(base_url)+ final_prompt = prompt+ if negative_prompt:+ final_prompt += f"\n\nAvoid the following: {negative_prompt}"++ headers = {+ "Authorization": f"Bearer {api_key}",+ "Content-Type": "application/json",+ }+ payload = {+ "model": model,+ "prompt": final_prompt,+ "width": width,+ "height": height,+ "response_format": "base64",+ "n": 1,+ }++ print("[MiniMax Image]")+ print(f" Model: {model}")+ print(f" Prompt: {final_prompt[:120]}{'...' if len(final_prompt) > 120 else ''}")+ print(f" Aspect Ratio: {aspect_ratio}")+ print(f" Resolution: {width}x{height} (from image_size={image_size})")+ print()+ print(" [..] Generating...", end="", flush=True)+ start = time.time()+ response = requests.post(url, headers=headers, json=payload, timeout=300)+ elapsed = time.time() - start+ print(f"\n [DONE] Response received ({elapsed:.1f}s)")++ if response.status_code != 200:+ raise http_error(response, "MiniMax image generation")++ data = response.json()+ base_resp = data.get("base_resp") or {}+ if base_resp.get("status_code") not in (None, 0, "0"):+ raise RuntimeError(f"MiniMax image generation failed: {data}")++ image_bytes = _extract_image_bytes(data)+ if not image_bytes:+ raise RuntimeError(f"MiniMax response missing image data: {data}")++ ext = detect_image_extension(image_bytes) or ".jpeg"+ path = resolve_output_path(prompt, output_dir, filename, ext)+ return save_image_bytes(image_bytes, path)+++def generate(prompt: str, negative_prompt: str = None,+ aspect_ratio: str = "1:1", image_size: str = "1K",+ output_dir: str = None, filename: str = None,+ model: str = None, max_retries: int = MAX_RETRIES) -> str:+ """Generate an image with retries using the MiniMax backend."""+ api_key = require_api_key(+ "MINIMAX_API_KEY",+ message="No API key found. Set MINIMAX_API_KEY in the current environment or the project-root .env.",+ )+ base_url = os.environ.get("MINIMAX_BASE_URL") or DEFAULT_ENDPOINT+ resolved_model = model or os.environ.get("MINIMAX_MODEL") or DEFAULT_MODEL+ normalized_size = normalize_image_size(image_size)++ last_error = None+ for attempt in range(max_retries + 1):+ try:+ return _generate_image(+ api_key=api_key,+ prompt=prompt,+ negative_prompt=negative_prompt,+ aspect_ratio=aspect_ratio,+ image_size=normalized_size,+ output_dir=output_dir,+ filename=filename,+ model=resolved_model,+ base_url=base_url,+ )+ except Exception as exc:+ last_error = exc+ if attempt >= max_retries:+ break+ limited = is_rate_limit_error(exc)+ delay = retry_delay(attempt, rate_limited=limited)+ label = "Rate limit hit" if limited else f"Error: {exc}"+ print(f"\n [WARN] {label}. Retrying in {delay}s...")+ time.sleep(delay)++ raise RuntimeError(f"Failed after {max_retries + 1} attempts. Last error: {last_error}")diff --git a/skills/ppt-master/scripts/image_gen.py b/skills/ppt-master/scripts/image_gen.pyindex 0f7226ea..b964b042 100644--- a/skills/ppt-master/scripts/image_gen.py+++ b/skills/ppt-master/scripts/image_gen.py@@ -7,6 +7,7 @@ Dispatches to the appropriate backend based on explicit provider configuration.Backend selection (`IMAGE_BACKEND` in `.env` or the current process environment):IMAGE_BACKEND=gemini -> Gemini backend (google-genai SDK)IMAGE_BACKEND=openai -> OpenAI-compatible backend (openai SDK)+ IMAGE_BACKEND=minimax -> MiniMax image backendIMAGE_BACKEND=stability -> Stability AI backendIMAGE_BACKEND=bfl -> Black Forest Labs FLUX backendIMAGE_BACKEND=ideogram -> Ideogram backend@@ -45,6 +46,7 @@ IMAGE_ENV_PREFIXES = ("IMAGE_","GEMINI_","OPENAI_",+ "MINIMAX_","STABILITY_","BFL_","IDEOGRAM_",@@ -91,6 +93,14 @@ BACKEND_REGISTRY = {"key_hint": "OPENAI_API_KEY","aliases": ["openai-compatible", "openai_compatible"],},+ "minimax": {+ "module": "backend_minimax",+ "tier": "experimental",+ "label": "MiniMax Image",+ "default_model": "image-01",+ "key_hint": "MINIMAX_API_KEY",+ "aliases": ["minimaxi"],+ },"qwen": {"module": "backend_qwen","tier": "core",