-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (examples): show generate-image result preview in terminal (#4728)
- Loading branch information
Showing
20 changed files
with
1,526 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
output | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
import { deepinfra } from '@ai-sdk/deepinfra'; | ||
import { experimental_generateImage as generateImage } from 'ai'; | ||
import { presentImages } from '../lib/present-image'; | ||
import 'dotenv/config'; | ||
import fs from 'fs'; | ||
|
||
async function main() { | ||
const result = await generateImage({ | ||
model: deepinfra.image('black-forest-labs/FLUX-1-schnell'), | ||
prompt: 'A resplendent quetzal mid flight amidst raindrops', | ||
}); | ||
|
||
for (const [index, image] of result.images.entries()) { | ||
const filename = `image-${Date.now()}-${index}.png`; | ||
fs.writeFileSync(filename, image.uint8Array); | ||
console.log(`Image saved to ${filename}`); | ||
} | ||
await presentImages(result.images); | ||
} | ||
|
||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
import { fal } from '@ai-sdk/fal'; | ||
import { experimental_generateImage as generateImage } from 'ai'; | ||
import { presentImages } from '../lib/present-image'; | ||
import 'dotenv/config'; | ||
import fs from 'node:fs'; | ||
|
||
async function main() { | ||
const { image } = await generateImage({ | ||
const { images } = await generateImage({ | ||
model: fal.image('fal-ai/flux/schnell'), | ||
prompt: 'A cat wearing a intricate robe', | ||
prompt: | ||
'A cat wearing an intricate robe while gesticulating wildly, in the style of 80s pop art', | ||
}); | ||
|
||
const filename = `image-${Date.now()}.png`; | ||
fs.writeFileSync(filename, image.uint8Array); | ||
console.log(`Image saved to ${filename}`); | ||
await presentImages(images); | ||
} | ||
|
||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
import { openai } from '@ai-sdk/openai'; | ||
import { experimental_generateImage as generateImage } from 'ai'; | ||
import { presentImages } from '../lib/present-image'; | ||
import 'dotenv/config'; | ||
import fs from 'fs'; | ||
|
||
async function main() { | ||
const { image } = await generateImage({ | ||
model: openai.image('dall-e-3'), | ||
prompt: 'Santa Claus driving a Cadillac', | ||
}); | ||
|
||
const filename = `image-${Date.now()}.png`; | ||
fs.writeFileSync(filename, image.uint8Array); | ||
console.log(`Image saved to ${filename}`); | ||
await presentImages([image]); | ||
} | ||
|
||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
import { replicate } from '@ai-sdk/replicate'; | ||
import { experimental_generateImage as generateImage } from 'ai'; | ||
import { presentImages } from '../lib/present-image'; | ||
import 'dotenv/config'; | ||
import fs from 'node:fs'; | ||
|
||
async function main() { | ||
const { image } = await generateImage({ | ||
model: replicate.image('black-forest-labs/flux-schnell'), | ||
prompt: 'The Loch Ness Monster getting a manicure', | ||
}); | ||
|
||
const filename = `image-${Date.now()}.png`; | ||
fs.writeFileSync(filename, image.uint8Array); | ||
console.log(`Image saved to ${filename}`); | ||
await presentImages([image]); | ||
} | ||
|
||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.