Analyze images and automatically add descriptive labels such as:
for sqs_record in event.get('Records', []):
try:
# Parse S3 event from SQS message body
s3_event = json.loads(sqs_record['body'])
# Process each S3 record in the event
for s3_record in s3_event.get('Records', []):
try:
# Extract S3 information
bucket = s3_record['s3']['bucket']['name']
key = s3_record['s3']['object']['key']
Detect and prioritize important labels:
# Detect and prioritize labels
labels_data = detect_labels_in_image(bucket, key)
if not labels_data:
print("No labels detected after prioritization")
results['failed'] += 1
continue
Update article with tags and save to Gallery:
# Update article
success = update_article_with_tags(article_id, labels_data)
if success:
results['succeeded'] += 1
# Save to Gallery tables
try:
import sys
import os
# Add current directory to path
current_dir = os.path.dirname(os.path.abspath(__file__))
if current_dir not in sys.path:
sys.path.insert(0, current_dir)
from save_to_gallery import save_photo_to_gallery, update_trending_tags
tag_names = [label['name'] for label in labels_data]
image_url = key # S3 key
photo_id = key # Use S3 key as unique identifier
save_photo_to_gallery(
photo_id,
image_url,
tag_names,
status='public',
article_id=article_id
)
update_trending_tags(tag_names, image_url)
print("✓ Saved to Gallery tables")
After successful processing, data is stored in DynamoDB tables:
