Public
HTTP
Forked from substrate/template
substrate-imagegeneration.web.val.run
August 2, 2024
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
import { ComputeText, GenerateImage, Substrate, UpscaleImage } from "npm:substrate";
const substrate = new Substrate({ apiKey: Deno.env.get("SUBSTRATE_API_KEY") });
const prompt = "futuristic city of atlants";
const description = new ComputeText({
prompt:
`create a description of an image of ${prompt}. we'll use this description to generate an image. be concise and terse focusing on the subject, just return the description, no preamble.`,
max_tokens: 500,
});
description.cache_age = 60;
description.id = "description";
const image = new GenerateImage({ prompt: description.future.text });
image.cache_age = 60;
image.id = "image";
const upscale = new UpscaleImage({
prompt: description.future.text,
image_uri: image.future.image_uri,
output_resolution: 2048,
});
upscale.cache_age = 60;
upscale.id = "upscale";
const stream = substrate.stream(upscale);
export default async function render(req: Request): Promise<Response> {
if (new URL(req.url).pathname === "/robots.txt") {
return new Response("User-agent: *\nDisallow: /");
}
const renderNodeResults = (await import("https://esm.town/v/substrate/renderNodeResults")).default;
return renderNodeResults(stream);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
August 2, 2024