Spaces:
Sleeping
Sleeping
File size: 1,726 Bytes
0d218b1 4348dc5 0d218b1 db70195 0d218b1 db70195 0d218b1 db70195 0d218b1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
import { generateSeed } from "@aitube/clap"
import { sleep } from "@/lib/utils/sleep"
import { newRender, getRender } from "@/app/api/providers/videochain/renderWithVideoChain"
import { getNegativePrompt, getPositivePrompt } from "@/app/api/utils/imagePrompts"
export async function generateImageID({
prompt,
// negativePrompt,
turbo = false,
seed,
}: {
prompt: string
// negativePrompt?: string
turbo?: boolean
seed?: number
}) {
// those can be constants for a face ID
// also we want something a bit portrait-ish
// but this risk creating a lot of variability in poses
// so perhaps we should use a controlnet to condition the face scale and position,
// to make sure it is uniform in size across all models
const width = 1024
const height = 768
// console.log("calling await newRender")
prompt = getPositivePrompt(prompt)
const negativePrompt = getNegativePrompt()
let render = await newRender({
prompt,
negativePrompt,
nbFrames: 1,
nbFPS: 1,
// note: for the model ID we might want to maximize things here,
// and maybe not use the "turbo" - but I'm not sure
width,
height,
nbSteps: turbo ? 8 : 25,
turbo,
shouldRenewCache: true,
seed: seed || generateSeed()
})
let attempts = 10
while (attempts-- > 0) {
if (render.status === "completed") {
return render.assetUrl
}
if (render.status === "error") {
console.error(render.error)
throw new Error(`failed to generate the image ${render.error}`)
}
await sleep(2000) // minimum wait time
// console.log("asking getRender")
render = await getRender(render.renderId)
}
throw new Error(`failed to generate the image`)
}
|