Skip to content

Instantly share code, notes, and snippets.

Last active Oct 25, 2018
What would you like to do?
Scarefai Flask App -- Clarifai + Twilio
from flask import Flask, request
from twilio.twiml.messaging_response import MessagingResponse
from clarifai_tagger import get_concept_tags
app = Flask(__name__)
#this is a list of concepts we will look for among all possible Clarifai concepts
spooky_concepts = ['scary','eerie','dark','monochrome','spider','spiderweb',
@app.route('/sms', methods=['POST'])
def sms_reply():
# Create a MessagingResponse object to generate TwiML.
resp = MessagingResponse()
print("Sender: " + request.form['From'])
# See if the number of images in the text message is greater than zero.
if request.form['NumMedia'] != '0':
# Grab the image URL from the request body.
image_url = request.form['MediaUrl0']
relevant_tags = get_concept_tags(image_url)
### Compare returned tags to pre-identified spooky concepts
spooky_tags = set(spooky_concepts).intersection(set(relevant_tags))
if len(spooky_tags) >= 1:
resp.message('Spooooookiness detected! ' + str(spooky_tags))
resp.message("Didn't trigger my spook detectors.")
resp.message('Please send an image. :)')
return str(resp)
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment