Skip to content

Commit

Permalink
AI enhanced prompts for 'dall-e-3', code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
matatonic committed Mar 27, 2024
1 parent 1712361 commit f66fbb9
Show file tree
Hide file tree
Showing 22 changed files with 302 additions and 187 deletions.
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This is not affiliated with OpenAI in any way, and no OpenAI API key is required

Compatibility:
- [x] generations
- - [x] prompt
- - [x] prompt, including AI enhanced prompts when selecting 'dall-e-3'
- - [x] model
- - [x] size
- - [ ] quality ("hd or standard")
Expand All @@ -20,19 +20,27 @@ Compatibility:
- [ ] edits
- [ ] variations

This is in active development and currently works for basic use-cases. It selects generation configuration based on model.
This is in active development and currently works for basic use-cases. It selects the generation configuration based on the chosen model.

Currently hard coded as:
The default configuration uses:
- dall-e-1: sd 1.5
- dall-e-2: sdxl_lightning
- dall-e-3: sdxl

Settings for each model type can be found in the config folder, and can be modified as needed without needing to restart the server.

Quickstart
----------

Docker (**recommended**):
Configure your environment:
```shell
echo SD_BASE_URL=http://<your stable diffusion webui server>:<port> > .env
echo OPENAI_BASE_URL=http://<your openai chat server>:<port>/v1 >> .env # optional, for dall-e-3 style AI prompt enhancement
echo OPENAI_API_KEY=skip >> .env # optional, for dall-e-3 style AI prompt enhancement
```

Docker (**recommended**):
```shell
docker compose up
```
or:
Expand All @@ -41,14 +49,18 @@ pip install -r requirements.txt
python images.py --host 127.0.0.1 --port 5005
```

You can use the OpenAI client to interact with the API.
You can use the OpenAI python client to interact with the API.
```shell
pip install -U openai
```

```python
import base64
import io
import openai
from PIL import Image
client = openai.Client(base_url='http://localhost:5005/v1')
response = client.images.generate(prompt="A cute baby sea otter", response_format='b64_json')
client = openai.Client(base_url='http://localhost:5005/v1', api_key='skip')
response = client.images.generate(prompt="A cute baby sea otter", response_format='b64_json', model='dall-e-3')
image = Image.open(io.BytesIO(base64.b64decode(response.data[0].b64_json)))
image.show()

Expand All @@ -61,4 +73,5 @@ Links & Documentation
- OpenAI Images Guide: (https://platform.openai.com/docs/guides/moderation)
- OpenAI Images API Reference: (https://platform.openai.com/docs/api-reference/moderations)
- AUTOMATIC1111 Stable Diffusion WebUI: (https://github.com/AUTOMATIC1111/stable-diffusion-webui)
- ashleykleynhans/stable-diffusion-docker (https://github.com/ashleykleynhans/stable-diffusion-docker)
- ashleykleynhans/stable-diffusion-docker (https://github.com/ashleykleynhans/stable-diffusion-docker)

10 changes: 9 additions & 1 deletion config/default_sd15_conf.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"sampler_name": "DPM++ 2M Karras",
"steps": 30
"steps": 30,
"hr_upscaler": "Latent",
"denoising_strength": 0.68,
"subseed_strength": 0.75,
"override_settings": {
"sd_model_checkpoint": "realisticVisionV60B1_v51VAE.safetensors",
"sd_vae": "vae-ft-mse-840000-ema-pruned.ckpt"
},
"override_settings_restore_afterwards": false
}
11 changes: 9 additions & 2 deletions config/default_sdxl_conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
"sampler_name": "DPM++ 2S a Karras",
"refiner_checkpoint": "sd_xl_refiner_1.0.safetensors",
"refiner_switch_at": 0.8,
"VAE": "fixFP16ErrorsSDXLLowerMemoryUse_v10.safetensors",
"steps": 40
"steps": 40,
"hr_upscaler": "Latent",
"denoising_strength": 0.68,
"subseed_strength": 0.75,
"override_settings": {
"sd_model_checkpoint": "opendalle_v11.safetensors",
"sd_vae": "fixFP16ErrorsSDXLLowerMemoryUse_v10.safetensors"
},
"override_settings_restore_afterwards": false
}
13 changes: 10 additions & 3 deletions config/default_sdxl_lightning_conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
"sampler_name": "DPM++ SDE",
"refiner_checkpoint": null,
"refiner_switch_at": 0.0,
"VAE": null,
"steps": 4,
"cfg_scale": 1.0
}
"cfg_scale": 1.0,
"hr_upscaler": "Latent",
"denoising_strength": 0.68,
"subseed_strength": 0.75,
"override_settings": {
"sd_model_checkpoint": "dreamshaperXL_lightningDPMSDE.safetensors",
"sd_vae": null
},
"override_settings_restore_afterwards": false
}
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ services:
server:
build:
dockerfile: Dockerfile
tty: true
image: ghcr.io/matatonic/openedai-images
env_file:
- .env
volumes:
- ./config:/app/config
ports:
- 5005:5005
command: ["python", "images.py", "--host", "0.0.0.0", "--port", "5005"]
Expand Down
Loading

0 comments on commit f66fbb9

Please sign in to comment.