Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
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
import * as fal from "npm:@fal-ai/serverless-client";
fal.config({
credentials: Deno.env.get("FAL_KEY"),
});
export const generateImageHandler = async (req: Request): Promise<Response> => {
try {
const {
model,
model_name,
prompt,
negative_prompt = "",
image_size,
num_inference_steps,
guidance_scale,
seed,
num_images,
enable_safety_checker,
sync_mode,
format,
safety_checker_version
} = await req.json();
const result = await fal.run(model, {
input: {
model_name,
prompt,
negative_prompt,
image_size,
num_inference_steps: parseInt(num_inference_steps),
guidance_scale: guidance_scale ? parseFloat(guidance_scale) : undefined,
seed: seed ? parseInt(seed) : undefined,
num_images: parseInt(num_images),
enable_safety_checker: enable_safety_checker !== undefined ? enable_safety_checker : true,
sync_mode: sync_mode !== undefined ? sync_mode : undefined,
format: format || undefined,
safety_checker_version: safety_checker_version || undefined,
},
});
const imageUrls = result.images.map((image: any) => image.url);
return new Response(JSON.stringify({ imageUrls }), {
headers: { "Content-Type": "application/json" },
status: 200,
});
} catch (error) {
return new Response(JSON.stringify({ error: error.message }), {
headers: { "Content-Type": "application/json" },
status: 500,
});
}
};
iamseeley-generateimagehandler.web.val.run
June 17, 2024