try to migrate to nano-banana

This commit is contained in:
songtianlun 2025-09-05 16:52:25 +08:00
parent af708b9043
commit 3c0f425e1e
6 changed files with 25 additions and 24 deletions

View File

@ -60,8 +60,8 @@ FREE_TIMES=2
REPLICATE_WEBHOOK=
# replicate 的 API token需要去你的 replicate 账号里面复制 https://replicate.com/account/api-tokens
REPLICATE_API_TOKEN=
# 生成贴纸的API版本 https://replicate.com/fofr/sticker-maker/versions ,最新的那个版本只生成一张图片了,下方这个版本是还会一次生成两张图片的
REPLICATE_API_VERSION="6443cc831f51eb01333f50b757157411d7cadb6215144cc721e3688b70004ad0"
# 生成图片的API模型 使用 Google Gemini 2.5 Flash Image
REPLICATE_API_MODEL="google/gemini-2.5-flash-image"
#--------------------------------------------------------------------------------------------------------
# cloudflare R2 config

View File

@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev --port 80",
"dev": "next dev --port 3000",
"build": "next build",
"start": "next start"
},

View File

@ -12,11 +12,11 @@ export const POST = async (req: Request) => {
const output = json.output;
console.log('callByReplicate ==>json.output==>', output);
// 使用fetch API下载文件,output是一个数组,可能多个
const len = output.length;
// 使用fetch API下载文件,output可能是字符串或数组
const urls = Array.isArray(output) ? output : [output];
const output_urls = [];
for (let i = 0; i < len; i++) {
const url = output[i];
for (let i = 0; i < urls.length; i++) {
const url = urls[i];
const currentFileContent = await fetch(url)
.then((v) => v.arrayBuffer())
.then(Buffer.from);

View File

@ -58,7 +58,7 @@ export async function POST(req: Request, res: Response) {
const origin_language = await getLanguage(textStr);
const input = await getInput(textStr, checkSubscribeStatus);
await replicateClient.predictions.create({
version: process.env.REPLICATE_API_VERSION,
model: process.env.REPLICATE_API_MODEL,
input: input,
webhook: `${process.env.REPLICATE_WEBHOOK}/api/generate/callByReplicate?uid=${uid}`,
webhook_events_filter: ["completed"],

View File

@ -5,21 +5,21 @@ export const getInput = async (textStr, checkSubscribeStatus) => {
// 翻译成英语后返回
const revised_text = await translateContent(textStr, 'en');
let width = 512;
let height = 512;
let upscale = false;
// 为 Gemini 2.5 Flash Image 构建更详细的提示词
let enhancedPrompt = `Create a high-quality sticker image: ${revised_text}.
Style: Clean, vibrant, cartoon-like sticker design with clear outlines.
Requirements: Suitable for all ages, no inappropriate content, professional quality.`;
// 如果是订阅用户,可以添加更高质量的描述
if (checkSubscribeStatus) {
width = 1024;
height = 1024
enhancedPrompt = `Create a premium high-quality sticker image: ${revised_text}.
Style: Professional cartoon/anime style with vibrant colors, detailed artwork, clean vector-like appearance.
Quality: High resolution, crisp lines, suitable for printing and digital use.
Requirements: Family-friendly content, no inappropriate material, premium design quality.`;
}
return {
steps: 20,
width: width,
height: height,
prompt: revised_text,
upscale: upscale,
upscale_steps: 2,
negative_prompt: "NSFW. No nudity or explicit content.No violence or gore.No sexual themes.Suitable for all ages.No illegal activities or substances.General audience appropriate.No offensive material.No hate speech or discrimination.Nothing disturbing or shocking.Respectful, non-exploitative content."
prompt: enhancedPrompt,
output_format: "png" // PNG format for better quality with transparency support
}
}

View File

@ -9,11 +9,12 @@ export const countSticker = async (key, addCount) => {
if (rows.length <= 0) {
// 新增
await db.query('insert into key_value(key, value) values($1,$2)', [key, addCount]);
} else {
// 更新
const origin = rows[0];
const newCount = Number(origin.value) + addCount
await db.query('update key_value set value=$1 where key=$2', [newCount, key]);
}
// 更新
const origin = rows[0];
const newCount = Number(origin.value) + addCount
await db.query('update key_value set value=$1 where key=$2', [newCount, key]);
}