-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetect.py
More file actions
51 lines (38 loc) · 1.4 KB
/
Detect.py
File metadata and controls
51 lines (38 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import csv
import boto3
import json
import argparse
class Detect:
def __init__(self, bucket, photo):
self.bucket = bucket
self.photo = photo
def GetClient(self):
with open ('credentials.csv', 'r') as input:
next(input)
reader = csv.reader(input)
for line in reader:
access_key_id = line[2]
secret_access_key = line[3]
client = boto3.client('rekognition',
aws_access_key_id = access_key_id,
aws_secret_access_key = secret_access_key)
return client
def DetectViolation(self):
client = self.GetClient()
response = client.detect_moderation_labels(Image={'S3Object':{'Bucket':self.bucket,'Name':self.photo}})
print('Detected labels for ' + self.photo)
for label in response['ModerationLabels']:
print (label['Name'] + ' : ' + str(label['Confidence']))
print (label['ParentName'])
response = len(response['ModerationLabels'])
def main():
ap = argparse.ArgumentParser()
ap.add_argument("-b", "--bucket", type=str, required=True,
help="S3 bucket name")
ap.add_argument("-p", "--photo", type=str, required=True,
help="Photo")
args = vars(ap.parse_args())
obj = Detect(args['bucket'], args['photo'])
obj.DetectViolation()
if __name__ == "__main__":
main()