-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
54 lines (30 loc) · 950 Bytes
/
lambda_function.py
File metadata and controls
54 lines (30 loc) · 950 Bytes
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 tflite_runtime.interpreter as tflite
from keras_image_helper import create_preprocessor
preprocessor = create_preprocessor('xception', target_size=(299, 299))
interpreter = tflite.Interpreter(model_path='sign_language_model.tflite')
interpreter.allocate_tensors()
input_index = interpreter.get_input_details()[0]['index']
output_index = interpreter.get_output_details()[0]['index']
labels = {
0: 0,
1: 1,
2: 2,
3: 3,
4: 4,
5: 5,
6: 6,
7: 7,
8: 8,
9: 9
}
#url = {'url' : 'https://raw.githubusercontent.com/Olawuwo2000/sign-language/main/img_3455.jpg'}'
def predict(url):
x = preprocessor.from_url(url)
interpreter.set_tensor(input_index, x)
interpreter.invoke()
preds = interpreter.get_tensor(output_index)
return dict(zip(labels, preds[0]))
def lambda_handler(event, context):
url = event['url']
result = predict(url)
return result