-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit.js
34 lines (27 loc) · 964 Bytes
/
edit.js
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
import { Configuration, OpenAIApi } from "openai";
import { createReadStream, write, writeFileSync } from 'fs';
import * as dotenv from 'dotenv' // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
dotenv.config()
import express from 'express'
let apiKey = process.env.OPENAI_API_KEY
const configuration = new Configuration({
apiKey: apiKey,
});
const openai = new OpenAIApi(configuration);
const src = './coder.png'
const mask = './mask.png'
// For some reason this doesnt work. I think its the two images not being right.
const result = await openai.createImageEdit(
createReadStream(src),
createReadStream(mask),
'a programmer drawing AI art',
1,
"1024x1024",
);
const url = result.data.data[0].url;
console.log(url);
// Save Image URL to Disk
const imgResult = await fetch(url);
const blob = await imgResult.blob()
const buffer = Buffer.from( await blob.arrayBuffer() )
writeFileSync(`./img/${Date.now()}.png`, buffer);