Skip to content

Commit 3f03b1c

Browse files
Updated Fun with AI to Dall-e 3
1 parent 1961cb5 commit 3f03b1c

8 files changed

Lines changed: 5208 additions & 28 deletions

File tree

-12.2 KB
Binary file not shown.

Misc/Dall-E/grasshopper/dalle-api.ghx

Lines changed: 5113 additions & 0 deletions
Large diffs are not rendered by default.

Misc/Dall-E/nodejs/dalle-generate-args.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ const commandLineArgs = require('command-line-args');
77
const optionDefinitions = [
88
{ name: 'prompt', alias: 'p', type: String, defaultValue: "an isometric view of a miniature city, tilt shift, bokeh, voxel, vray render, high detail" },
99
{ name: 'number', alias: 'n', type: Number, defaultValue: 1 },
10-
{ name: 'size', alias: 's', type: Number, defaultValue: 256 },
10+
{ name: 'size', alias: 's', type: String, defaultValue: "1024x1024" },
11+
{ name: 'model', alias: 'm', type: String, defaultValue: "dall-e-2" },
12+
{ name: 'quality', alias: 'q', type: String, defaultValue: "standard" },
13+
{ name: 'style', alias: 'S', type: String, defaultValue: "natural" },
1114
];
1215

1316
const options = commandLineArgs(optionDefinitions);
@@ -24,7 +27,10 @@ const predict = async function () {
2427
const response = await openai.createImage({
2528
prompt: options.prompt,
2629
n: options.number,
27-
size: `${options.size}x${options.size}`,
30+
size: options.size,
31+
model: options.model,
32+
quality: options.quality,
33+
style: options.style,
2834
response_format: 'b64_json',
2935
});
3036

Misc/Dall-E/nodejs/dalle-generate-no-module.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ const commandLineArgs = require('command-line-args');
66
const optionDefinitions = [
77
{ name: 'prompt', alias: 'p', type: String, defaultValue: "an isometric view of a miniature city, tilt shift, bokeh, voxel, vray render, high detail" },
88
{ name: 'number', alias: 'n', type: Number, defaultValue: 1 },
9-
{ name: 'size', alias: 's', type: Number, defaultValue: 256 },
9+
{ name: 'size', alias: 's', type: String, defaultValue: "1024x1024" },
10+
{ name: 'model', alias: 'm', type: String, defaultValue: "dall-e-2" },
11+
{ name: 'quality', alias: 'q', type: String, defaultValue: "standard" },
12+
{ name: 'style', alias: 'S', type: String, defaultValue: "natural" },
1013
];
1114

1215
const options = commandLineArgs(optionDefinitions);
@@ -17,7 +20,10 @@ const dalleEndpoint = 'https://api.openai.com/v1/images/generations';
1720
const reqBody = {
1821
prompt: options.prompt,
1922
n: options.number,
20-
size: `${options.size}x${options.size}`,
23+
size: options.size,
24+
model: options.model,
25+
quality: options.quality,
26+
style: options.style,
2127
response_format: 'b64_json',
2228
};
2329

Misc/Dall-E/python/dalle-generate-no-module.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
# This example is part of the `Fun with Dall-E` video tutorial series
22
# at ParametricCamp: https://www.youtube.com/playlist?list=PLx3k0RGeXZ_zs3az0Z2BnpTIPH2lxQfFX
3+
import argparse
4+
import base64
5+
import json
36
import os
7+
import time
8+
49
import requests
5-
import json
6-
import base64, time
7-
import argparse
810

911
# Initiate the parser
1012
parser = argparse.ArgumentParser()
1113
parser.add_argument("-p", "--prompt", help="Text to image prompt:", default='an isometric view of a miniature city, tilt shift, bokeh, voxel, vray render, high detail')
1214
parser.add_argument("-n", "--number", help="Number of images generated", default=1)
13-
parser.add_argument("-s", "--size", help="Image size: 256, 512 or 1024", default=256)
15+
parser.add_argument("-s", "--size", help="The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024 for dall-e-2. Must be one of 1024x1024, 1792x1024, or 1024x1792 for dall-e-3 models.", default="1024x1024")
16+
parser.add_argument("-m", "--model", help="Model generator: 'dalle-e-3' or 'dall-e-2' (default) ", default='dall-e-2')
17+
parser.add_argument("-q", "--quality", help="Quality (only supported for 'dall-e-3'): 'standard' (default) or 'hd'", default='standard')
18+
parser.add_argument("-S", "--style", help="The style of the generated images. Must be one of vivid or natural. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images. This param is only supported for dall-e-3.", default='natural')
19+
1420

1521
# Read arguments from the command line
1622
args = parser.parse_args()
@@ -26,7 +32,10 @@
2632
reqBody = {
2733
"prompt": args.prompt,
2834
"n": int(args.number),
29-
"size": f'{args.size}x{args.size}',
35+
"size": args.size,
36+
"model": args.model,
37+
"quality": args.quality,
38+
"style": args.style,
3039
"response_format": "b64_json"
3140
}
3241

Misc/Dall-E/python/dalle-generate.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
# This example is part of the `Fun with Dall-E` video tutorial series
22
# at ParametricCamp: https://www.youtube.com/playlist?list=PLx3k0RGeXZ_zs3az0Z2BnpTIPH2lxQfFX
3-
import os
4-
import openai
3+
import argparse
54
import base64
5+
import os
66
import time
7-
import argparse
7+
8+
import openai
89

910
# Initiate the parser
1011
parser = argparse.ArgumentParser()
1112
parser.add_argument("-p", "--prompt", help="Text to image prompt:", default='an isometric view of a miniature city, tilt shift, bokeh, voxel, vray render, high detail')
1213
parser.add_argument("-n", "--number", help="Number of images generated", default=1)
13-
parser.add_argument("-s", "--size", help="Image size: 256, 512 or 1024", default=256)
14+
parser.add_argument("-s", "--size", help="The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024 for dall-e-2. Must be one of 1024x1024, 1792x1024, or 1024x1792 for dall-e-3 models.", default="1024x1024")
15+
parser.add_argument("-m", "--model", help="Model generator: 'dalle-e-3' or 'dall-e-2' (default) ", default='dall-e-2')
16+
parser.add_argument("-q", "--quality", help="Quality (only supported for 'dall-e-3'): 'standard' (default) or 'hd'", default='standard')
17+
parser.add_argument("-S", "--style", help="The style of the generated images. Must be one of vivid or natural. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images. This param is only supported for dall-e-3.", default='natural')
18+
1419

1520
# Read arguments from the command line
1621
args = parser.parse_args()
@@ -20,7 +25,10 @@
2025
res = openai.Image.create(
2126
prompt=args.prompt,
2227
n=int(args.number),
23-
size=f'{args.size}x{args.size}',
28+
size=args.size,
29+
model=args.model,
30+
quality=args.quality,
31+
style=args.style,
2432
response_format="b64_json"
2533
)
2634

Misc/Dall-E/web-dalle/index.html

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,56 @@
2323
<textarea id="text-prompt" rows="4" cols="52">An isometric view of a miniature city, tilt shift, bokeh, voxel, vray render, high detail</textarea>
2424
</div>
2525

26+
<div>
27+
Image model:
28+
<select name="model" class="dropdown" id="model-selector">
29+
<option value="dall-e-2">dall-e-2</option>
30+
<option value="dall-e-3" selected>dall-e-3</option>
31+
</select>
32+
</div>
33+
2634
<div>
2735
Image count (1-4): <input id="image-count" value="1">
2836
</div>
2937

3038
<div>
3139
Image size:
3240
</div>
33-
3441
<div>
35-
<input type="radio" id="radio-256" name="image-size" value="256" checked>
36-
<label for="256">256</label>
42+
<input type="radio" id="radio-256" name="image-size" value="256x256">
43+
<label for="256x256">256x256</label>
44+
</div>
45+
<div>
46+
<input type="radio" id="radio-512" name="image-size" value="512x512">
47+
<label for="512x512">512x512</label>
48+
</div>
49+
<div>
50+
<input type="radio" id="radio-1024" name="image-size" value="1024x1024" checked>
51+
<label for="1024x1024">1024x1024</label>
52+
</div>
53+
<div>
54+
<input type="radio" id="radio-1024x1792" name="image-size" value="1024x1792">
55+
<label for="1024x1792">1024x1792</label>
3756
</div>
3857
<div>
39-
<input type="radio" id="radio-512" name="image-size" value="512">
40-
<label for="512">512</label>
58+
<input type="radio" id="radio-1792x1024" name="image-size" value="1792x1024">
59+
<label for="1792x1024">1792x1024</label>
4160
</div>
61+
62+
<div>
63+
Image quality:
64+
<select name="quality" class="dropdown" id="quality-selector">
65+
<option value="standard">standard</option>
66+
<option value="hd" selected>hd</option>
67+
</select>
68+
</div>
69+
4270
<div>
43-
<input type="radio" id="radio-1024" name="image-size" value="1024">
44-
<label for="1024">1024</label>
71+
Image style:
72+
<select name="style" class="dropdown" id="style-selector">
73+
<option value="natural">natural</option>
74+
<option value="vivid" selected>vivid</option>
75+
</select>
4576
</div>
4677

4778
<div>

Misc/Dall-E/web-dalle/js/script.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@ reqButton.onclick = function () {
1919
const key = document.getElementById('api-key').value;
2020
const prompt = document.getElementById('text-prompt').value;
2121
const count = Number(document.getElementById('image-count').value);
22-
const radios = document.getElementsByName('image-size');
22+
const sizeRadios = document.getElementsByName('image-size');
2323
let size;
24-
for (let i = 0; i < radios.length; i++) {
25-
if (radios[i].checked) {
26-
size = Number(radios[i].value);
24+
for (let i = 0; i < sizeRadios.length; i++) {
25+
if (sizeRadios[i].checked) {
26+
size = sizeRadios[i].value;
2727
break;
2828
}
2929
}
3030

31+
const model = document.getElementById('model-selector').value;
32+
const quality = document.getElementById('quality-selector').value;
33+
const style = document.getElementById('style-selector').value;
34+
3135
// These can be handled by the server
3236
// // Some validity checks.
3337
// if (key.length == 0)
@@ -61,7 +65,10 @@ reqButton.onclick = function () {
6165
const reqBody = {
6266
prompt: prompt,
6367
n: count,
64-
size: size + "x" + size,
68+
size: size,
69+
model: model,
70+
quality: quality,
71+
style: style,
6572
response_format: 'url',
6673
};
6774

@@ -95,7 +102,7 @@ reqButton.onclick = function () {
95102
*/
96103
function addImages(jsonData, prompt) {
97104

98-
// console.log(jsonData);
105+
console.log(jsonData);
99106
reqButton.disabled = false;
100107

101108
// Handle a possible error response from the API
@@ -112,7 +119,7 @@ function addImages(jsonData, prompt) {
112119
let imgData = jsonData.data[i];
113120
let img = document.createElement('img');
114121
img.src = imgData.url;
115-
img.alt = prompt;
122+
img.alt = `prompt: ${prompt}, revised_prompt: ${imgData.revised_prompt}`;
116123
container.prepend(img);
117124
}
118125

0 commit comments

Comments
 (0)