Skip to content

Commit

Permalink
ai enhance update, better scaler, more tests. better defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
matatonic committed Mar 28, 2024
1 parent a6cab22 commit 3b98994
Show file tree
Hide file tree
Showing 31 changed files with 136 additions and 68 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.env
test-*/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
3 changes: 3 additions & 0 deletions config/default_sd15_conf.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"sampler_name": "DPM++ 2M Karras",
"refiner_switch_at": 0.0,
"steps": 30,
"cfg_scale": 7.0,
"hr_upscaler": "Latent",
"denoising_strength": 0.68,
"subseed_strength": 0.75,
"restore_faces": false,
"negative_prompt": "bad_prompt_version2-neg",
"override_settings_restore_afterwards": false,
"override_settings": {
"sd_model_checkpoint": "realisticVisionV60B1_v51VAE.safetensors",
Expand Down
2 changes: 2 additions & 0 deletions config/default_sdxl_conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"hr_upscaler": "Latent",
"denoising_strength": 0.68,
"subseed_strength": 0.75,
"restore_faces": false,
"negative_prompt": "ac_neg1 ac_neg2",
"override_settings_restore_afterwards": false,
"override_settings": {
"sd_model_checkpoint": "opendalle_v11.safetensors",
Expand Down
3 changes: 2 additions & 1 deletion config/default_sdxl_lightning_conf.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"sampler_name": "DPM++ SDE",
"refiner_checkpoint": null,
"refiner_switch_at": 0.0,
"steps": 4,
"cfg_scale": 1.0,
"hr_upscaler": "Latent",
"denoising_strength": 0.68,
"subseed_strength": 0.75,
"restore_faces": false,
"negative_prompt": "ac_neg1 ac_neg2",
"override_settings_restore_afterwards": false,
"override_settings": {
"sd_model_checkpoint": "dreamshaperXL_lightningDPMSDE.safetensors",
Expand Down
7 changes: 4 additions & 3 deletions images.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def OpenDallePrompt(prompt):
7. **Additional details (5-10 words).** Include specific or important details that will complement and clarify the visualization.
8. **Overall mood or impression (3-7 words).** Conclude with a description of the overall mood or main impression that the image should convey.
Write everything in 1 sentence (not a list), separating with commas, in English, strictly following the instruction (especially the number of words)."""},
Write everything in 1 sentence (not a list), separating with commas, in English, strictly following the instruction (especially the number of words). Provide descriptions that are direct and literal, avoiding metaphors and figurative language, and exclude specific features like "Velvet shadows." Focus on explicit and clear depiction of features, surroundings, element combinations, symbolic significance, lighting, additional details, and overall mood without using commonly associated expressions or imagery."""},
{'role': 'assistant', 'content': "Understood, provide the input and I will generate a complete description of a scene."},
{'role': 'user', 'content': "photo of an ancient castle very atmospheric, but the sky should be completely covered in clouds, yet it should be bright."},
{'role': 'assistant', 'content': "photo of an ancient castle with a majestic, eerie ambiance, highlighting its towering spires, weathered stone, and ivy-clad walls, set against a backdrop of a dense, mystic forest under a sky completely shrouded in clouds yet illuminated by a diffused, ethereal light, where the fusion of natural decay and enduring architectural grandeur evokes a sense of timeless mystery and the eternal battle between man and nature, casting a glow that reveals subtle details and textures, creating an impression of haunting beauty and solemn tranquility. "},
Expand Down Expand Up @@ -79,7 +79,8 @@ def load_default_conf(self, filename):
def maybe_scaler(self, payload, width, height):
scale = math.sqrt(width * height) / self.base_model_size

if scale >= 1.2:
# If the target is more than 20% off the ideal size, scale it
if abs(scale - 1) >= 0.2:
# SD expects pixel sized aligned by 8
sd_width = 8 * round(width / (scale * 8))
sd_height = 8 * round(height / (scale * 8))
Expand Down Expand Up @@ -158,7 +159,7 @@ async def generations(request: GenerationsRequest):
if not request.prompt.startswith("I NEED to test how the tool works with extremely simple prompts. DO NOT add any detail, just use it AS-IS:"):
request.prompt = revised_prompt = await OpenDallePrompt(request.prompt)
else:
request.prompt = request.prompt[len("I NEED to test how the tool works with extremely simple prompts. DO NOT add any detail, just use it AS-IS:"):]
request.prompt = revised_prompt = request.prompt[len("I NEED to test how the tool works with extremely simple prompts. DO NOT add any detail, just use it AS-IS:"):]

req = rg.create_request(request.prompt, int(width), int(height), request.n)
print(req)
Expand Down
Binary file added test/test_image_dall-e-1_1024x1024-01_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed test/test_image_dall-e-1_1024x1024.png
Binary file not shown.
Binary file added test/test_image_dall-e-1_256x256-01_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed test/test_image_dall-e-1_256x256.png
Binary file not shown.
Binary file added test/test_image_dall-e-1_512x512-01_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed test/test_image_dall-e-1_512x512.png
Binary file not shown.
Binary file added test/test_image_dall-e-2_1024x1024-01_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed test/test_image_dall-e-2_1024x1024.png
Binary file not shown.
Binary file added test/test_image_dall-e-2_256x256-01_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed test/test_image_dall-e-2_256x256.png
Binary file not shown.
Binary file added test/test_image_dall-e-2_512x512-01_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed test/test_image_dall-e-2_512x512.png
Binary file not shown.
Binary file added test/test_image_dall-e-3_1024x1024-01_01.png
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 removed test/test_image_dall-e-3_1024x1024.png
Binary file not shown.
Binary file added test/test_image_dall-e-3_1024x1796-01_01.png
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 removed test/test_image_dall-e-3_1024x1796.png
Binary file not shown.
Binary file added test/test_image_dall-e-3_1796x1024-01_01.png
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 removed test/test_image_dall-e-3_1796x1024.png
Binary file not shown.
12 changes: 6 additions & 6 deletions test/test_images-dall-e-1.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# A cute baby sea otter
## dall-e-1 256x256 took 3.1 seconds
![A cute baby sea otter](test_image_dall-e-1_256x256.png)
## dall-e-1 256x256 took 36.4 seconds
![A cute baby sea otter](test_image_dall-e-1_256x256-01_01.png)


--------------------------------------------------


## dall-e-1 512x512 took 3.4 seconds
![A cute baby sea otter](test_image_dall-e-1_512x512.png)
## dall-e-1 512x512 took 3.1 seconds
![A cute baby sea otter](test_image_dall-e-1_512x512-01_01.png)


--------------------------------------------------


## dall-e-1 1024x1024 took 12.1 seconds
![A cute baby sea otter](test_image_dall-e-1_1024x1024.png)
## dall-e-1 1024x1024 took 12.2 seconds
![A cute baby sea otter](test_image_dall-e-1_1024x1024-01_01.png)


--------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions test/test_images-dall-e-2.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# A cute baby sea otter
## dall-e-2 256x256 took 13.3 seconds
![A cute baby sea otter](test_image_dall-e-2_256x256.png)
## dall-e-2 256x256 took 32.2 seconds
![A cute baby sea otter](test_image_dall-e-2_256x256-01_01.png)


--------------------------------------------------


## dall-e-2 512x512 took 2.7 seconds
![A cute baby sea otter](test_image_dall-e-2_512x512.png)
## dall-e-2 512x512 took 8.5 seconds
![A cute baby sea otter](test_image_dall-e-2_512x512-01_01.png)


--------------------------------------------------


## dall-e-2 1024x1024 took 3.8 seconds
![A cute baby sea otter](test_image_dall-e-2_1024x1024.png)
## dall-e-2 1024x1024 took 5.4 seconds
![A cute baby sea otter](test_image_dall-e-2_1024x1024-01_01.png)


--------------------------------------------------
Expand Down
42 changes: 33 additions & 9 deletions test/test_images-dall-e-3.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,47 @@
# A cute baby sea otter
## dall-e-3 1024x1024 took 62.4 seconds
![A cute baby sea otter](test_image_dall-e-3_1024x1024.png)
revised_prompt: A cuddly, playful baby sea otter with soft, dark brown fur, large, curious eyes, and tiny, webbed paws floating on its back among lush kelp forests, basking in the gentle sunlight filtering through the crystal-clear water, exuding an irresistible charm and innocence that warms the heart, capturing the joy and wonder of nature's most adorable marine creatures.
## dall-e-3 1024x1024 took 74.9 seconds
![A cute baby sea otter](test_image_dall-e-3_1024x1024-01_01.png)
revised_prompt: A cute baby sea otter with round, fluffy fur, large, curious eyes, and tiny paws clutching a piece of kelp, floating on its back in a calm, serene ocean environment surrounded by lush, swaying kelp forests, embodying the innocence and playfulness of nature, under soft, warm sunlight filtering through the water's surface, showcasing the otter's endearing features and the gentle ripples of water around it, conveying a sense of joy and tranquility.


--------------------------------------------------


## dall-e-3 1024x1796 took 112.5 seconds
![A cute baby sea otter](test_image_dall-e-3_1024x1796.png)
revised_prompt: A cuddly, fluffy baby sea otter floating on its back, displaying its adorable button nose, sparkling eyes, and soft fur, surrounded by vibrant kelp forests and playful bubbles, with the sun casting a warm, golden glow on the crystal-clear water, embodying the innocence and joy of life, and showcasing the harmonious coexistence of marine creatures and their environment, capturing a delightful and heartwarming moment in nature.
## dall-e-3 1024x1024 took 29.3 seconds
![I NEED to test how the tool works with extremely simple prompts. DO NOT add any detail, just use it AS-IS:A cute baby sea otter](test_image_dall-e-3_1024x1024-not-enhanced-01_01.png)
revised_prompt: A cute baby sea otter


--------------------------------------------------


## dall-e-3 1796x1024 took 112.0 seconds
![A cute baby sea otter](test_image_dall-e-3_1796x1024.png)
revised_prompt: A cuddly, fluffy baby sea otter floating on its back, showcasing its soft, velvety fur, button-like eyes, and playful expression, surrounded by calm, crystal-clear waters and lush kelp forests, embodying the perfect blend of innocence and curiosity, as the sunlight dances on the water's surface, casting a warm, gentle glow that accentuates the otter's endearing features and captures the essence of pure joy and wonder, invoking feelings of delight and affection.
## dall-e-3 1024x1796 took 111.4 seconds
![A cute baby sea otter](test_image_dall-e-3_1024x1796-01_01.png)
revised_prompt: A cute baby sea otter floating on its back, displaying its round, fluffy body, button-like eyes, and small, playful paws, clutching a piece of kelp for stability, surrounded by calm, crystal-clear waters and lush underwater vegetation, embodying the essence of innocence and curiosity, bathed in soft, warm sunlight filtering through the water's surface, with tiny air bubbles escaping from its nose, evoking feelings of delight and endearment.


--------------------------------------------------


## dall-e-3 1024x1796 took 85.1 seconds
![I NEED to test how the tool works with extremely simple prompts. DO NOT add any detail, just use it AS-IS:A cute baby sea otter](test_image_dall-e-3_1024x1796-not-enhanced-01_01.png)
revised_prompt: A cute baby sea otter


--------------------------------------------------


## dall-e-3 1796x1024 took 111.5 seconds
![A cute baby sea otter](test_image_dall-e-3_1796x1024-01_01.png)
revised_prompt: A cute baby sea otter with a round, fluffy body, playful dark eyes, and small, webbed paws, floating on its back in a calm, shallow ocean cove surrounded by lush kelp forests, its fur glistening with droplets of water as it curiously manipulates a seashell, embodying the innocence and wonder of nature, under soft, warm sunlight filtering through the surface, revealing the otter's delightful expression and intricate fur patterns, capturing an adorable and heartwarming moment.


--------------------------------------------------


## dall-e-3 1796x1024 took 84.4 seconds
![I NEED to test how the tool works with extremely simple prompts. DO NOT add any detail, just use it AS-IS:A cute baby sea otter](test_image_dall-e-3_1796x1024-not-enhanced-01_01.png)
revised_prompt: A cute baby sea otter


--------------------------------------------------
Expand Down
43 changes: 0 additions & 43 deletions test/test_images.py

This file was deleted.

79 changes: 79 additions & 0 deletions test_images.py
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)



0 comments on commit 3b98994

Please sign in to comment.