<jupyter_start><jupyter_text>This notebook demonstrates the various Rekognition APIs<jupyter_code>from pprint import pprint
import boto3

items_to_show = 1

rekognition_client = boto3.client('rekognition')

print('Detecting faces')

with open('data/rek_sample_face.jpeg', 'rb') as img_file:
    sample_image = {'Bytes': img_file.read()}

faces = rekognition_client.detect_faces(Image=sample_image, Attributes=['ALL'])
pprint(faces['FaceDetails'][:items_to_show])
print('Detecting labels')
max_labels = 10
items_to_show = 10

with open('data/rek_sample_label.jpeg', 'rb') as img_file:
    sample_image = {'Bytes': img_file.read()}
    
labels = rekognition_client.detect_labels(Image=sample_image, MaxLabels=max_labels)
pprint(labels['Labels'][:items_to_show])
print('Detecting text')

with open('data/rek_sample_text.jpeg', 'rb') as img_file:
    sample_image = {'Bytes': img_file.read()}
    
text = rekognition_client.detect_text(Image=sample_image)
pprint(text['TextDetections'])
print('Detecting celebrities')

# Save a picture with celebrities you want  

with open('data/rek_sample_celebrity.jpeg', 'rb') as img_file:
    sample_image = {'Bytes': img_file.read()}
    
celebrities = rekognition_client.recognize_celebrities(Image=sample_image)
pprint(celebrities)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12779060816012316, 'fraction_numerical': 0.005388760585065435, 'mean_word_length': 7.496732026143791, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '94212', 'license': 'MIT', 'n_tokens_mistral': 474, 'n_tokens_neox': 442, 'n_words': 81, 'path': 'Chapter12/.ipynb_checkpoints/rekognition-checkpoint.ipynb', 'repo_name': 'PacktPublishing/The-Machine-Learning-Solutions-Architect-Handbook', 'size': '1299'}