File size: 1,843 Bytes
8b26614
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
from handler import EndpointHandler
import json

# init handler
my_handler = EndpointHandler(path=".")

import base64

# prepare sample payload
# non_holiday_payload = {"inputs": "I am quite excited how this will turn out", "date": "2022-08-08"}
# holiday_payload = {"inputs": "Today is a though day", "date": "2022-07-04"}

# with open('sample_input.json', 'r') as file:
#     data = json.load(file)
import io
from PIL import Image
import requests
response = requests.get('https://mystore-12345-product-images.s3-us-east-2.amazonaws.com/0c817b58-2774-4f02-95b8-3ae379aa2e98.jpeg')
image = Image.open(io.BytesIO(response.content)).convert('RGB')

response2 = requests.get('https://mystore-12345-product-images.s3-us-east-2.amazonaws.com/3b9c698b-b7ae-4c5d-a978-2179ccc08d12.jpeg')
image2 = Image.open(io.BytesIO(response2.content)).convert('RGB')

response3 = requests.get('https://mystore-12345-product-images.s3-us-east-2.amazonaws.com/72801dfa-5d6a-442e-91cd-80bdb394a323.jpeg')
image3 = Image.open(io.BytesIO(response3.content)).convert('RGB')

pil_images = [image.copy() for i in range(10)]
pil_images[1] = image2.copy()
pil_images[2] = image3.copy()

base64_strings = []
for output_image in pil_images:
    buffered = io.BytesIO()
    output_image = output_image.convert('RGB')
    output_image.save(buffered, format="png")
    img_str = base64.b64encode(buffered.getvalue())
    base64_strings.append(img_str)

inputs = {
    'image': base64_strings
}


# test the handler
import time 
start =  time.time()
prediction=my_handler(inputs)
# holiday_payload=my_handler(holiday_payload)
print("inference time itself is", time.time() - start)

# show results
# print("prediction", prediction)

print("type of prediction", type(prediction))

data_json = prediction


print("type of prediction", data_json.keys())

img_str = data_json['image']