Lumina - AI Art Generator (DALL-E 3) for Your TV
by DevMiser in Circuits > Raspberry Pi
2004 Views, 21 Favorites, 0 Comments
Lumina - AI Art Generator (DALL-E 3) for Your TV
The Lumina AI Art Generator uses voice control to create stunning artwork and displays it on any TV with an HDMI input. Lumina runs a python program that uses Picovoice solutions to detect a wake word and listen to requests and OpenAI’s DALL-E 3 to convert the request to an image that is then displayed on the connected TV.
A brief demo video of the Lumina AI Art Generator is here:
Supplies
Raspberry Pi 4 – This needs to be a Raspberry Pi 4, so that you can run the legacy 64-bit operating system. Earlier version Raspberry Pis are likely to throw memory errors while running this program. Also, do not use the Raspberry Pi 5. It requires an operating system that is not compatible with this installation. The 2 GB RAM Raspberry Pi 4 model is sufficient: https://www.adafruit.com/product/4292
5v Power Supply – I recommend the official Raspberry Pi power supply: https://www.adafruit.com/product/4298
USB Microphone – for talking to the Lumina. Any USB mic should work, and this inexpensive one is sufficient: https://www.adafruit.com/product/3367
Micro HDMI to HDMI cable – for connecting Lumina to your TV. Lumina has a micro HDMI plug and most TVs have a standard HDMI plug. I used this one: https://www.adafruit.com/product/1322
Micro HDMI to HDMI Adapter (alternative) – if you already have a normal HDMI cable you would prefer to use, you can use an adapter for the micro HDMI plug on the Raspberry Pi 4: https://www.amazon.com/gp/product/B0BHYS1L5D/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&th=1
Heatsink (recommended) – Place it on the largest chip on your Raspberry Pi 4 to help it run cooler. I used this one: https://www.adafruit.com/product/3083
Create an OpenAI Account and Obtain Your Secret OpenAI API Key
Open a web browser on your PC and navigate to the OpenAI website - https://openai.com/.
In the upper right-hand corner, click on “API”.
On the next screen, click on "Sign Up" and then follow the prompts to create your account.
Next, on the logged-in screen, click on your Personal icon in the upper right-hand corner and then click on “View API keys”.
Then click on "+ Create new secret key" to create your new secret API key.
Copy your API key and keep it in a secure location. You will need it in a later step.
Create a Picovoice Account and Obtain Your Secret Picovoice Access Key
Create a free Picovoice account by opening a web browser and navigating to https://picovoice.ai/.
In the upper right-hand corner, click the "Start Free" button and follow the prompts to open your account.
As soon as you complete your sign up, you will automatically be redirected to a page with your secret access key.
Copy your "AccessKey" and keep it in a secure location. You will need it in a later step.
Prepare Your Raspberry Pi 4 to Run the Program
These instructions assume you already have a Raspberry Pi 4 set up and running with the legacy 64-bit operating system. If not, set up your Raspberry Pi using the instructions found here: Raspberry Pi Documentation - Getting started, but also carefully follow the following instructions: For best results, use a Raspberry Pi 4 (not a Raspberry Pi 5) and use the legacy 64-bit OS. Raspberry Pi’s newer OS (Bookworm) released on December 5, 2023, does not work well with this installation. To load the legacy OS, use Raspberry Pi Imager and select Raspberry Pi 4 as the Raspberry Pi Device. After you select CHOOSE OS under Operating System, select Raspberry Pi OS (other). On the next screen, scroll down and select Raspberry Pi OS (Legacy, 64-bit), and proceed as normal from there.
Be certain to load the 64-bit (not the 32-bit) version of the Raspberry Pi OS when setting up your Raspberry Pi. If you use the 32-bit version, you are likely to get memory errors when running the program.
To prepare your Raspberry Pi to run Lumina, do the following:
1. Edit the bashrc file on your Raspberry Pi as follows:
a. Open a terminal and enter the following command to open the bashrc file:
sudo nano ~/.bashrc
b. Scroll to the bottom of the file using your keyboard and add the following lines at the end (be certain to include the #s):
# sets a location where the Raspberry Pi OS and Python can look for
# executable/configuration files
export PATH="$HOME/.local/bin:$PATH"
c. Press the CTRL and X keys simultaneously on your keyboard, then press Y and then press Enter to save the revisions to the file.
d. Then enter the following command:
sudo reboot
This will reboot your Raspberry Pi. After the reboot is completed, log back in.
2. Open a terminal and enter the following commands in the following order:
sudo apt update
sudo apt full-upgrade - If asked if you want to continue, enter Y and then press Enter
pip3 install --upgrade pip
sudo apt install ttf-mscorefonts-installer - When asked if you want to continue, enter Y and then press Enter
sudo apt-get install x11-xserver-utils
sudo apt-get install python3-pil.imagetk
sudo apt-get install portaudio19-dev - When asked if you want to continue, enter Y and then press Enter
pip3 install pyaudio
pip3 install pvrecorder
pip3 install pvporcupine
pip3 install pvcobra
pip3 install pvleopard
pip3 install schedule
pip3 install --upgrade openai
sudo reboot – will reboot your Raspberry Pi; log back in after the reboot.
3. You can optionally take the following steps to blank out the screen cursor after 5 seconds of inactivity so that it won’t show on top of your generated images:
a. Open a terminal and enter the following commands in the following order:
sudo apt-get install unclutter- When asked if you want to continue, enter Y and then press Enter
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
b. Scroll to the bottom of the opened file using your keyboard and add the following line at the end:
@unclutter -idle 5
c. Press the CTRL and X keys simultaneously on your keyboard, then press Y and then press Enter to save the revisions to the file.
d. Then enter the following command:
sudo reboot – log back in after the reboot.
4. Download the Lumina.py program and associated files by opening a terminal and entering the following command:
git clone https://github.com/DevMiser/Lumina.git
5. Modify Lumina.py to include the secret API key that you previously created in your OpenAI account and the secret access key that you created in your Picovoice account by doing the following:
a. Open a terminal and enter the following commands:
cd /home/pi/Lumina
sudo nano Lumina.py
b. Use your keyboard to scroll down to the lines that say:
openai.api_key = “put your secret API key between these quotation marks”
pv_access_key= “put your secret access key between these quotation marks”
Now modify those lines to replace the portions that are italicized above with your secret OpenAI API key and your secret Picovoice access key, respectively.
c. Press the CTRL and X keys simultaneously on your keyboard, then press Y and then press Enter to save the revisions to the file.
6. Move the Lumina keyword file to the Porcupine raspberry-pi folder by entering the following command:
mv /home/pi/Lumina/Lumina_en_raspberry-pi.ppn /home/pi/.local/lib/python3.9/site-packages/pvporcupine/resources/keyword_files/raspberry-pi
Important - Note there are two blank spaces in the above command – one between "mv" and "/home" and one between ".ppn" and "/home". Be sure to include them. Also, there is no space between “site-” and “packages”.
7. Reboot your Raspberry Pi.
Run the Program
Plug your microphone into an USB port on your Raspberry Pi 4. Then plug the micro HDMI end of the HDMI cable into your Raspberry Pi 4 and the other end into an HDMI plug on your TV. Use your TV remote to select that port as the source. Then plug in the power to the Raspberry Pi 4.
Make certain that your TV is turned on before running the Lumina program. This allows Lumina to automatically detect the resolution of your TV.
To run the program, open a terminal and enter the following commands:
cd /home/pi/Lumina
python3 Lumina.py
Wait for the Lumina logo to appear on your TV screen (if it does not appear, make certain you selected the correct HDMI port on your TV).
You can then wake up Lumina by saying its wake word, which is also its name: Lumina.
When Lumina hears its name, it will display “Listening” on the TV. You can then make your request. For example, try:
Chipmunks at a New Year’s Eve party with balloons, streamers, and champagne.
A couple in a rowboat in the style of Renoir.
A city of neon lights.
An album cover for a punk rock band.
A schematic of a spaceship in the style of Leonardo DaVinci.
A still life of flowers, wine, and cheese.
When you finish your request, Lumina will display “Generating new image…” followed by the request you made, and a few seconds later will display your requested image on your TV.
When you are finished with the program, say “Lumina” and follow with “Close the program”, “End the program”, or “Exit the program” to exit.
Assembling the Optional Lumina Enclosure
If you would like to use the optional Lumina enclosure, follow these instructions.
3D print the top and bottom of the Lumina enclosure. The STLs for these 3D parts are on my GitHub repository: DevMiser/Lumina: Lumina - AI Art Generator for Your TV (github.com). The recommended settings for slicing the STLs are 0.20mm quality with 15% infill. Use organic supports with no top interface layer if possible.
Remove your SD card before placing your Raspberry Pi 4 in the bottom part of the enclosure. You will reinsert it in a later step.
The top of the Lumina enclosure will hold the Raspberry Pi in place. Use four Phillips pan head machine screws to screw the bottom of the enclosure into the top. The metric screw size is 2mm x 0.4mm x 10mm. They are available here: https://www.boltdepot.com/Product-Details.aspx?product=17850
Plug the USB microphone into the Raspberry Pi through the slot on the side of the enclosure. Reinsert the SD card through the available slot in the enclosure.
The HDMI cable and power supply cable are attached through the slots in the back of the enclosure.
Adjusting the Screen Resolution
Lumina will adapt its settings to the screen resolution of most TVs automatically.
However, if the images displayed on your TV appear distorted, you may need to adjust the screen resolution manually.
To adjust the screen resolution manually, open a terminal and enter the following commands:
cd /home/pi/Lumina
sudo nano Lumina.py
b. Use your keyboard to scroll down to the lines that say:
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
c. Comment out those lines by placing a hash sign (#) at the beginning of each of those two lines.
d. Uncomment the next two lines by deleting the hash sign (#) at the beginning of each of those two lines so that they look like this:
screen_width = x
screen_height = y
e. Replace the ‘x’ and the ‘y’ with the number of pixels for the width and height of the resolution of your TV. You should be able to find that information in your TV owner’s manual. If not, try the following:
The most common standard resolution for HDTVs is 1920 x 1080 pixels, also known as Full HD or 1080p. The most common UHD resolution is 4K, which has 3840 x 2160 pixels.
You might also try 2560 x 1440 (Quad HD), 1260 x 720 (720p) and 5120 x 2880 (Ultra-high-resolution).
f. Press the CTRL and X keys simultaneously on your keyboard, then press Y and then press Enter to save the revisions to the file.
g. Reboot your Raspberry Pi and run the program again.
Setting Up the Program to Run Automatically Upon Startup
After you have everything up and running, you may want to program Lumina to run automatically when you plug in its power. To do so, edit the bashrc file on your Raspberry Pi 4 as follows:
a. Open a terminal and enter the following command to open the bashrc file:
sudo nano ~/.bashrc
b. Scroll to the bottom of the file using your keyboard and add the following lines at the end [the first line includes zeros, not Os]:
export DISPLAY=:0.0
python3 /home/pi/Lumina/Lumina.py &
c. Press the CTRL and X keys simultaneously on your keyboard, then press Y and then press Enter to save the revisions to the file.
d. Then enter the following command:
sudo reboot
Now your Lumina should run automatically when you plug in its power.
Make certain that the HDMI cable is connected between Lumina and your TV and that your TV is turned on before plugging in the power to Lumina. This allows Lumina to automatically detect the resolution of your TV on startup.