예제 #1
0
def invoke(request):
    with monitor(labels=_labels, name="invoke"):
        request_str = request.decode('utf-8')
        avatar_url = json.loads(request_str)['sender']['avatar_url']
        github_login = json.loads(request_str)['sender']['login']
        classification_response = inception.invoke(avatar_url)

        classification_response_json= json.loads(classification_response)

        classification_response_formatted = '\\n '.join("%s%%\t%s" % (str((100 * item['score']))[0:4], item['name']) for item in classification_response_json)

        cmd = 'curl -X POST --data-urlencode "payload={\\"unfurl_links\\": true, \\"channel\\": \\"#community\\", \\"username\\": \\"pipelineai_bot\\", \\"text\\": \\"%s has starred the PipelineAI GitHub Repo!\n%s\nTheir avatar picture is classified as follows:\n%s\nTo classify your avatar picture, star the PipelineAI GitHub Repo @ https://github.com/PipelineAI/pipeline\\"}" https://hooks.slack.com/services/T/B/o' % (github_login, avatar_url, (classification_response_formatted or ''))
        response = subprocess.check_output(cmd, shell=True).decode('utf-8')

# https://github.com/alexellis/faas-twitter-fanclub/blob/master/tweet-stargazer/handler.py
#
#        auth = tweepy.OAuthHandler(os.environ["consumer_key"], os.environ["consumer_secret"])
#        auth.set_access_token(os.environ["access_token"], os.environ["access_token_secret"])
#        github_login = json.loads(request_str)['sender']['login']
#        api = tweepy.API(auth)
#        api.update_with_media('%s' % filename, '%s' % github_login)

        filename = avatar_url.split('/')
        if filename:
            idx = len(filename) - 1
            filename = filename[idx]
            if os.path.exists('inception/%s' % filename):
                os.remove('inception/%s' % filename)

        return {'response': response}
예제 #2
0
 def do_GET(self):
     try:
         query_components = parse_qs(urlparse(self.path).query)
         imageUrl = query_components.get('imageUrl')
         if imageUrl is None:
             self.send_response(400)
             self._set_headers()
             self.wfile.write(
                 json.dumps({
                     'error': 'imageUrl parameter required'
                 }).encode('utf-8'))
             return
         imageUrl = imageUrl[0]
         print('imageUrl to download --> %s' % (imageUrl))
         result = inception.invoke(imageUrl)
         self.send_response(200)
         self._set_headers()
         self.wfile.write(result.encode('utf-8'))
     except Exception as err:
         print("Error {}".format(err))
         self.send_response(400)
         self._set_headers()
         self.wfile.write(json.dumps({'error': str(err)}).encode('utf-8'))
예제 #3
0
# Copyright (c) Alex Ellis 2017. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

import sys
#from function import handler
import inception


def get_stdin():
    data = sys.stdin.buffer.read()
    return data


if (__name__ == "__main__"):
    st = get_stdin()
    #handler.handle(st)
    print(inception.invoke(st))
예제 #4
0
def handle(body):
    return inception.invoke(body)