AI-generated mobile wallpapers
🥊

AI-generated mobile wallpapers

Tags
AI Agent
n8n
Author
notion image
💡
Replicate相比Azure openai的专业性模型更多比如flux-kontext-pro,且模型api调用方式为异步,更适合这个逻辑流场景:
  • 任务耗时太长:AI模型(特别是图像生成和高清化)的计算非常耗时,可能需要几秒到几分钟。如果采用同步模式(即API必须等任务完成后才返回结果),n8n工作流就必须一直卡在那里“等待”,直到Replicate完成任务。
  • 资源浪费和高失败率:这种长时间的等待会极大地占用n8n服务器的资源,并且非常容易因为网络波动或服务器设定的超时时间而失败。如果一个任务需要2分钟,工作流就要保持一个长达2分钟的网络连接,非常不稳定和低效
Replicate提供的是一次性免费额度,用完付费

1. Schedule Trigger (定时触发器)

  • 触发时间: 每天早上6点
  • 配置参数:
    • { "rule": { "interval": [ { "triggerAtHour": 6 } ] } }

2. AI 生成提示词 (AI Agent)

System Prompt (系统提示词)

You are an expert AI prompt engineer that specializes in generating prompts for AI image generation tools like Midjourney or Stable Diffusion. Your task is to generate high-quality, detailed prompts for images depicting peaceful and poetic Chinese landscape or nature scenes, rendered in the style of traditional Chinese ink painting and watercolor artworks. Each prompt should describe: • Majestic natural elements such as towering mountains, serene rivers or lakes, cascading waterfalls, dense forests, or graceful bamboo groves. • A tranquil body of water (e.g., a river, lake, or pond) reflecting the surrounding scenery. • Diverse flora and/or fauna (e.g., ancient trees, blooming flowers, elegant birds) that harmonize with the natural environment. • Optional traditional Chinese structures or subtle human elements (e.g., a secluded pavilion, a humble dwelling, a small boat, an arched bridge, a lone figure contemplating) integrated seamlessly into the landscape. • Optional atmospheric or seasonal elements (e.g., morning mist, ethereal clouds, falling snow, vibrant autumn foliage, delicate spring blossoms, gentle rain). The style must emphasize: • Chinese watercolor and ink wash painting (水墨丹青) • Soft, diffused lighting, delicate and flowing brush strokes, translucent washes, a rich sense of depth, and a poetic atmosphere. • A profound sense of tranquility, elegance, and natural simplicity. Generate prompts in English in a single sentence, using descriptive and visual language. Do not include camera parameters or technical terms. Example: A majestic, mist-shrouded mountain range overlooking a serene, reflective lake lined with ancient pine trees and blooming lotus flowers, rendered with delicate ink washes and soft watercolor hues in a poetic Chinese landscape painting style.

User Prompt (用户提示词)

生成10个prompt,并且每一幅不能重复,然后要为每一幅画,附上一个情绪

3. Structured Output Parser (结构化输出解析器)

JSON Schema Example

[ { "name":"鸟语花香", "prompt":"prompt1", "motion":"" }, { "name":"花香", "prompt":"prompt2", "motion":"" }, { "name":"鸟语", "prompt":"prompt3", "motion":""

4. flux-kontext-pro (图像生成API)

HTTP Request 配置

  • 方法: POST
  • URL: https://api.replicate.com/v1/models/black-forest-labs/flux-kontext-pro/predictions
  • 认证: Bearer Token (Replicate API Key)
  • Headers:
    • Prefer: wait

Request Body (JSON)

{ "input": { "prompt": "{{ $json.prompt }}", "aspect_ratio": "9:16", "output_format": "png", "safety_tolerance": 2, "prompt_upsampling": false } }

5. 将图片转成高清4k (Real-ESRGAN)

HTTP Request 配置

  • 方法: POST
  • URL: https://api.replicate.com/v1/predictions
  • 认证: Bearer Token (Replicate API Key)
  • Headers:
    • Prefer: wait

Request Body (JSON)

{ "version": "nightmareai/real-esrgan:f121d640bd286e1fdc67f9799164c1d5be36ff74576ee11c803ae5b665dd46aa", "input": { "image": "{{ $('判断是否已经完成').item.json.output }}", "scale": 2, "face_enhance": false } }

6. 创建下载路径 (Execute Command)

Shell Command

mkdir "C:\Users\wangxiaoyi\Downloads\n8n_images\{{ $('Loop Over Items').item.json.name }}_{{ $now.toFormat('yyyyMMdd_HHmmss') }}"

7. 文件保存配置

保存本地,高清图

  • 操作: write
  • 文件名: {{ $('创建下载路径').item.json.stdout }}/{{ $('Loop Over Items').item.json.name }}_hight.png

 
notion image
notion image

主要执行步骤:

  1. 定时触发 → 每天6点自动启动
  1. 生成Prompt → AI生成10个不重复的国风提示词
  1. 结构化解析 → 将AI输出转换为JSON格式
  1. 循环处理 → 遍历每个prompt
  1. 图像生成 → 调用flux-kontext-pro生成初始图像
  1. 状态检查 → 等待5秒后检查生成状态
  1. 条件判断 → 检查图像是否生成完成
  1. 路径创建 → 为每张图片创建独立保存路径
  1. 高清处理 → 使用Real-ESRGAN将图片放大至4K
  1. 文件保存 → 保存高清版本图片