first commit
This commit is contained in:
128
event-publisher/scripts/generate_prompt.sh
Executable file
128
event-publisher/scripts/generate_prompt.sh
Executable file
@@ -0,0 +1,128 @@
|
||||
#!/bin/bash
|
||||
# 活动海报提示词生成器 - 使用豆包大模型生成
|
||||
|
||||
# 获取脚本所在目录的绝对路径
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SKILL_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
ASSETS_DIR="$SKILL_DIR/assets"
|
||||
|
||||
# 加载环境变量
|
||||
if [ -f "$SCRIPT_DIR/.env" ]; then
|
||||
source "$SCRIPT_DIR/.env"
|
||||
elif [ -f "$SKILL_DIR/.env" ]; then
|
||||
source "$SKILL_DIR/.env"
|
||||
fi
|
||||
|
||||
# 默认值
|
||||
DOUBAO_API_KEY="${DOUBAO_API_KEY:-db1f8b60-0ffc-473c-98da-40daa3a95df8}"
|
||||
|
||||
# 使用豆包大模型生成海报提示词
|
||||
generate_prompt_with_ai() {
|
||||
local event_content="$1"
|
||||
|
||||
echo "🤖 正在使用豆包大模型生成海报提示词..."
|
||||
|
||||
# 构建prompt,让AI根据活动内容生成适合的图片提示词
|
||||
local system_prompt="你是一个专业的活动海报设计提示词专家。根据用户提供的活动文案内容,生成适合用于AI绘画生成海报的中文提示词。要求:1. 生成的提示词要准确反映活动的主题、氛围和特点 2. 提示词应该是有画面结构,内容文字,用逗号分隔 3. 提示词要包含:活动场景、人物、物品、氛围、风格、构图和海报文字等关键词 4. 适合用于AI图像生成(豆包/Nanobanana等模型)并且文字部分用双引号包起来 5. 建议风格:电影大片感、视觉冲击力、oc渲染,光线追踪、动态模糊、景深、质感真实。请直接输出提示词,不要其他解释。"
|
||||
|
||||
# 将活动内容进行URL编码
|
||||
local user_prompt_encoded=$(python3 -c "import urllib.parse; print(urllib.parse.quote('''请根据以下活动文案内容,生成适合生成活动海报的AI绘画提示词。$event_content。请生成:1. 适合豆包API(写实风格)的提示词 2. 适合Nanobanana API(创意风格)的提示词。格式:豆包提示词:[提示词] 创意提示词:[提示词]'''))")
|
||||
|
||||
# 使用简化的请求
|
||||
local json_data="{\"model\":\"doubao-seed-2-0-pro-260215\",\"messages\":[{\"role\":\"system\",\"content\":\"$system_prompt\"},{\"role\":\"user\",\"content\":\"$user_prompt_encoded\"}],\"max_tokens\":1000}"
|
||||
|
||||
# 调用豆包API
|
||||
response=$(curl -s -X POST "https://ark.cn-beijing.volces.com/api/v3/chat/completions" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $DOUBAO_API_KEY" \
|
||||
--data-binary "$json_data")
|
||||
|
||||
# 保存原始响应用于调试
|
||||
echo "$response" > /tmp/ai_prompt_response.json
|
||||
|
||||
# 解析响应
|
||||
python3 << 'PYEOF'
|
||||
import json
|
||||
import re
|
||||
|
||||
try:
|
||||
with open('/tmp/ai_prompt_response.json', 'r') as f:
|
||||
data = json.load(f)
|
||||
|
||||
if 'error' in data:
|
||||
print('ERROR: ' + data['error'].get('message', 'Unknown error'))
|
||||
# 使用默认提示词
|
||||
print('DOUBAO_PROMPT=Chinese New Year celebration, red lanterns, traditional festival, festive atmosphere, Chinese style')
|
||||
print('NANO_PROMPT=Chinese New Year, modern design, flat style, vibrant colors, Memphis style')
|
||||
else:
|
||||
content = data['choices'][0]['message']['content']
|
||||
|
||||
# 提取豆包提示词
|
||||
doubao_match = re.search(r'豆包提示词[::]\s*([^\n]+)', content)
|
||||
if doubao_match:
|
||||
doubao_prompt = doubao_match.group(1).strip()
|
||||
else:
|
||||
parts = content.split('创意提示词')
|
||||
if len(parts) > 0:
|
||||
doubao_prompt = parts[0].replace('豆包提示词', '').replace('[提示词]', '').strip()
|
||||
else:
|
||||
doubao_prompt = content.strip()
|
||||
|
||||
# 提取创意提示词
|
||||
nano_match = re.search(r'创意提示词[::]\s*([^\n]+)', content)
|
||||
if nano_match:
|
||||
nano_prompt = nano_match.group(1).strip()
|
||||
else:
|
||||
parts = content.split('豆包提示词')
|
||||
if len(parts) > 1:
|
||||
nano_prompt = parts[1].replace('创意提示词', '').replace('[提示词]', '').strip()
|
||||
else:
|
||||
nano_prompt = ''
|
||||
|
||||
print('DOUBAO_PROMPT=' + doubao_prompt)
|
||||
print('NANO_PROMPT=' + nano_prompt)
|
||||
|
||||
except Exception as e:
|
||||
print('ERROR: ' + str(e))
|
||||
print('DOUBAO_PROMPT=Chinese New Year celebration, red lanterns, traditional festival, festive atmosphere, Chinese style')
|
||||
print('NANO_PROMPT=Chinese New Year, modern design, flat style, vibrant colors, Memphis style')
|
||||
PYEOF
|
||||
}
|
||||
|
||||
# 生成豆包提示词的3个变体
|
||||
generate_doubao_variations() {
|
||||
local base_prompt="$1"
|
||||
|
||||
# 变体1:强调氛围夜景
|
||||
local var1="$base_prompt, cinematic lighting, night scene, lanterns glowing, festive atmosphere, dramatic"
|
||||
|
||||
# 变体2:强调人物活动
|
||||
local var2="$base_prompt, happy crowd, people celebrating, lively atmosphere, traditional costumes, dynamic composition"
|
||||
|
||||
# 变体3:强调元素特写
|
||||
local var3="$base_prompt, close-up view, detailed, main subject focus, premium quality, 8k"
|
||||
|
||||
echo "$var1"
|
||||
echo "$var2"
|
||||
echo "$var3"
|
||||
}
|
||||
|
||||
# 根据参数调用对应函数
|
||||
case "$1" in
|
||||
ai)
|
||||
generate_prompt_with_ai "$2"
|
||||
;;
|
||||
variations)
|
||||
generate_doubao_variations "$2"
|
||||
;;
|
||||
*)
|
||||
echo "======================================"
|
||||
echo "🤖 AI海报提示词生成器"
|
||||
echo "======================================"
|
||||
echo ""
|
||||
echo "用法: $0 ai <活动文案内容>"
|
||||
echo ""
|
||||
echo "示例: "
|
||||
echo ' $0 ai "活动名称:春节游园会"'
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user