|
import { client } from "@gradio/client" |
|
|
|
import { generateSeed } from "../utils/generateSeed.mts" |
|
import { getValidNumber } from "./getValidNumber.mts" |
|
|
|
|
|
const instances: string[] = [ |
|
`${process.env.VC_SDXL_360_SPACE_API_URL_1 || ""}`, |
|
|
|
].filter(instance => instance?.length > 0) |
|
|
|
export async function generateImageSDXL360AsBase64(options: { |
|
positivePrompt: string; |
|
negativePrompt?: string; |
|
seed?: number; |
|
width?: number; |
|
height?: number; |
|
nbSteps?: number; |
|
}) { |
|
|
|
const positivePrompt = options?.positivePrompt || "" |
|
if (!positivePrompt) { |
|
throw new Error("missing prompt") |
|
} |
|
const negativePrompt = options?.negativePrompt || "" |
|
const seed = getValidNumber(options?.seed, 0, 2147483647, generateSeed()) |
|
const width = getValidNumber(options?.width, 256, 1024, 512) |
|
const height = getValidNumber(options?.height, 256, 1024, 512) |
|
const nbSteps = getValidNumber(options?.nbSteps, 5, 100, 20) |
|
console.log("SEED FOR 360:", seed) |
|
|
|
const instance = instances.shift() |
|
instances.push(instance) |
|
|
|
const positive = [ |
|
"360 view", |
|
positivePrompt, |
|
"beautiful", |
|
"intricate details", |
|
"award winning", |
|
"high resolution" |
|
].filter(word => word) |
|
.join(", ") |
|
|
|
const negative = [ |
|
negativePrompt, |
|
"watermark", |
|
"copyright", |
|
"blurry", |
|
|
|
|
|
"low quality", |
|
"ugly" |
|
].filter(word => word) |
|
.join(", ") |
|
|
|
const api = await client(instance, { |
|
hf_token: `${process.env.VC_HF_API_TOKEN}` as any |
|
}) |
|
|
|
|
|
const rawResponse = (await api.predict("/run", [ |
|
positive, |
|
negative, |
|
positive, |
|
negative, |
|
true, |
|
false, |
|
false, |
|
seed, |
|
width, |
|
height, |
|
8, |
|
8, |
|
nbSteps, |
|
nbSteps, |
|
true, |
|
])) as any |
|
|
|
return rawResponse?.data?.[0] as string |
|
} |
|
|