AWS – Google Perspective API.
Table Of Content:
- What is Google Perspective API?
- How Does It Work?
- What Attribute It Can Detect ?
- Example Request & Response.
- Use Cases Of Google Perspective API.
- Limitations Of Google Perspective API.
(1) What Is Google Perspective API?
(2) How Does Google Perspective API Works?
(3) What Attribute Google Perspective API Detect ?
(4) Example Request & Response
import requests
import json
# Replace with your actual Perspective API key
API_KEY = "YOUR_API_KEY"
API_URL = f"https://commentanalyzer.googleapis.com/v1alpha1/comments:analyze?key={API_KEY}"
# The comment you want to analyze
comment_text = "I hate you and I will find you!"
# Attributes to analyze
attributes = {
"TOXICITY": {},
"SEVERE_TOXICITY": {},
"INSULT": {},
"THREAT": {},
"PROFANITY": {},
"IDENTITY_ATTACK": {}
}
# Payload for the POST request
data = {
"comment": {"text": comment_text},
"languages": ["en"],
"requestedAttributes": attributes
}
# Send the request
response = requests.post(API_URL, headers={"Content-Type": "application/json"}, data=json.dumps(data))
# Parse and display results
if response.status_code == 200:
result = response.json()
print(f"Comment: {comment_text}")
print("Attribute Scores:")
for attr, score_data in result['attributeScores'].items():
score = score_data['summaryScore']['value']
print(f" {attr}: {score:.2f}")
else:
print(f"Request failed: {response.status_code}")
print(response.text) (5) Use Cases Of Google Perspective API.
(6) Limitations Of Google Perspective API?

