feat: add some ai stuff
This commit is contained in:
27
src/routes/api/ai/image/[name]/+server.ts
Normal file
27
src/routes/api/ai/image/[name]/+server.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { json } from "@sveltejs/kit";
|
||||
import type { RequestHandler } from "./$types";
|
||||
import { putObject } from "$lib/helpers/s3";
|
||||
import { generateImage } from "$lib/helpers/stability";
|
||||
|
||||
|
||||
export const GET: RequestHandler = async ({ params }) => {
|
||||
|
||||
const inputName = params.name;
|
||||
|
||||
const prompt = `realistic profile portrait oil painting of a masked ${inputName}, baroque, Charles Vess, masked ball attire, Charles Vess, opulence, mystery, elegance, medium-length blond hair, darker skin`;
|
||||
const negativePrompt = "blurry, multiple persons, picture frame"
|
||||
const a = performance.now()
|
||||
const image = await generateImage(prompt, negativePrompt);
|
||||
const duration = performance.now() - a;
|
||||
|
||||
console.log({ duration })
|
||||
|
||||
const imageName = `${image.seed}-${inputName.toLowerCase().split(" ").slice(0, 5).join("-").slice(0, 25)}.png`
|
||||
|
||||
const res = await putObject(imageName, Buffer.from(image.base64, 'base64'), { "Content-Type": "image/png" });
|
||||
|
||||
return json({
|
||||
...res,
|
||||
url: `https://s3.app.max-richter.dev/silvester23/${imageName}`
|
||||
})
|
||||
}
|
25
src/routes/api/ai/image/[name]/GET.ts
Normal file
25
src/routes/api/ai/image/[name]/GET.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { json } from "@sveltejs/kit";
|
||||
import type { RequestHandler } from "./$types";
|
||||
import { putObject } from "$lib/helpers/s3";
|
||||
|
||||
|
||||
|
||||
export const GET: RequestHandler = async ({ params }) => {
|
||||
|
||||
const inputName = params.name;
|
||||
|
||||
const prompt = `upper body realistic portrait oil painting of a masked ${inputName}, Baroque, Charles Vess, masked ball attire, Charles Vess, opulence, mystery, elegance, dark long hair`;
|
||||
const negativePrompt = "blurry, multiple persons, picture frame";
|
||||
|
||||
const image = generateImage(prompt, negativePrompt);
|
||||
|
||||
const imageName = `txt2img_${image.seed}.png`;
|
||||
|
||||
const res = await putObject(imageName, Buffer.from(image.base64, 'base64'), { contentType: "image/png" });
|
||||
|
||||
return json({
|
||||
...res,
|
||||
url: `https://s3.app.max-richter.dev/silvester23/${imageName}`
|
||||
});
|
||||
};
|
||||
|
Reference in New Issue
Block a user