Spaces:
Running
Running
File size: 1,759 Bytes
f42fa3f 8ca3c3b f42fa3f 8ca3c3b f42fa3f 8ca3c3b f42fa3f 8ca3c3b f42fa3f 8ca3c3b f42fa3f |
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 |
"use server"
import { HfInference, HfInferenceEndpoint } from '@huggingface/inference'
import { filterOutBadWords } from "./censorship"
export async function getPanoramaFlux({
prompt,
width,
height,
}: {
prompt: string
width: number
height: number
}): Promise<string> {
if (!prompt) {
console.error(`cannot call the rendering API without a prompt, aborting..`)
throw new Error(`cannot call the rendering API without a prompt, aborting..`)
}
prompt = [
`HDRI panoramic view of TOK`,
filterOutBadWords(prompt),
`highly detailed`,
`intricate details`,
].join(', ')
console.log(`calling API with prompt: ${prompt}`)
const hf: HfInferenceEndpoint = new HfInference(
`${process.env.HF_API_KEY}`
)
const blob: Blob = await hf.textToImage({
model: "jbilcke-hf/flux-dev-panorama-lora-2",
inputs: prompt,
parameters: {
width,
height,
// this triggers the following exception:
// Error: __call__() got an unexpected keyword argument 'negative_prompt'
// negative_prompt: request.prompts.image.negative || '',
/**
* The number of denoising steps. More denoising steps usually lead to a higher quality image at the expense of slower inference.
*/
// num_inference_steps?: number;
/**
* Guidance scale: Higher guidance scale encourages to generate images that are closely linked to the text `prompt`, usually at the expense of lower image quality.
*/
// guidance_scale?: number;
},
})
// console.log('output from Hugging Face Inference API:', blob)
const buffer = Buffer.from(await blob.arrayBuffer())
return `data:${blob.type || 'image/jpeg'};base64,${buffer.toString('base64')}`
}
|