BookWise Pi
Introducing the BookWise Pi: Your Ultimate Reading Companion! Imagine a world where your books not only come to life but also help you digest their contents effortlessly. With BookWise Pi, that vision becomes a reality. Simply place your open book on our intelligent device, and like magic, it captures the page, deciphers the text, and consults with ChatGPT to craft a concise summary. Then, when you're ready to dive back into your reading, the BookWise Pi whispers your custom summary, ensuring you never miss a beat. Experience the future of reading, where technology meets literature in perfect harmony!
Supplies
Material
- Raspberry Pi (Model 4 or newer recommended)
- Wide-angle camera module compatible with Raspberry Pi
- MicroSD card (8GB or larger) with Raspbian OS installed
- Power supply for Raspberry Pi (USB-C or Micro USB, depending on the model)
- HDMI cable and monitor (for initial setup and debugging)
- USB keyboard and mouse (for initial setup and debugging)
- Google Nest Mini for Text-to-Speech (TTS) output
- Internet connection
- Python programming environment installed on Raspberry Pi
- Access to the ChatGPT API (requires API key)
- 2 2mm screws with bolts
- 50 cm x 50 cm 2.5 mm plexyglass
Tools
- 3D printer
- Hot-glue gun
- Screwdriver
- Cutter
Get an API Key for ChatGPT
1. Sign up for OpenAI
- Visit the OpenAI website at https://openai.com/.
- Click on the "Try ChatGPT" button
- Click on the "Sign up" button.
- Follow the prompts to create an account. You may need to provide your email address, create a password, and agree to the terms of service.
2. Create new secret key
- Once you're signed in to your OpenAI account, navigate to the API section (https://platform.openai.com/api-keys).
- Click on the "Create new secret key" button
- Enter a name for your key and click "Create secret key"
3. Create a new API key
- On the API management page, look for an option to create a new API key.
- Click on the "Create new API key" button or similar.
- You may need to provide a name or description for your API key to help you identify it later.
4. Retrieve your API key
- After creating the API key, you should see it listed on the API management page.
- Your API key will typically be a long string of characters and numbers.
- Copy the API key to your clipboard or save it in a secure location. Treat your API key like a password and do not share it publicly.
Additional Tips:
- Keep your API key secure and do not expose it in public repositories or code samples.
- Monitor your API usage and consider implementing rate limiting or usage caps to avoid unexpected charges.
- Review the OpenAI API documentation for information on endpoints, request formats, and response formats.
Setup Raspberry Pi
1. Set up Raspberry Pi with Bullseye OS
- Download the Raspberry Pi Imager from https://www.raspberrypi.com/software/
- Launch Raspberry Pi Imager
- Select the model of your board (For example, Raspberry Pi 4)
- Select the preferred OS version
- Select the storage device (e.g. the USB card you will later insert in the Raspberry Pi's SD slot)
- Click "Next"
- Click "Edit settings" to customize system settings
- In the "General" tab
- Set the hostname
- Set username and password to access the system
- Set Wifi SSID and password
- Set locale
- In the "Services" tab
- enable SSH service and enter SSH credentials
Install Libraries
1. Download and install Putty
NOTE: if you already have an SSH terminal on your system, you can skip this section
- Download Putty from official site
- Launch installer
2. Connect to Raspberry Pi
- Launch Putty
- Enter the IP address of your Raspberry Pi
- Click "Open"
- When asked, enter username and password you configured in previous step
TIP: One method to find the IP address of the Raspberry Pi is to connect to your Wifi router and check for the list of connected devices
3. Update and Upgrade
- Launch Putty. Enter the IP address of the Raspberry Pi board
- When asked, enter username and password you configured in the Raspberry Pi Images
- Run the following commands to update the package lists and upgrade the installed packages:
sudo apt update
sudo apt upgrade
4. Install Python 3
- Python 3 should come pre-installed with Bullseye OS. To verify, run:
python3 --version
- If Python 3 is not installed, you can install it using:
sudo apt install python3
5. Set Up OpenAI SDK for Python
- Install the OpenAI Python package using pip:
pip install openai
- Set up your OpenAI API key by exporting it as an environment variable:
export OPENAI_API_KEY="your-api-key"
- Replace "your-api-key" with your actual API key (see Step 1)
6. Install PyChromecast
- Install the PyChromecast requirements using pip:
pip install casttube==0.2.1
pip install protobuf==4.25.2
pip install zeroconf==0.131.0
- Install PyChromecast package using pip
pip install PyChromecast
- Find the friendly name of the device you want to connect to. If you are not sure about the friendly name, run the following commands in the Python shell to print the friendly name of all the discoverable devices
>> import time
>> import pychromecast
>> import zeroconf
>> # Create a browser which prints the friendly name of found chromecast devices
>> zconf = zeroconf.Zeroconf()
>> browser = pychromecast.CastBrowser(pychromecast.SimpleCastListener(lambda uuid, service: print(browser.devices[uuid].friendly_name)), zconf)
>> browser.start_discovery()
>> # Shut down discovery
>> pychromecast.discovery.stop_discovery(browser)
7. Install source files
- Clone github repository to download all the scripts for this project
git clone https://github.com/ambrogio-galbusera/bookwise
- Edit to main Python script to configure the OpenAI API key and the friendly name of your Chromecast device
cd bookwise
nano bookwise.py
- Set the correct api_key
# OpenAI API Key
api_key = "sk-hf12xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
- Set the IP address or the name of your Raspberry board
# This board's IP address or hostname
this_server="192.168.1.104"
- Set the name of the Chromecast device
# Chromecast device friendly name
cc_device="Garage speaker"
- Save our changes by pressing "Ctrl-X", then "Y" and "Enter" to confirm the flename
8. Configure automatic start of Bookwise application
- Check that startup scripts have execution permission
chmod +x ~/bookwise/launcher.sh
chmod +x ~/bookwise/server_launcher.sh
- Copy autostart script to the proper position
mkdir -p .config/lxsession/LXDE-pi
cp ~/bookwise/autostart .config/lxsession/LXDE-pi
Additional Tips:
- Make sure your Raspberry Pi is connected to the internet to download packages and access the OpenAI API.
- Explore the documentation for OpenAI SDK for advanced usage and customization options.
Build the Bookwise Base
1. Print and assemble the frame
- Print four base elements (base1c.stl)
- Assemble the four base elements with glue or hot glue and make a perfect square
2. Cut Plexyglass
- Cut a piece of Plexyglass 17.4 cm x 17.4 cm. This will be the base where the Raspberry Pi board will be installed
- Glue the Plexiglass to the bottom side of the base frame
Downloads
Build the Camera Support
- Print camera support
- Drill two holes for the screws to keep the camera module in place
- Insert the two screws and tight the nuts
Additional tips
Check the position of the ribbon connector: it has to be positioned as shown in picture
Downloads
Install the Raspberry Pi
- Connect the Sense HAT to the Raspberry Pi
- Place some double-side tape on the base
- Put the Raspberry Pi board in place
Install the Camera
1. Mount the camera support
- Drill a couple of holes in the base. The holes must be larger than the pegs on the bottom of the camera support
- Position the camera support so that the camera is directed toward the center of the opposite frame edge
- Glue the camera support to the base
2. Adjust the camera focus
- Connect to Raspberry Pi board through SSH
- Enter the following command
libcamera-vid --qt-preview
- Adjust camera focus until you clearly see the book page
Build the Book Support
- Print two clips (Support.stl)
- Cut two pieces of Plexyglass 17.4 cm x 17 cm
- Glue the two pieces of Plexiglass with the supports
- Glue a small metal clip. The clip must match the position of the joystick on the Sense HAT
Downloads
Test
- Connect the USB-C power supply
- Place a book on the clip
- Wait until Bookwise says "Done"
- Remove the book
- Listen to the abstract of the last page you read