jezs00 / pycasso

A system to send AI generated art to an E-Paper display through a Raspberry PI unit
MIT License
76 stars 6 forks source link
ai ai-art e-paper raspberry-pi

pycasso

System to send AI generated art to an E-Paper display through a Raspberry PI unit

An article has been published on pycasso's development here.

Pycasso At Home
Yee-ha.

Acknowledgments

Inspiration for this project based on Tom Whitwell's SlowMovie and the very helpful write-up available at https://debugger.medium.com/how-to-build-a-very-slow-movie-player-in-2020-c5745052e4e4 on setting up epaper to work with a Raspberry Pi unit. I also liberally reused a lot of the install.sh script from this project because of the similarities and because it's pretty good. I would also like to acknowledge robweber who not only created omni-epd which I implemented so that this can work dynamically with many displays, but also provided me with a lot of good code examples that I referred back to often to try to ensure I was following best practises.

Uses stability-sdk to interact with Stable Diffusion's API.

Uses openai-python to interact with DALL-E's API.

Setup

Get Raspberry Pi Ready

(Optional) Plug in pijuice HAT

Connect EPD to Pi

Install pycasso

Configure pycasso

Configure PiJuice

PiJuice CLI Menu
PiJuice CLI Menu
PiJuice CLI Wakeup
PiJuice CLI Wakeup Configuration

Run pycasso

Customise pycasso

Administration

Hierarchical Bracket Wildcards

To enhance dynamic prompt generation within pycasso, many text files and strings in pycasso are parsed to replace wildcard text. This allows more flexibility when defining prompts.

By default, the three types of brackets used are:

  1. ()
  2. []
  3. {}

These can be added to, removed, or customised in .config.

Different options are separated by a pipe, for example (Option 1|Option 2|[Option {3|4|5|6}|Option 7]). The parser will first look for the lowest level of brackets (in this example {}), choose only one random option of the text, and then proceed to the next levels. Unless otherwise specified, each option has an equal chance of being chosen from each bracket pair. This means with nested brackets, you should consider the way the parsing works when thinking about the likelihood of a certain item of text occurring. For example, A (Good|[B|R]ad) Dog could return A Good Dog A Bad Dog or A Rad Dog. The option will be picked randomly between each bracket pair, so you have 50% chance of A Good Dog, 25% chance of A Bad Dog and 25% chance of A Rad Dog.

At the start of any segment, you can also provide a weighting for a particular option. For example (20:Option A|Option B|0:Option C) should provide Option A about 20 times more often than Option B. Option C would never appear. These weightings can also be used at the start of every line in one of the prompt-building text files to specify the likelihood of that line being chosen.

Have a play around with the strings and see what works for you. You can leave the EPD in test mode with no provider modes selected, and the test display will show you what subject it would have fetched.

Here are a few more examples of how one may use these to make simple prompts more complex:

A (|Happy|Sad) (Dog|Cat|Bird) could result in:

A (Dog|Cat) (|[Carrying|Stealing] A[n Apple| Banana]) could result in:

A(5: Friendly|2:n Uncommon| Rare) (3:Dog|Cat) could result in:

Configuration

You can run nano .config in the pycasso install folder to configure the way pycasso runs. There are a lot of options to configure your experience, and it is highly recommended to play around with these options to find the settings that work best for your setup. If at any time you wish to roll back to the default configuration you can find it is /examples/.config-example, or you can delete .config and running pycasso will restore the defaults automatically. If you are running pycasso frequently to see what changes your updates make, it is recommended to either use the test mode by setting all providers to 0, or using external/generated modes so that you are not being charged by your provider for each time you run the program. Below you will find a full explanation of all configuration sections and items.

File

Settings related to file operations within pycasso

EPD

These settings are consumed by omni-epd to customise the EPD information. See omni-epd for supported displays for more information on omni-epd options

Display

These settings are consumed by omni-epd to customise the display on the EPD. See omni-epd for more information on these options.

Image Enhancements

These settings are consumed by omni-epd to customise the display on the EPD. See omni-epd for more information on these options.

Prompt

Settings related to creation of prompts for submission and requests from AI art providers

Text

Settings related to parsing text of filenames and strings, and text display on the EPD

Icon

Settings related to status icons to display on EPD

Logging

Settings related to error and information logging from pycasso.

Providers

Settings related to image providers.

Generation

Settings related to generation of images with AI image providers

PiJuice

Settings related to PiJuice HAT configuration.

Post

Settings related to posting and sharing pycasso output on the web. Use set_keys.py to set up.

Debug

The following settings are only relevant for development. Only use them if you know what you're doing.

Troubleshooting

There is a symbol on the top left of the screen

By default, pycasso puts a faint symbol on the top left of the EPD to inform of system events. By default, these are:

GLIBC_2.33 not found

I have experienced this error even with the most recent release of raspbian. Following this appeared to work, however I haven't had any luck for a while. It might work for you:

sudo pip3 uninstall grpcio 
sudo pip3 uninstall grpcio-status 
sudo pip3 install grpcio==1.44.0 --no-binary=grpcio
sudo pip3 install grpcio-tools==1.44.0 --no-binary=grpcio-tools

If you can't store your credentials in keyring, you'll have to set the use_keyring option in .config to False, and provide your credentials using setup.sh option 5 or set_keys.py

Module I2C Missing

I have found this might cause issues with PiJuice. This is possibly due to running a lite version of the operating system. I found success by:

Log an issue

If you're experiencing a bug or issue, or have a feature request, please visit the Issues page to let us know. Recommend including the relevant information provided in pycasso.log and your current .config