Last active
October 25, 2018 08:38
-
-
Save everling-prime/65e8eff166f66bb0f2e4691d1c27b60f to your computer and use it in GitHub Desktop.
Scarefai Flask App -- Clarifai + Twilio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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