Level Up Your Desk with the Gen AI Photo Frame


Video showing AI generated anime characters on the tiny photo frame.

Download Code for this project

Say hello to the Gen AI powered tiny photo frame, your desk’s new best friend! A sleek, compact frame that randomly displays unique images tailored to your interests. Whether you’re an anime aficionado, a nature enthusiast, or a comics connoisseur, this little gem adds an undeniable cool factor to your workspace. With infinite possibilities and never-ending variety, boredom is simply not an option. From stunning landscapes to your favorite characters, the sky’s the limit with this innovative device. Spice up your desk and let your imagination run wild with this one-of-a-kind photo frame!

Building Your Gen AI Photo Frame

Let’s begin with what we need. Firstly, we require the hardware components to construct this compact photo frame. Detailed instructions on acquiring these components are available in my previous article. Essentially, we’ll utilize a custom PCB to connect a 128x160 SPI TFT display to the Raspberry Pi Pico W. The photo frame itself is remarkably small, akin to the size of an address card. The Pi Pico W is priced at approximately $8 to $10, while the PCB ranges from $2 to $5. The display costs around $10. Additionally, you can opt to 3D print an enclosure for the frame, detailed on my website. Follow the assembly instructions provided, and ensure everything functions smoothly by running the ‘game of life program’

Harnessing the Power of Gen AI

Now, onto the challenging phase: acquiring Gen AI-based software to produce visually appealing random images for our photo frame. We have several options at our disposal. One approach is to utilize a Cloud-Based text-to-image API directly. However, for a more enjoyable (and cost-effective) experience, we can develop our own service for image generation. Most Gen AI models are bulky and require powerful machines with GPUs to run at reasonable speeds. After extensive research, I came across the Stable Diffusion Turbo model, which is relatively compact and operates at impressive speeds (2-3 seconds per image) on a dual-core CPU with around 4 GB of RAM. I opted to rent a virtual machine from Hetzner for approximately $10 to $12 per month, equipped with an Intel CPU and 8 GB of RAM. The next step involved writing Python code to generate inferences. Thankfully, Python offers robust support for handling text-to-image generation pipelines, and the code required for our purposes, including setting up a web server, is straightforward. Simply install the dependencies and execute the following command:

python3 server.py

This command initiates a local server on port 5000. You can visit the ‘/generate’ URL to create a random image. By default, it generates an image of flowers in a vase. To customize the prompt, use the ‘/prompt?prompt=your_desired_prompt’ endpoint. With this setup, we now have a server capable of generating captivating images at remarkable speeds, all for around $10.

Taking Your GenAI service to the internet

Now, with our local server up and running, the next step is to make it accessible over the internet. While there are various methods to achieve this, let’s explore a quick and straightforward approach.

⚠️ Note: that this method is primarily for experimentation purposes.

We’ll utilize https://serveo.net/ for this task. Simply execute the following command in the terminal:

ssh -R 80:localhost:5000 serveo.net

This command will provide us with a unique URL corresponding to our tunnel, granting access to our service over the internet.

Note: I attempted using ngrok and localtunnel, but encountered issues. If you manage to get them working, I’d love to hear about your experience.

To run our services in the background, execute the following commands:

nohup python server.py &
nohup ssh -R 80:localhost:5000 serveo.net &

Note: that the nohup.out file will contain the public URL from serveo.net for our tunnel.

Programming the Pi Pico

It’s finally time to upload the code to our Pi Pico W and get our Gen AI-powered photoframe up and running. Here’s the link to the code file: [insert link here]. Please make the following changes in the code file:

  • Change WIFI_SSID to the SSID of your WiFi network.
  • Change WIFI_PWD to the password of your WiFi network.
  • Change ENDPOINT to the public tunnel URL from a service like serveo, ngrok, or localtunnel.

⚠️ Please exercise caution: Note that there is no secure way to store passwords on your Pi Pico. Be aware that your password can be easily stolen by someone with physical access to your Pi Pico. I would recommend setting up a mobile phone-based access point for internet connectivity and changing your password frequently.

Cost Breakdown: Components and Services

Category Item Cost Description
One-time Expenses Raspberry Pi Pico W $8-$10 Microcontroller for the photo frame
Custom PCB $2-$5 Connects display to Raspberry Pi Pico W
128x160 SPI TFT Display $10 Display for the photo frame
3D Printing Enclosure (Optional) Variable Enclosure for the photo frame
Monthly Recurring Virtual Machine (VPS) Rental (e.g., Hetzner) $10-$12 Hosting server software for image generation

Conclusion

There you have it! Our Gen AI-powered photo frame is all set to dazzle. Simply utilize the public tunnel endpoints in your browser to witness the magic unfold and tweak the prompts to your heart’s content. Watch as the frame springs to life, displaying captivating images. And if boredom dares to creep in, fear not! Just change the prompt for an instant refresh. Now, it’s time to proudly place it on your desk and let the admiration begin!