5});
6
7export const generateImageHandler = async (req: Request): Promise<Response> => {
8 try {
9 const {
12 prompt,
13 negative_prompt = "",
14 image_size,
15 num_inference_steps,
16 guidance_scale,
17 seed,
18 num_images,
19 enable_safety_checker,
20 sync_mode,
28 prompt,
29 negative_prompt,
30 image_size,
31 num_inference_steps: parseInt(num_inference_steps),
32 guidance_scale: guidance_scale ? parseFloat(guidance_scale) : undefined,
33 seed: seed ? parseInt(seed) : undefined,
34 num_images: parseInt(num_images),
35 enable_safety_checker: enable_safety_checker !== undefined ? enable_safety_checker : true,
36 sync_mode: sync_mode !== undefined ? sync_mode : undefined,
40 });
41
42 const imageUrls = result.images.map((image: any) => image.url);
43
44 return new Response(JSON.stringify({ imageUrls }), {
45 headers: { "Content-Type": "application/json" },
46 status: 200,
1/** @jsxImportSource npm:hono@3/jsx */
2import { fileToDataURL } from "https://esm.town/v/stevekrouse/fileToDataURL";
3import { modifyImage } from "https://esm.town/v/stevekrouse/modifyImage";
4import { chat } from "https://esm.town/v/stevekrouse/openai";
5import { Hono } from "npm:hono@3";
50 type="file"
51 id="file"
52 accept="image/*"
53 name="file"
54 />
115 {
116 role: "user",
117 content: `What is the calorie count in this image?`,
118 },
119 {
120 role: "user",
121 content: [{
122 type: "image_url",
123 image_url: {
124 url: dataURL,
125 },
1# File to Data URL
2
3Was built for uploading base64 encoded images to GPT4v
1# uploadImage
2uploads an image to val.town just like when you paste an image into a readme
1/**
2 * upload an image to val.town
3 * @param {Blob} image - image must have image/jpeg, image/png, image/webp, image/gif or image/svg+xml content-type
4 * @returns {string} - uploaded image url
5 */
6export async function uploadImage(image: Blob): Promise<string> {
7 const fd = new FormData();
8 fd.append(
9 "file",
10 image,
11 );
12 const data = await (await fetch(await getUploadURL(), {
24}
25async function getUploadURL(): Promise<string> {
26 const data = await (await fetch("https://www.val.town/api/trpc/generateImageUploadUrl", {
27 "headers": {
28 "content-type": "application/json",
3This is a lightweight Blob Admin interface to view and debug your Blob data.
4
5
6
7Use this button to install the val:
1Migrated from folder: image_gen/formStyles
1Migrated from folder: image_gen/formLogic
1Migrated from folder: image_gen/generateImageHandler
1## 🖼️ text to image playground using [fal.ai](https://fal.ai) model apis
2
3Migrated from folder: image_gen/textToImagePlayground