Skip to content

Instantly share code, notes, and snippets.

@everling-prime everling-prime/app.py

Last active Oct 25, 2018
Embed
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',
'arachnid','phobia','fog','mystery','shadow','abandoned',
'storm','pumpkin','jack-o-lantern','Halloween','dusk','skull',
'calamity','Fall','danger','satan','horror','vicious','ghost',
'haunt','cemetery','fright']
@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))
else:
resp.message("Didn't trigger my spook detectors.")
else:
resp.message('Please send an image. :)')
return str(resp)
if __name__ == '__main__':
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.