-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ai enhance update, better scaler, more tests. better defaults
- Loading branch information
matatonic
committed
Mar 28, 2024
1 parent
a6cab22
commit 3b98994
Showing
31 changed files
with
136 additions
and
68 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.env | ||
test-*/ | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
|
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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 was deleted.
Oops, something went wrong.
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,79 @@ | ||
#!/usr/bin/env python | ||
import base64 | ||
import time | ||
import argparse | ||
import sys | ||
import io | ||
from PIL import Image | ||
import openai | ||
|
||
client = openai.Client(base_url='http://localhost:5005/v1') | ||
|
||
TEST_DIR = 'test' | ||
not_enhanced = "I NEED to test how the tool works with extremely simple prompts. DO NOT add any detail, just use it AS-IS:" | ||
|
||
def generate_image(prompt, model, res, f, n = 1, suffix=''): | ||
start = time.time() | ||
response = client.images.generate(prompt=prompt, model=model, size=res, response_format='b64_json', n=n) | ||
#image = Image.open(io.BytesIO(base64.b64decode(response.data[0].b64_json))) | ||
#image.show() | ||
end = time.time() | ||
print(f"## {model} {res} took {end-start:.1f} seconds", file=f) | ||
|
||
for i, img in enumerate(response.data, 1): | ||
fname = f"test_image_{model}_{res}{suffix}-{i:02d}_{n:02d}.png" | ||
with open(f'{TEST_DIR}/{fname}', 'wb') as png: | ||
png.write(base64.b64decode(img.b64_json)) | ||
# markdown record the details of the test, including any extra revised_prompt | ||
print(f"![{prompt}]({fname})", file=f) | ||
if img.revised_prompt: | ||
print("revised_prompt: " + img.revised_prompt, file=f) | ||
print("\n", file=f, flush=True) | ||
|
||
print("-"*50, file=f) | ||
print("\n", file=f, flush=True) | ||
|
||
def full_test(prompt, n=1): | ||
for model in ['dall-e-1', 'dall-e-2']: | ||
with open(f"{TEST_DIR}/test_images-{model}.md", "w") as f: | ||
print(f"# {prompt}", file=f) | ||
for res in ['256x256', '512x512', '1024x1024']: | ||
generate_image(prompt, model, res, f, n=n) | ||
|
||
model = 'dall-e-3' | ||
with open(f"{TEST_DIR}/test_images-{model}.md", "w") as f: | ||
print(f"# {prompt}", file=f) | ||
for res in ['1024x1024', '1024x1796', '1796x1024']: | ||
generate_image(prompt, model, res, f, n=n) | ||
generate_image(not_enhanced + prompt, model, res, f, n=n, suffix='-not-enhanced') | ||
|
||
def quick_test(prompt, n=1): | ||
with open(f"{TEST_DIR}/test_images_quick.md", "w") as f: | ||
print(f"# {prompt}", file=f) | ||
generate_image(prompt, "dall-e-1", "512x512", f, n=n) | ||
generate_image(prompt, "dall-e-1", "1024x1024", f, n=n) | ||
generate_image(prompt, "dall-e-2", "1024x1024", f, n=n) | ||
generate_image(not_enhanced + prompt, "dall-e-3", "1024x1024", f, n=n, suffix='-not-enhanced') | ||
generate_image(prompt, "dall-e-3", "1024x1024", f, n=n) | ||
|
||
def parse_args(argv=None): | ||
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
|
||
parser.add_argument('-p', '--prompt', action='store', type=str, default="A cute baby sea otter") | ||
parser.add_argument('-q', '--quick', action='store_true') | ||
parser.add_argument('-f', '--full', action='store_true') | ||
parser.add_argument('-n', '--batch', action='store', type=int, default=1) | ||
|
||
return parser.parse_args() | ||
|
||
|
||
if __name__ == '__main__': | ||
args = parse_args(sys.argv[1:]) | ||
|
||
if args.quick: | ||
quick_test(args.prompt, n=args.batch) | ||
elif args.full: | ||
full_test(args.prompt, n=args.batch) | ||
|
||
|
||
|