Happy Curry'in with Epicurean. (Or how chat-bots solve practical problems.)
Sanjay Bhatikar
Digital Innovation With Deep Learning, Computer Vision and Operations Research
We like to eat healthy by cooking at home. Picking up fresh ingredients on the daily commute is a time-saver and avoids waste. But we are often guessing what's in the pantry at home and what we need to get to plan the day's meal. What if we had a robot do the due-diligence and make a recommendation, wouldn't that be great?!
Mobility is key. But building an app for the mobile app-store involves software development effort beyond a weekend project. A better approach is to use an existing platform and fit it out to the requirement. Sounds like a job for a chat-bot!
Bots are just special accounts that subscribers can interact with. Any subscriber can create a bot. A bot can respond to text messages and commands. However, a bot can never initiate conversations with users. (Otherwise the Universe would be awash with spam.)
I picked Telegram to implement a chat-bot. As an app, Telegram is an instant messaging software like WhatsApp. Unlike WhatsApp, Telegram has an awesome API. And unlike WhatsApp, the platform actively encourages bots. And unlike WhatsApp, it isn't owned by Facebook. ;-)
The python-telegram-bot project offers the means to program a bot in Python. Aside from support for the base API that a developer would expect to find, the telegram.ext sub-module offers cool features in modern programming style for automation with queues, filters and handlers. It is a fantastic way to program in the DRY style advocated in The Practical Programmer and a natural choice for my Epicurean bot.
For querying recipes, I selected the Spoonacular Food API. The free account works on a points system with a fixed daily quota. Points are deducted per query made depending on the API end-point used. The Spoonacular API offers access to a comprehensive database of world-wide cuisines with smart querying based on Natural Language Processing (NLP).
So after a weekend of programming in the COVID-19 curfew, here is what the product looks like. If you have Telegram on your phone, strike up a chat with Epicurean a.k.a. @epicurryin_bot. Type /start in the message box and follow instructions. You don't even have to say hello!
Here is a snap-shot showing Epicurean's recommendations in Telegram chat based on what's in my fridge today.
My bot will build a recipe for you based on the ingredients you provide and tastefully present it as a recipe card. Here is a sample recipe card I got for dal (Indian lentils), onions and carrots. It is pretty impressive how effortlessly the Spoonacular API uses NLP to bridge-over different languages and culinary idioms.
And it even tells a dirty joke or two! Send a /joke command to get a random joke when the kids are not around.
So what's next? I plan to enhance the bot to make the engagement style more conversational. A little further down the road, I want to merge this project with another side-project I have going on to identify food items in the refrigerator using computer vision on a Raspberry Pi with a Picamera. Then, our fridge will chat with us about our meal plan. Tasty!
Happy curry'in with Epicurean!
References:
- Take a look at my code posted in this Github repo with a Jupyter notebook that has step-step instructions to build your own bot.
- The Spooncular API has excellent docs.
- A vibrant community has developed around Telegram in Python to help each other and share examples and code snippets.
- RapidAPI presents a browser-based interface to test API end-points - a great way to become familiar with APIs and their usage. You can search their collection of food-related APIs or try your hand at Spoonacular APIs.
- The Telegram bots overview has general information about bots and to find out what they are capable of.
- The Pragmatic Programmer by Andrew Hunt and David Thomas is one of the most influential computer programming books of all time.