avatarRouter.get("/", async(c) => {
const body = await c.req.json()
const ai = new Ai(c.env.AI)
const prompt = body.prompt
const anime = `anime style ${prompt}`
const realistic = `photo realistic style ${prompt}`
try {
const animeImg = await ai.run("@cf/bytedance/stable-diffusion-xl-lightning", { prompt: anime})
const realisticImg = await ai.run("@cf/bytedance/stable-diffusion-xl-lightning", { prompt: realistic})
console.log({
data: encodeBase64(animeImg)
// returns an empty string
})
//this works for a single image:
// return c.body(animeImg)
//this just returns empty strings
return c.json({
anime: encodeBase64(animeImg)
realistic: encodeBase64(realisticImg)
} catch (e) {
c.status(400)
return c.json({
message: "error while fetching image"
})
}
})
avatarRouter.get("/", async(c) => {
const body = await c.req.json()
const ai = new Ai(c.env.AI)
const prompt = body.prompt
const anime = `anime style ${prompt}`
const realistic = `photo realistic style ${prompt}`
try {
const animeImg = await ai.run("@cf/bytedance/stable-diffusion-xl-lightning", { prompt: anime})
const realisticImg = await ai.run("@cf/bytedance/stable-diffusion-xl-lightning", { prompt: realistic})
console.log({
data: encodeBase64(animeImg)
// returns an empty string
})
//this works for a single image:
// return c.body(animeImg)
//this just returns empty strings
return c.json({
anime: encodeBase64(animeImg)
realistic: encodeBase64(realisticImg)
} catch (e) {
c.status(400)
return c.json({
message: "error while fetching image"
})
}
})