Remaking the Bookshelf With AI!

by PiGuy163 in Circuits > Gadgets

634 Views, 6 Favorites, 0 Comments

Remaking the Bookshelf With AI!

AI.png

Hello! My name is Daniel B and I am a Year 11 student in the UK, in this Instructable I will show you how I redesigned my bookshelf to incorporate artificial intelligence, and how you can do the same.

The Idea


When you think of things that could do with a redesign, bookshelves probably wouldn't rank very high on your list. However, at at time when almost everything has been re-imagined with technology (even toothbrushes and soap dispensers!), I wondered why the same couldn't be said for the humble bookshelf too? Sure, you can just grab a good book straight from the shelf, but what about that when you're filled with the inevitable indecision about what to read? How about that feeling when you love a book so much you're itching to find something with the same thrill? For that reason, I knew there must be a way to add a modern AI upgrade to a timeless concept!

Supplies

Webcam(1).png
  • Raspberry Pi or other small computer (I recommend at least a pi 4)
  • MicroSD Card - I recommend at least 8GB
  • USB Webcam - this is much better with a manual focus, more on this later
  • Type-C Power Supply
  • Android Tablet/Phone to run companion app. (this doesn't have to be too powerful or modern!)
  • Enclosure for Pi - optional, but recommended
  • Bookshelf (yes, really!)

Design

Screenshot from 2024-04-23 20-20-10.png

I started by creating a rough design in Tinkercad to set out the main objectives. I decided I wanted the design to be:

  • Non-intrusive
  • Easy to use
  • Accessible (no touch necessary)
  • Simple - no unnecessary steps to use the device
  • Made of few parts - ideally only using parts I already owned

I planned for a small box for barcode scanning and a tablet to display recommendations and collected data. Ideally the design shouldn't be more complex than it needs to be, and so I want to avoid any unnecessary features that could cause problems. I chose the Raspberry Pi as the brain of the project for its small size yet modest computational power. Its official Linux distribution makes software support makes it an ideal candidate for writing software, and its OpenCV performance is pretty well documented. For the tablet, I found a dead Amazon Kindle that I could repair, and for the app I decided on Flutter, a framework I have quite a bit of experience with. I decided that the server should use python to read the ISBN and look up the book's information on google books before using a LLM to recommend books.

Scanner - Hardware

Manual-focus Webcam.png
raspberry-pi-4-model-b-4-gb.png
official-uk-raspberry-pi-4-power-supply-5-1v-3a-raspberry-pi-sc0212-7009471070270_700x.jpg

The first thing I needed was a case for the Pi. For this I used the case of an old TV box which fitted well. I flashed a 32GB MicroSD card with Raspberry Pi OS Lite to avoid unnecessary CPU load from the desktop from impacting performance, and put it into the pi in its new case. The semi-transparent front of the enclosure allowed for the power and CPU activity LEDs to check that the scanner is actually switched on, and its robust plastic and convenient IO at the rear made it perfect for a bookshelf where it could be accidentally knocked.

After this, I used the rear AUX port of the box to channel the cable for the webcam. If you decide to try this at home, you should search for a webcam which allows manual focussing, I used a cheap unbranded one I had lying around. It is important to set the focus with a close object to ensure that barcode scanning is as accurate (and fast) as possible.

Originally, I planned to use a pre-made barcode scanner like this, but these were not particularly cheap and I wanted to avoid using new parts where possible to minimise requirements for anyone wishing to create their own.

Another important consideration for this build is the power supply; if using a raspberry pi you will need a stable 5v type-c plug that can deliver up to 3A to account for power usage spikes, I would recommend the official adapter.

User Interface - Hardware

PCB repair.png
IMG_20240409_165646.jpg
s-l400.jpg

Repairing the tablet


As I mentioned in step 1, I decided on an Amazon Kindle Fire to run the user interface. These tablets are well established as cheap but reliable android devices, and I was recently given a dead one that I've been meaning to repurpose for a while. You can most likely skip this step if you have a working android device, but to get mine working I had to first repair the charging circuit.

After inspecting the charging port, I saw several bent pins which would be difficult to restore. This meant my original plan to simply fix the port would not work, and I needed another solution. Instead I decided to bypass the charging circuit altogether, soldering to pads on the back of the device instead. I used the pads labelled "ID" for ground and "VBUS" for 5V power, and connected a USB cable to them to supply 5V to the charging IC.


Android Magic


FireOS devices run a modified version of android which works in fundementally the same way. Because of the damaged USB port I could only transfer the app's package file to the kindle via Wi-Fi, and for this I used the build in http server python module on my laptop by running the following command:

python3 -m http.server

After this I used the Silk Browser app to download the file and install the app. I also configured it to open on boot, further reducing the need to physically interact with the tablet and so improving accessibility.

User Interface - Software

Screenshot from 2024-04-29 20-40-37.png
Screenshot from 2024-04-29 20-43-40.png

[Images: Left=design template, right=final app]

[Note: All of the code for this project can be found in my git repo]


I wanted the interface to be simple, easy to use, and with minimal interaction needed for accessibility reasons as stated in the introduction. I started the design process with a simple template I created on Canva as shown in the first image. I used a red accent colour to add some contrast, and included details about the recommended book. After writing an app and playing around with styling in Flutter, I reached a result that looked similar enough to the design with some minor changes that you can see in the second image. I also integrated TTS (text to speech) to read aloud the suggestion, which is again better for accessibility.


After compiling the app to an APK (android package) and running some tests, I found that the app ran nicely on the kindle. The text to speech was effective, and updating the data dynamically worked fine. As the app is written in flutter, it can also be compiled to the web, so it would be possible to run it on even older tablets such as early-generation iPads or other devices which would likely otherwise end up as e-waste (it can even be compiled to the web to run on a samsung smart freezer if for some crazy reason you wanted to!!).

Scanner - Software

Screenshot from 2024-04-29 21-33-39.png
carbon(1).png
isbn_square.jpeg

Code Link

The scanner's software is relatively simple. I decided on OpenCV to capture and process video, and pyzbar to detect and convert barcodes.

After implementing this, I used researched how barcodes on books work. They use a unique identifier known as an ISBN (international standard book number) which I processed in the script using the library pyzbar. This module can also verify that a book has been scanned correctly by using its check digit. You can see an example of ISBN numbers in the third image.

Finally, I used the "requests" python library and the Huggingface Serverless Inference API to run a LLM query to recommend a book. The prompt took a few iterations and I experimented with a few models, but eventually I found that the best combination which almost never lead to hallucinations of books which didn't exist from the model was Mixtral-8x7B-Instruct-v0.1 with the prompt in the second image. To connect the UI, I used a separate python file that read from the result, and served it over a HTTP API using the Flask module.

Here is a list of all the modules and services used on the scanner:


In order to start running all the python scripts on booting the Pi, I created a shell script and added it to my "/etc/rc.local" file which contains commands to run after booting up. This also minimised required interactivity so that in the case of a potential power failure the system doesn't need to be restarted manually.

Due to the impressive GPU hardware hosted by Huggingface, recommendation speeds are generally very good (I can often get a book recommended within about 5 seconds). The slowest part of the process is probably the google books API, although I cannot find a more efficient way to retrieve data about books.

Evaluation

AI Bookshelf demo

[Video: Brief demo of the final system (sorry for phone recording!)]

Reflecting the initial objectives I set out to begin with, I'd say that most if not all of the requirements were met. Firstly, repurposing existing materials and devices was a cost-effective (and definitely more sustainable) approach. Using an old TV box for the Raspberry Pi enclosure and resurrecting a damaged Amazon Kindle Fire not only minimized cost but also breathed new life into discarded electronics.

Furthermore, by focusing on simplicity and accessibility I would say that I created user-friendly experience, making this redesign effective and easy to use. The non-intrusive aesthetic seamlessly works with pretty much any bookshelf, while the interface requires minimal interaction, making it accessible to users of all abilities.

I think an AI bookshelf is a novel and creative improvement, and something I would actually want to use myself. If I were to make improvements, I would want a more reliable barcode scanner than a webcam and a more finely-tuned language model, however I am happy with the results. I hope that you can follow this guide, even if you have a different approach or goals than me, to give your bookshelf a cohesive and innovative rethink. If you do make your own version, please show me in the comments, I'd love to how you spin this project!

Good luck, and happy making!