Kategorien
AI

AWS Comprehend: connecting with python

When you start adding AI services, python is handy to help with simple connection tools. Today: boto3

This is the simple connect I wrote, you can also get it on my github:

#!/usr/bin/python3
# python file to ask amazon comprehend for sentiment
import boto3

# Replace the following with your own AWS access key ID and secret key
aws_access_key_id = "YOUR AWS KEYID"
aws_secret_access_key = "YOUR AWS KEY"

# Create a boto3 client for the Amazon Comprehend API
comprehend_client = boto3.client("comprehend", aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)

# Use the Amazon Comprehend API to analyze some text

text = "Danke, das haben Sie gut gemacht."
response = comprehend_client.detect_sentiment(Text=text, LanguageCode="de")

# Print the detected sentiment
print(response["Sentiment"])

Its simple an straight forward. To get it up and runninf have the follwoing prerequsitites in place:

  1. You need AWS console access
  2. Create program based IAM Access to group AWS comprehend edit
  3. Install python3, pip, awscli
  4. Edit .aws config to use a region, e.g. eu-central-1
  5. pip install boto3

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.