Auto commit: 2026-03-28 15:05:27
This commit is contained in:
@@ -1,179 +0,0 @@
|
||||
---
|
||||
name: popiskill-image-real2anime
|
||||
version: 1.0.0
|
||||
description: >
|
||||
真人照片转动漫风格,支持多种动漫风格转换
|
||||
homepage: https://llmapitest.popi.art
|
||||
user-invocable: true
|
||||
metadata:
|
||||
{
|
||||
"openclaw":
|
||||
{
|
||||
"emoji": "🎭",
|
||||
"requires": { "bins": ["python3"], "env": ["POPI_OPENAPI_KEY"] },
|
||||
"primaryEnv": "POPI_OPENAPI_KEY",
|
||||
},
|
||||
}
|
||||
---
|
||||
# 真人照片转动漫风格
|
||||
|
||||
将真人照片转换为多种动漫/艺术风格,支持16种风格选择。
|
||||
|
||||
## 环境配置指引
|
||||
|
||||
### 密钥配置
|
||||
|
||||
本 Skill 需要 Popi API 密钥才能正常工作。
|
||||
|
||||
#### 方式一:环境变量
|
||||
|
||||
**Linux / macOS:**
|
||||
|
||||
```bash
|
||||
export POPI_OPENAPI_KEY="your-api-key-here"
|
||||
```
|
||||
|
||||
如需持久化:
|
||||
|
||||
```bash
|
||||
echo 'export POPI_OPENAPI_KEY="your-api-key-here"' >> ~/.zshrc
|
||||
source ~/.zshrc
|
||||
```
|
||||
|
||||
**Windows (PowerShell):**
|
||||
|
||||
```powershell
|
||||
$env:POPI_OPENAPI_KEY = "your-api-key-here"
|
||||
```
|
||||
|
||||
#### 方式二:openclaw.json 配置(推荐)
|
||||
|
||||
在 `~/.openclaw/openclaw.json` 中添加:
|
||||
|
||||
```json
|
||||
{
|
||||
"skills": {
|
||||
"entries": {
|
||||
"popiskill-image-real2anime": {
|
||||
"enabled": true,
|
||||
"env": {
|
||||
"POPI_OPENAPI_KEY": "your-api-key-here"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 支持的风格
|
||||
|
||||
风格配置存储在 skill 目录下的 `style.json` 文件中。
|
||||
|
||||
| 风格名称 | 说明 |
|
||||
|----------|------|
|
||||
| JOJO漫画风格 | 《JOJO的奇妙冒险》漫画风格 |
|
||||
| 水彩风格 | 吉卜力水彩风格,柔和 pastel 色调 |
|
||||
| 迪士尼3D动画风格 | 迪士尼3D动画质感 |
|
||||
| 80年代复古漫画风格 | 80年代日本复古动画风格 |
|
||||
| 像素风格 | 像素化游戏风格 |
|
||||
| 日系漫画风格 | 日式动画风格 |
|
||||
| 扁平插画风格 | Flat Design 扁平设计 |
|
||||
| 黑白漫画风格 | 黑白漫画风格 |
|
||||
| 2.5D游戏风格 | 《崩坏:星穹铁道》风格化3D |
|
||||
| 饥荒风格 | 《Don't Starve》哥特卡通风格 |
|
||||
| 水墨国风风格 | 国风水墨风格 |
|
||||
| 彩铅风格 | 彩色铅笔手绘风格 |
|
||||
| 毛绒娃娃风格 | 毛绒玩具/玩偶风格 |
|
||||
| 卡通INS风格 | Q版INS风格 |
|
||||
| Q版萌趣风格 | Q版萌趣风格 |
|
||||
| 恶搞之家风格 | 《恶搞之家》动画风格 |
|
||||
| 韩系漫画风格 | 现代韩漫风格 |
|
||||
|
||||
## Agent 执行指令(必读)
|
||||
|
||||
> 本节是 Agent(AI 模型)的核心执行规范。当用户请求生成图片时,Agent 必须严格按照以下步骤自主执行,无需询问用户确认。
|
||||
|
||||
### 通用执行规则
|
||||
|
||||
1. **触发条件**:用户上传了真人照片,要求转换为动漫/艺术风格。
|
||||
2. **零交互原则**:Agent 应直接执行脚本,不要向用户询问任何确认。
|
||||
3. **模型选择**:固定使用 **nano-pro** 模型(用户指定要求)
|
||||
4. **风格选择**:从用户输入中提取风格名称,匹配 style.json 中的风格
|
||||
|
||||
---
|
||||
|
||||
### 脚本:真人照片转动漫风格
|
||||
|
||||
**适用场景**:用户上传了图片,需要转换为动漫/艺术风格
|
||||
|
||||
**图片处理步骤(必须执行)**:
|
||||
1. 首先创建临时文件夹:`mkdir -p ~/.openclaw/workspace/skills/popiskill-image-real2anime/scripts/tmp`
|
||||
2. 将用户上传的图片原封不动复制到上述 tmp 文件夹(不压缩、不修改)
|
||||
3. 使用复制后的图片路径作为 `--image-path` 参数
|
||||
|
||||
**风格处理步骤**:
|
||||
1. 从用户输入中提取风格名称(如"JOJO风格"、"水彩风格"等)
|
||||
2. 读取 skill 目录下的 `style.json` 获取对应风格的 prompt
|
||||
3. 使用该 prompt 作为 `--prompt` 参数
|
||||
|
||||
**固定参数**:
|
||||
|
||||
```
|
||||
- `--model`: nano-pro(固定)
|
||||
- `--prompt`: 从 style.json 读取对应风格的 prompt
|
||||
- `--image-path`: 用户上传图片路径
|
||||
```
|
||||
|
||||
**可变参数**:
|
||||
|
||||
| 参数 | 说明 | 默认值 | 可选值 |
|
||||
|------|------|--------|--------|
|
||||
| `--size` | 图片尺寸 | 2K | 2K, 4K, 1024x1024, 1280x1280 |
|
||||
| `--aspect-ratio` | 宽高比 | 16:9 | 16:9, 4:3, 1:1, 2:3, 3:2, 9:16 |
|
||||
|
||||
**执行命令**:
|
||||
|
||||
```bash
|
||||
python3 scripts/generate_image.py nano-pro --prompt "{从style.json读取的prompt}" --image-path "tmp/uploaded_image.png" --size 2K --aspect-ratio 16:9
|
||||
```
|
||||
|
||||
**输出示例**:
|
||||
|
||||
```json
|
||||
{
|
||||
"path": "C:/Users/xxx/.openclaw/workspace/scripts/image_20250325_161200.png",
|
||||
"model": "nano-pro",
|
||||
"size": "2K",
|
||||
"aspect_ratio": "16:9"
|
||||
}
|
||||
```
|
||||
|
||||
### 完整调用示例
|
||||
|
||||
**示例 1:JOJO漫画风格**
|
||||
```bash
|
||||
python3 scripts/generate_image.py nano-pro --prompt "将参考图中的角色转化为《JOJO的奇妙冒险》漫画风格。保持构图和核心特征" --image-path "tmp/photo.jpg" --size 2K --aspect-ratio 16:9
|
||||
```
|
||||
|
||||
**示例 2:水彩风格**
|
||||
```bash
|
||||
python3 scripts/generate_image.py nano-pro --prompt "Transform the characters in the reference image into《Ghibli》style: soft watercolor edges, gentle pastel washes, clean white background, high contrast, muted palette with selective color pops, warm yet whimsical Studio-Ghibli vibe. Masterpiece quality, intricate hand-painted detail" --image-path "tmp/photo.jpg" --size 2K --aspect-ratio 16:9
|
||||
```
|
||||
|
||||
**示例 3:迪士尼3D动画风格**
|
||||
```bash
|
||||
python3 scripts/generate_image.py nano-pro --prompt "将参考图中的角色转变为具有《迪士尼3d动画》质感的动画风格,背景变为白色背景" --image-path "tmp/photo.jpg" --size 2K --aspect-ratio 16:9
|
||||
```
|
||||
|
||||
### Agent 须避免的行为
|
||||
|
||||
- 只打印脚本路径而不执行
|
||||
- 向用户询问"是否要执行图片生成"——应直接执行
|
||||
- 忘记读取输出结果中的 `path` 并返回给用户
|
||||
- 图像生成失败时,自行编造图片路径
|
||||
- 使用非 nano-pro 模型(用户明确要求使用 nano-pro)
|
||||
- 忽略用户指定的风格,使用默认 prompt
|
||||
|
||||
## API 参考文档
|
||||
|
||||
暂无
|
||||
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 3.5 MiB |
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 9.9 MiB After Width: | Height: | Size: 9.8 MiB |
@@ -1,158 +0,0 @@
|
||||
"""Popiart AI OpenAPI 公共模块:HTTP 请求、鉴权、图片保存等工具函数"""
|
||||
|
||||
import base64
|
||||
import datetime
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import struct
|
||||
import sys
|
||||
import time
|
||||
from typing import Optional, Tuple
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
|
||||
# ========== 配置 ==========
|
||||
POPI_OPENAPI_URL = os.environ.get("POPI_OPENAPI_URL", "https://llmapitest.popi.art")
|
||||
API_KEY = os.environ.get("POPI_OPENAPI_KEY", "")
|
||||
|
||||
if not API_KEY:
|
||||
print("错误:请设置 POPI_OPENAPI_KEY 环境变量", file=sys.stderr)
|
||||
print(" export POPI_OPENAPI_KEY=sk-xxxx", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# 轮询配置
|
||||
POLL_INTERVAL = 30 # 秒
|
||||
MAX_WAIT_TIME = 600 # 秒
|
||||
# ==========================
|
||||
|
||||
|
||||
def headers(content_type="application/json"):
|
||||
h = {"Authorization": f"Bearer {API_KEY}"}
|
||||
if content_type:
|
||||
h["Content-Type"] = content_type
|
||||
return h
|
||||
|
||||
|
||||
def post_json(path: str, body: dict, timeout: int = 120) -> dict:
|
||||
url = f"{POPI_OPENAPI_URL.rstrip('/')}{path}"
|
||||
data = json.dumps(body).encode("utf-8")
|
||||
req = urllib.request.Request(url, data=data, method="POST", headers=headers())
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
||||
return json.loads(resp.read().decode("utf-8"))
|
||||
except urllib.error.HTTPError as e:
|
||||
body_text = e.read().decode("utf-8") if e.fp else ""
|
||||
print(f"❌ HTTP {e.code}: {body_text}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
except urllib.error.URLError as e:
|
||||
print(f"❌ 网络错误: {e.reason}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def get_json(path: str, timeout: int = 30) -> dict:
|
||||
url = f"{POPI_OPENAPI_URL.rstrip('/')}{path}"
|
||||
req = urllib.request.Request(url, method="GET", headers=headers(content_type=None))
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
||||
return json.loads(resp.read().decode("utf-8"))
|
||||
except urllib.error.HTTPError as e:
|
||||
body_text = e.read().decode("utf-8") if e.fp else ""
|
||||
print(f"❌ HTTP {e.code}: {body_text}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
except urllib.error.URLError as e:
|
||||
print(f"❌ 网络错误: {e.reason}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def post_multipart(path: str, fields: dict, file_fields: list = None, timeout: int = 30) -> dict:
|
||||
"""
|
||||
multipart/form-data POST。
|
||||
fields: {name: value}
|
||||
file_fields: [(field_name, filename, bytes, mime_type), ...] 或 None,支持多个同名字段
|
||||
"""
|
||||
import requests as _requests
|
||||
url = f"{POPI_OPENAPI_URL.rstrip('/')}{path}"
|
||||
# requests 支持 list of tuples 以传递同名多字段
|
||||
files = [(k, (None, v)) for k, v in fields.items()]
|
||||
for fname, filename, data, mime in (file_fields or []):
|
||||
files.append((fname, (filename, data, mime)))
|
||||
resp = _requests.post(url, headers={"Authorization": f"Bearer {API_KEY}"}, files=files, timeout=timeout)
|
||||
if resp.status_code != 200:
|
||||
print(f"❌ HTTP {resp.status_code}: {resp.text}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
return resp.json()
|
||||
|
||||
|
||||
def download_stream(path: str, output_path: str, timeout: int = 120) -> bool:
|
||||
"""流式下载文件到 output_path,返回是否成功"""
|
||||
import requests as _requests
|
||||
url = f"{POPI_OPENAPI_URL.rstrip('/')}{path}"
|
||||
resp = _requests.get(url, headers={"Authorization": f"Bearer {API_KEY}"}, stream=True, timeout=timeout)
|
||||
if resp.status_code != 200:
|
||||
print(f"❌ 下载失败 HTTP {resp.status_code}: {resp.text}", file=sys.stderr)
|
||||
return False
|
||||
total = int(resp.headers.get("content-length", 0))
|
||||
downloaded = 0
|
||||
with open(output_path, "wb") as f:
|
||||
for chunk in resp.iter_content(chunk_size=8192):
|
||||
if chunk:
|
||||
f.write(chunk)
|
||||
downloaded += len(chunk)
|
||||
if total:
|
||||
print(f"\r {downloaded/total*100:.1f}% ({downloaded}/{total} bytes)", end="")
|
||||
print()
|
||||
return True
|
||||
|
||||
|
||||
def save_base64_image(b64_data: str, prefix: str = "image") -> str:
|
||||
"""将 base64 图片数据保存为 PNG 文件,返回文件路径"""
|
||||
ts = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
filename = f"{prefix}_{ts}.png"
|
||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
generation_dir = os.path.dirname(script_dir)
|
||||
filepath = os.path.join(generation_dir,"generation", filename)
|
||||
with open(filepath, "wb") as f:
|
||||
f.write(base64.b64decode(b64_data))
|
||||
# 输出超链接格式(使用 file:// 协议)
|
||||
print(f"\n🔗 点击查看图片: file://{filepath}")
|
||||
return filepath
|
||||
|
||||
|
||||
|
||||
def extract_image_urls(markdown_text: str) -> list:
|
||||
"""从 markdown 文本中提取图片 URL"""
|
||||
return re.findall(r'!\[.*?\]\((https?://[^)]+)\)', markdown_text)
|
||||
|
||||
|
||||
def poll_video(video_id: str) -> Optional[str]:
|
||||
"""
|
||||
轮询视频生成状态,返回最终 task_id(用于下载),失败返回 None。
|
||||
网关返回结构:{ code, data: { status, progress, result_url, ... } }
|
||||
"""
|
||||
url = f"/v1/video/generations/{video_id}"
|
||||
start = time.time()
|
||||
while True:
|
||||
elapsed = int(time.time() - start)
|
||||
if elapsed > MAX_WAIT_TIME:
|
||||
print(f"⏱️ 超时:已等待 {MAX_WAIT_TIME}s")
|
||||
return None
|
||||
result = get_json(url)
|
||||
data = result.get("data") or result
|
||||
status = data.get("status", "")
|
||||
progress = data.get("progress", 0)
|
||||
print(f" [{elapsed:>4}s] status={status} progress={progress}%")
|
||||
if status == "SUCCESS":
|
||||
url_result = data.get("result_url", "")
|
||||
if url_result:
|
||||
print(f" result_url: {url_result}")
|
||||
return data.get("task_id") or video_id
|
||||
elif status == "FAILURE":
|
||||
print(f"❌ 生成失败: {data.get('fail_reason', '')}")
|
||||
return None
|
||||
print(f" 等待 {POLL_INTERVAL}s...")
|
||||
time.sleep(POLL_INTERVAL)
|
||||
|
||||
|
||||
def ts() -> str:
|
||||
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
@@ -1,245 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import sys
|
||||
import io
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||||
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
|
||||
|
||||
"""
|
||||
图像生成 skill 脚本
|
||||
用法:
|
||||
python3 generate_image.py <model> --prompt TEXT [选项]
|
||||
|
||||
模型:
|
||||
seedream SeeDream 文生图(OpenAI Images API)
|
||||
nano-pro nano-banana-pro 文生图 / 图生图(Gemini 原生 API)
|
||||
nano-2 nano-banana-2 文生图 / 图生图(Gemini 原生 API)
|
||||
sora Sora Image 文生图 / 图生图(Chat Completions API)
|
||||
不传则默认 seedream
|
||||
|
||||
图生图触发条件:
|
||||
nano-pro/nano-2 传 --image-path(本地图片路径)
|
||||
sora 传 --image-list(一张或多张在线图片 URL)
|
||||
|
||||
必填参数:
|
||||
--prompt TEXT 图像生成提示词
|
||||
|
||||
可选参数:
|
||||
--image-path PATH ... 本地图片路径列表(nano-pro / nano-2 图生图,支持多张)
|
||||
--image-list URL ... 原图 URL 列表(sora 图生图,支持多张)
|
||||
--n N 生成数量,>=1,>1 时循环调用(sora,默认 1)
|
||||
--size SIZE 图片尺寸,如 2K / 4K (默认 2K)
|
||||
--quality Q 图片质量,standard/hd(seedream,默认 hd)
|
||||
--ratio W:H 图片比例,如 2:3(sora 文生图,默认 2:3)
|
||||
--aspect-ratio W:H 宽高比,如 16:9(nano,默认 16:9)
|
||||
|
||||
示例:
|
||||
python3 generate_image.py seedream --prompt "一只猫" ✅ 完成
|
||||
python3 generate_image.py seedream --prompt "一只猫" --n 2 ✅ 完成(n未生效,只返回一张图)
|
||||
python3 generate_image.py nano-pro --prompt "一只猫" ✅ 完成
|
||||
python3 generate_image.py nano-pro --prompt "改成油画风格" --image-path ./cat.jpg ✅ 完成
|
||||
python3 generate_image.py nano-pro --prompt "融合两张图" --image-path ./a.jpg ./b.jpg ✅ 完成
|
||||
python3 generate_image.py nano-2 --prompt "一只猫" --aspect-ratio 1:1 ✅ 完成
|
||||
python3 generate_image.py nano-2 --prompt "改成油画风格" --image-path ./cat.jpg ✅ 完成
|
||||
python3 generate_image.py nano-2 --prompt "融合两张图" --image-path ./cat.jpg ./dog.jpg ✅ 完成
|
||||
python3 generate_image.py sora --prompt "一只柴犬" ✅ 完成
|
||||
python3 generate_image.py sora --prompt "一只柴犬" --n 2 ✅ 完成
|
||||
python3 generate_image.py sora --prompt "把毛色改成彩虹色" --image-list https://example.com/dog.jpg ✅ 完成
|
||||
python3 generate_image.py sora --prompt "融合两张图" --image-list https://a.com/1.jpg https://b.com/2.jpg ✅ 完成
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import base64
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
from _common_new import post_json, save_base64_image, extract_image_urls, ts, POPI_OPENAPI_URL, API_KEY
|
||||
|
||||
DEFAULT_MODEL = "seedream"
|
||||
|
||||
|
||||
# ---------- seedream ----------
|
||||
|
||||
def gen_seedream_text(prompt: str, size: str = "2K", quality: str = "hd", n: int = 1):
|
||||
print(f"模型: seedream 4.5 模式: 文生图 尺寸: {size} 质量: {quality} 数量: {n}")
|
||||
result = post_json("/v1/images/generations", {
|
||||
"model": "seedream-4-5-251128",
|
||||
"prompt": prompt,
|
||||
"size": size,
|
||||
"quality": quality,
|
||||
"n": n,
|
||||
"response_format": "url",
|
||||
}, timeout=120)
|
||||
if "data" in result:
|
||||
for item in result["data"]:
|
||||
if "url" in item:
|
||||
print(f"🔗 {item['url']}")
|
||||
return item['url']
|
||||
print(f"❌ {result}")
|
||||
return False
|
||||
|
||||
|
||||
|
||||
# ---------- gemini ----------
|
||||
|
||||
def gen_gemini_text(prompt: str, model_name: str, aspect_ratio: str = "16:9", size: str = "2K"):
|
||||
print(f"模型: {model_name} 模式: 文生图 宽高比: {aspect_ratio} 尺寸: {size}")
|
||||
result = post_json(f"/v1beta/models/{model_name}:generateContent", {
|
||||
"contents": [{"parts": [{"text": prompt}]}],
|
||||
"generationConfig": {
|
||||
"responseModalities": ["IMAGE"],
|
||||
"imageConfig": {"aspectRatio": aspect_ratio, "imageSize": size},
|
||||
},
|
||||
}, timeout=300)
|
||||
if "candidates" in result:
|
||||
try:
|
||||
b64 = result["candidates"][0]["content"]["parts"][0]["inlineData"]["data"]
|
||||
path = save_base64_image(b64, prefix="gemini")
|
||||
print(f"🖼️ 已保存: {path}")
|
||||
# return True
|
||||
return path
|
||||
except (KeyError, IndexError) as e:
|
||||
print(f"❌ 解析响应失败: {e}")
|
||||
print(f"❌ {result}")
|
||||
return False
|
||||
|
||||
|
||||
def gen_gemini_image(image_paths: list, prompt: str, model_name: str,
|
||||
aspect_ratio: str = "16:9", size: str = "2K"):
|
||||
print(f"模型: {model_name} 模式: 图生图 图片: {image_paths}")
|
||||
parts = [{"text": prompt}]
|
||||
for image_path in image_paths:
|
||||
try:
|
||||
with open(image_path, "rb") as f:
|
||||
img_b64 = base64.b64encode(f.read()).decode()
|
||||
except FileNotFoundError:
|
||||
print(f"❌ 文件不存在: {image_path}")
|
||||
return False
|
||||
mime = "image/jpeg" if image_path.lower().endswith((".jpg", ".jpeg")) else "image/png"
|
||||
parts.append({"inlineData": {"mimeType": mime, "data": img_b64}})
|
||||
result = post_json(f"/v1beta/models/{model_name}:generateContent", {
|
||||
"contents": [{"parts": parts}],
|
||||
"generationConfig": {
|
||||
"responseModalities": ["IMAGE"],
|
||||
"imageConfig": {"aspectRatio": aspect_ratio, "imageSize": size},
|
||||
},
|
||||
}, timeout=300)
|
||||
if "candidates" in result:
|
||||
try:
|
||||
b64 = result["candidates"][0]["content"]["parts"][0]["inlineData"]["data"]
|
||||
path = save_base64_image(b64, prefix="gemini_edited")
|
||||
print(f"🖼️ 已保存: {path}")
|
||||
return {"path": path}
|
||||
except (KeyError, IndexError) as e:
|
||||
print(f"❌ 解析响应失败: {e}")
|
||||
print(f"❌ {result}")
|
||||
return False
|
||||
|
||||
|
||||
# ---------- sora ----------
|
||||
|
||||
def gen_sora(prompt: str, ratio: str = "2:3", image_list: list = None, n: int = 1):
|
||||
"""
|
||||
sora_image 文生图 / 图生图统一入口。
|
||||
- image_list 为空 → 文生图,prompt 末尾附加比例标记
|
||||
- image_list 非空 → 图生图,每张图作为 image_url 传入
|
||||
- n >= 1,大于 1 时循环调用接口生成对应数量图片
|
||||
"""
|
||||
if n < 1:
|
||||
print("❌ n 必须大于等于 1")
|
||||
return False
|
||||
|
||||
image_list = image_list or []
|
||||
mode = "图生图" if image_list else "文生图"
|
||||
print(f"模型: sora_image 模式: {mode} 比例: {ratio} 数量: {n}")
|
||||
if image_list:
|
||||
print(f"原图: {image_list}")
|
||||
|
||||
def _build_messages():
|
||||
if image_list:
|
||||
content = [{"type": "text", "text": prompt}]
|
||||
for url in image_list:
|
||||
content.append({"type": "image_url", "image_url": {"url": url}})
|
||||
return [{"role": "user", "content": content}]
|
||||
else:
|
||||
p = f"{prompt}【{ratio}】" if ratio in ("2:3", "3:2", "1:1") else prompt
|
||||
return [{"role": "user", "content": p}]
|
||||
|
||||
success = 0
|
||||
for i in range(n):
|
||||
if n > 1:
|
||||
print(f"\n[{i+1}/{n}]")
|
||||
result = post_json("/v1/chat/completions", {
|
||||
"model": "sora_image",
|
||||
"messages": _build_messages(),
|
||||
}, timeout=120)
|
||||
if "choices" in result:
|
||||
content = result["choices"][0]["message"]["content"]
|
||||
urls = extract_image_urls(content)
|
||||
if urls:
|
||||
print(f"🔗 {urls[0]}")
|
||||
else:
|
||||
print(f"内容: {content[:200]}")
|
||||
success += 1
|
||||
else:
|
||||
print(f"❌ {result}")
|
||||
|
||||
return success == n
|
||||
|
||||
|
||||
# ---------- 主入口 ----------
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="图像生成 skill",
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog=__doc__,
|
||||
)
|
||||
parser.add_argument("model", nargs="?", default=DEFAULT_MODEL,
|
||||
choices=["seedream", "nano-pro", "nano-2", "sora"],
|
||||
help=f"模型别名,默认 {DEFAULT_MODEL}")
|
||||
parser.add_argument("--prompt", required=True, help="图像生成提示词(必填)")
|
||||
parser.add_argument("--image-path", nargs="+", default=[], metavar="PATH",
|
||||
help="本地图片路径列表(nano-pro / nano-2 图生图,支持多张)")
|
||||
parser.add_argument("--image-list", nargs="+", default=[], metavar="URL",
|
||||
help="原图 URL 列表(sora 图生图,支持多张)")
|
||||
parser.add_argument("--n", type=int, default=1, help="生成数量,>=1(sora,默认 1)")
|
||||
parser.add_argument("--size", default="2K", help="图片尺寸,如 2K / 4K / 1024x1024(默认 2K)")
|
||||
parser.add_argument("--quality", default="hd", help="图片质量 standard/hd(seedream,默认 hd)")
|
||||
parser.add_argument("--ratio", default="2:3", help="图片比例(sora 文生图,默认 2:3)")
|
||||
parser.add_argument("--aspect-ratio", default="16:9", help="宽高比(gemini,默认 16:9)")
|
||||
args = parser.parse_args()
|
||||
|
||||
model = args.model.lower()
|
||||
prompt = args.prompt
|
||||
|
||||
print(f"⏰ {ts()} POPI_OPENAPI_URL={POPI_OPENAPI_URL}")
|
||||
print(f"提示词: {prompt}\n")
|
||||
|
||||
ok = False
|
||||
if model == "seedream":
|
||||
ok = gen_seedream_text(prompt, size=args.size, quality=args.quality, n=args.n)
|
||||
elif model == "nano-pro":
|
||||
if args.image_path:
|
||||
ok = gen_gemini_image(args.image_path, prompt, "gemini-3-pro-image-preview",
|
||||
aspect_ratio=args.aspect_ratio, size=args.size)
|
||||
else:
|
||||
ok = gen_gemini_text(prompt, "gemini-3-pro-image-preview",
|
||||
aspect_ratio=args.aspect_ratio, size=args.size)
|
||||
elif model == "nano-2":
|
||||
if args.image_path:
|
||||
ok = gen_gemini_image(args.image_path, prompt, "gemini-3.1-flash-image-preview",
|
||||
aspect_ratio=args.aspect_ratio, size=args.size)
|
||||
else:
|
||||
ok = gen_gemini_text(prompt, "gemini-3.1-flash-image-preview",
|
||||
aspect_ratio=args.aspect_ratio, size=args.size)
|
||||
elif model == "sora":
|
||||
ok = gen_sora(prompt, ratio=args.ratio, image_list=args.image_list, n=args.n)
|
||||
|
||||
print(f"\n{'✅ 完成' if ok else '❌ 失败'} {ts()}")
|
||||
sys.exit(0 if ok else 1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,70 +0,0 @@
|
||||
{
|
||||
"jojo漫画风格": {
|
||||
"prompt": "将参考图中的角色转化为《JOJO的奇妙冒险》漫画风格。保持构图和核心特征",
|
||||
"base_img": ""
|
||||
},
|
||||
"水彩风格": {
|
||||
"prompt": "Transform the characters in the reference image into《Ghibli》style: soft watercolor edges, gentle pastel washes, clean white background, high contrast, muted palette with selective color pops, warm yet whimsical Studio-Ghibli vibe. Masterpiece quality, intricate hand-painted detail",
|
||||
"base_img": ""
|
||||
},
|
||||
"迪士尼3D动画风格": {
|
||||
"prompt": "将参考图中的角色转变为具有《迪士尼3d动画》质感的动画风格,背景变为白色背景",
|
||||
"base_img": ""
|
||||
},
|
||||
"80年代复古漫画风格": {
|
||||
"prompt": "将参考图中的角色转变为具有《80s Anime》质感的日本动画风格。背景变为白色背景",
|
||||
"base_img": ""
|
||||
},
|
||||
"像素风格": {
|
||||
"prompt": "将参考图中的角色转变为像素风格,背景变为白色背景",
|
||||
"base_img": ""
|
||||
},
|
||||
"日系漫画风格": {
|
||||
"prompt": "将参考图中的角色转变为动画风格,背景变为白色背景",
|
||||
"base_img": ""
|
||||
},
|
||||
"扁平插画风格": {
|
||||
"prompt": "将参考图中的角色转变为Flat Design(扁平设计)风格,背景变为白色背景",
|
||||
"base_img": ""
|
||||
},
|
||||
"黑白漫画风格": {
|
||||
"prompt": "将参考图中的角色转变为黑白漫画风格,背景变为白色背景",
|
||||
"base_img": ""
|
||||
},
|
||||
"2.5D游戏风格": {
|
||||
"prompt": "将参考图中的角色转变为具有《崩坏:星穹铁道》质感的 Stylized 3D 风格。",
|
||||
"base_img": ""
|
||||
},
|
||||
"饥荒风格": {
|
||||
"prompt": "Transform the characters in the reference image into gothic cartoon style, in the signature “Don't Starve” game aesthetic: shaky dark-ink outlines, textured paper background, The character's pupils constricted.high contrast, muted palette with selective color pops, whimsical yet macabre vibe. Masterpiece quality, intricate details.",
|
||||
"base_img": ""
|
||||
},
|
||||
"水墨国风风格": {
|
||||
"prompt": "Transform the characters in the reference image into Guofeng ink style: flowing xuan-paper brush lines, wet-on-wet ink gradations, blank-leave negative space, high contrast, muted palette with selective color pops, serene yet mysterious Eastern vibe. Masterpiece quality, intricate ink details.",
|
||||
"base_img": ""
|
||||
},
|
||||
"彩铅风格": {
|
||||
"prompt": "According to the reference image, transform this character into a colored pencil style: delicate paper fiber texture, soft overlapping colored pencil strokes, slightly rough edges of the blank spaces, high contrast, low-saturation main colors with partial contrasting colors, creating a warm yet slightly naive fairy-tale atmosphere.Masterpiece quality, intricate layering details.",
|
||||
"base_img": ""
|
||||
},
|
||||
"毛绒娃娃风格": {
|
||||
"prompt": "Convert the character in the reference image into《Plush Toy》style: soft velour seams, plush-fabric pile texture, matte stitch outlines, clean white background, high contrast, muted palette with selective color pops, cuddly yet whimsical stuffed-animal vibe. Masterpiece quality, intricate embroidery details. Adopt the above look for the character in the provided reference image.背景变为白色背景",
|
||||
"base_img": ""
|
||||
},
|
||||
"卡通INS风格": {
|
||||
"prompt": "A将参考图中的角色转变为具有Q版风格。保持参考图1的构图和核心特征,背景变为白色,风格参考图2(Q版风格)",
|
||||
"base_img": "https://popitest-public-1313913486.cos.ap-guangzhou.myqcloud.com/media/2026/0209/2468.png"
|
||||
},
|
||||
"Q版萌趣风格": {
|
||||
"prompt": "A将参考图中的角色转变为具有Q版风格。保持参考图1的构图和核心特征,背景变为白色,风格参考图2(Q版风格)",
|
||||
"base_img": "https://popitest-public-1313913486.cos.ap-guangzhou.myqcloud.com/media/2026/0209/2469.png"
|
||||
},
|
||||
"恶搞之家风格": {
|
||||
"prompt": "将参考图中的角色转变为具有《恶搞之家》动画风格。保持参考图1的构图和核心特征,背景变为白色,风格参考图2(《恶搞之家》动画风格)",
|
||||
"base_img": "https://popitest-public-1313913486.cos.ap-guangzhou.myqcloud.com/media/2026/0209/2470.jpg"
|
||||
},
|
||||
"韩系漫画风格": {
|
||||
"prompt": "将参考图中的角色转变为具有现代韩漫风格。保持参考图1的构图和核心特征,背景变为白色,风格参考图2(现代韩漫风格)",
|
||||
"base_img": "https://popitest-public-1313913486.cos.ap-guangzhou.myqcloud.com/media/2026/0209/2478.jpg"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user