replicate_starterApp.tsx20 matches
3import React from "https://esm.sh/react@18.2.0";
45function ImageGenerator() {
6const [prompt, setPrompt] = React.useState("");
7const [images, setImages] = React.useState<any>([]);
8const [loading, setLoading] = React.useState(false);
936}, []);
3738const generateImage = async () => {
39try {
40setLoading(true);
41const response = await fetch("/generate-image", {
42method: "POST",
43headers: {
52}
5354setImages(prevImages => [{
55url: data.imageUrl,
56prompt,
57timestamp: new Date().toLocaleTimeString(),
58}, ...prevImages]);
59} catch (error) {
60alert("An error occurred while generating the image: " + error.message);
61console.error("Error generating image:", error);
62} finally {
63setLoading(false);
68e.preventDefault();
69if (!loading && prompt) {
70generateImage();
7172// Set a new random prompt after submission, unless user has entered a custom prompt
80<div className="max-w-3xl mx-auto px-4 py-8">
81<h1 className="text-3xl font-bold text-center text-gray-800 mb-8">
82Flux Image Generator
83</h1>
8485<p className="text-center text-gray-600 mb-8">
86Generate images with{" "}
87<a
88href="https://replicate.com/black-forest-labs/flux-schnell"
112value={prompt}
113onChange={(e) => setPrompt(e.target.value)}
114placeholder="Enter your image prompt"
115className="flex-1 max-w-lg px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-orange-500 focus:border-transparent"
116/>
120className="px-6 py-2 bg-orange-600 text-white rounded-md hover:bg-orange-700 disabled:bg-gray-400 disabled:cursor-not-allowed transition-colors"
121>
122{loading ? "Generating..." : "Generate Image"}
123</button>
124</form>
125<div className="space-y-8">
126{images.map((image, index) => (
127<div key={image.timestamp} className="bg-white p-4 rounded-md shadow-lg">
128<img
129src={image.url}
130alt={image.prompt}
131className="rounded-md w-full mb-2"
132/>
133<div>
134<p className="text-gray-700 font-medium text-center">"{image.prompt}"</p>
135</div>
136</div>
142143const root = createRoot(document.getElementById("root"));
144root.render(<ImageGenerator />);
replicate_starterindex.html1 match
4<meta charset="UTF-8">
5<meta name="viewport" content="width=device-width, initial-scale=1.0">
6<title>Flux Image Generator</title>
7<script src="https://cdn.tailwindcss.com"></script>
8</head>
replicate_starterApp.tsx20 matches
3import React from "https://esm.sh/react@18.2.0";
45function ImageGenerator() {
6const [prompt, setPrompt] = React.useState("");
7const [images, setImages] = React.useState<any>([]);
8const [loading, setLoading] = React.useState(false);
936}, []);
3738const generateImage = async () => {
39try {
40setLoading(true);
41const response = await fetch("/generate-image", {
42method: "POST",
43headers: {
52}
5354setImages(prevImages => [{
55url: data.imageUrl,
56prompt,
57timestamp: new Date().toLocaleTimeString(),
58}, ...prevImages]);
59} catch (error) {
60alert("An error occurred while generating the image: " + error.message);
61console.error("Error generating image:", error);
62} finally {
63setLoading(false);
68e.preventDefault();
69if (!loading && prompt) {
70generateImage();
7172// Set a new random prompt after submission, unless user has entered a custom prompt
80<div className="max-w-3xl mx-auto px-4 py-8">
81<h1 className="text-3xl font-bold text-center text-gray-800 mb-8">
82Flux Image Generator
83</h1>
8485<p className="text-center text-gray-600 mb-8">
86Generate images with{" "}
87<a
88href="https://replicate.com/black-forest-labs/flux-schnell"
112value={prompt}
113onChange={(e) => setPrompt(e.target.value)}
114placeholder="Enter your image prompt"
115className="flex-1 max-w-lg px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-orange-500 focus:border-transparent"
116/>
120className="px-6 py-2 bg-orange-600 text-white rounded-md hover:bg-orange-700 disabled:bg-gray-400 disabled:cursor-not-allowed transition-colors"
121>
122{loading ? "Generating..." : "Generate Image"}
123</button>
124</form>
125<div className="space-y-8">
126{images.map((image, index) => (
127<div key={image.timestamp} className="bg-white p-4 rounded-md shadow-lg">
128<img
129src={image.url}
130alt={image.prompt}
131className="rounded-md w-full mb-2"
132/>
133<div>
134<p className="text-gray-700 font-medium text-center">"{image.prompt}"</p>
135</div>
136</div>
142143const root = createRoot(document.getElementById("root"));
144root.render(<ImageGenerator />);
digest_migratedmain.tsx1 match
257<meta charset="UTF-8"/>
258<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
259<link rel="icon" type="image/png" href="data:image/png;base64,${favicon}">
260<style>${style}</style>
261<title>Bolivia Digest</title>
61});
62} else {
63// Handle other image types with CanvasKit
64const image = CanvasKit.MakeImageFromEncoded(new Uint8Array(buffer));
65if (image) {
66try {
67width = image.width();
68height = image.height();
69faviconCandidates.push({ url: u, buffer, width, height });
70} finally {
71image.delete();
72}
73}
74}
75} catch (e) {
76console.warn(`Failed to decode image from ${u}:`, e);
77}
78}
redditAlertREADME.md3 matches
13## Example
14This val tracks mentions of "Val Town" and related terms on Reddit, filtering results from the last 7 days and sending alerts to a Discord webhook.
15
1617---
21### 1. Fork this Val
22To start using this template, fork this val by clicking the fork button at the top-right corner of the page.
23
2425---
26### 2. View Source Code
27<em>The `CODE` box shows you the the full source code of this val, you may need to scroll down to see it.</em>
28
2930---
sqliteExplorerAppREADME.md1 match
3View and interact with your Val Town SQLite data. It's based off Steve's excellent [SQLite Admin](https://www.val.town/v/stevekrouse/sqlite_admin?v=46) val, adding the ability to run SQLite queries directly in the interface. This new version has a revised UI and that's heavily inspired by [LibSQL Studio](https://github.com/invisal/libsql-studio) by [invisal](https://github.com/invisal). This is now more an SPA, with tables, queries and results showing up on the same page.
45
67## Install
replicate_starterREADME.md3 matches
3Ported from https://github.com/replicate/getting-started-cloudflare-workers
45This is a template for a simple web app using [Hono](https://honojs.dev/), and [Replicate](https://replicate.com/) to generate images using [Flux Schnell](https://replicate.com/black-forest-labs/flux-schnell), a fast and high-quality open-source image generation model.
67
89## Stack
11- [Hono](https://honojs.dev/) is a minimalist web framework for building serverless applications. It's built and maintained by Cloudflare.
12- [Replicate](https://replicate.com/) is a platform for building and running machine learning models.
13- [Flux Schnell](https://replicate.com/black-forest-labs/flux-schnell) is a fast and high-quality open-source image generation model, made by the original creators of Stable Diffusion.
replicate_starterindex.ts7 matches
11app.get("/frontend/**/*", c => serveFile(c.req.path, import.meta.url));
1213// Generate image
14app.post("/generate-image", async (c) => {
15try {
16const { prompt } = await c.req.json();
21input: {
22prompt,
23image_format: "webp",
24},
25}) as { url: string }[] | { url: string };
2627// Some image models return an array of output files, others just a single file.
28const imageUrl = Array.isArray(output) ? output[0].url() : output.url();
2930console.log({ imageUrl });
3132return c.json({ imageUrl });
33} catch (error) {
34console.error(error);
replicate_starterindex.html1 match
4<meta charset="UTF-8">
5<meta name="viewport" content="width=device-width, initial-scale=1.0">
6<title>Flux Image Generator</title>
7<script src="https://cdn.tailwindcss.com"></script>
8</head>