-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (30 loc) · 1.08 KB
/
index.js
File metadata and controls
40 lines (30 loc) · 1.08 KB
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
import Replicate from 'replicate'
import dotenv from 'dotenv'
import { writeFile } from 'node:fs/promises'
dotenv.config()
const replicate = new Replicate({
auth: process.env.REPLICATE_API_TOKEN,
userAgent: 'https://www.npmjs.com/package/create-replicate'
})
const model = 'resilientcoders/naruto-chakrax-style:94ed5f084a97ef2925add45f468cfa8471aca7f62224729ffb7613502d668d2d'
const prompt = 'a young shinobi warrior in CHAKRAX style, anime illustration, dramatic pose, detailed clothing, village background'
const input = {
prompt,
go_fast: true,
num_outputs: 1,
aspect_ratio: '1:1',
output_format: 'webp',
output_quality: 80,
}
console.log('Using model: %s', model)
console.log('Prompt: %s', prompt)
console.log('With input: %O', input)
console.log('Running...')
const output = await replicate.run(model, { input })
console.log('Done!', output)
const imageUrl = output[0]
const response = await fetch(imageUrl)
const arrayBuffer = await response.arrayBuffer()
const buffer = Buffer.from(arrayBuffer)
await writeFile('./output.png', buffer)
console.log('Image saved as output.png')