After watching the latest episode of HBO’s Silicon Valley and seeing the Not Hotdog iOS app that was built, I wanted to see if I could build the same thing as a Twitter bot.
First, I forked @BryanEBraun’s awesome open source, Node Twitter bot. It was set up to retweet everything from a specific list. My first task was setting it up to auto-reply to tweets that mentioned my bot, IsItAHotdog. First I started listening to any tweets with my handle using Twitter’s streaming API and the tuiter NPM package
function listen() {tu.filter({track: 'isitahotdog'}, function(stream) {console.log("listening to stream");stream.on('tweet', onTweet);});}
Then I only reply to the ones that have images
if(tweet.entities.hasOwnProperty('media') && tweet.entities.media.length > 0)
Finally, I use tuiter to tweet out a reply
tu.update({status: "@" + tweet.user.screen_name + message,in_reply_to_status_id: tweet.id_str}, onReTweet);
Next I needed to make the actual classification. Originally I was going to collect images and train a Keras CNN, but I decided to get something running with AWS Rekognition first. I’d still like to return to this and train my own net.
Using Rekognition was really simple. I just downloaded the image from Twitter onto my server, passed the bytes to Rekognition through the AWS Node SDK, and then got classification results.
rekognition.detectLabels(params, function(err, data) {
It was able to label images with hot dogs in them very consistently. Once I threw in some logic to tweet the correct message, I had everything working. I threw my bot on Heroku and started sharing it around. Here are some sample tweets:
It’s really crazy how quickly you can build something like this with all of the great open source tools and web services available. Try tweeting something at it yourself! Also, check out the rest of my code here.