Created
April 24, 2019 20:26
-
-
Save kunal732/dee523908e80685bf791f91022610a0f to your computer and use it in GitHub Desktop.
for webinar
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
import boto3 | |
import base64 | |
from chalice import Chalice | |
app = Chalice(app_name='example1') | |
@app.on_s3_event(bucket='rekogvtug') | |
def handler(event): | |
print("Object uploaded for bucket: %s, key: %s" % (event.bucket, event.key)) | |
#Python code for Rekognition | |
fileName=event.key | |
bucket=event.bucket | |
client=boto3.client('rekognition') | |
response = client.detect_labels(Image={'S3Object':{'Bucket':event.bucket,'Name':event.key}}) | |
print('Detected labels for ' + event.key) | |
for label in response['Labels']: | |
print (label['Name'] + ' : ' + str(label['Confidence'])) | |
@app.route('/sms', methods=['POST']) | |
def results(): | |
client =boto3.client('rekognition') | |
resp = MessagingResponse() | |
if request.form['NumMedia'] != '0': | |
image_url = request.form['MediaUrl0'] | |
response = client.detect_labels(Image={'Bytes':base64.b64encode(requests.get(url).content)}) | |
for label in response['Labels']: | |
resp.message('n'.join(label['Name'])) | |
else: | |
resp.message('Please send an image.') | |
print(str(resp)) | |
return str(resp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment