-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadk_algorithms.py
More file actions
52 lines (36 loc) · 1.32 KB
/
adk_algorithms.py
File metadata and controls
52 lines (36 loc) · 1.32 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
52
import Algorithmia
import base64
import os
# -- Apply functions --- #
def apply_basic(input):
return "hello " + input
def apply_binary(input):
if isinstance(input, bytes):
input = input.decode('utf8')
return bytes("hello " + input, encoding='utf8')
def apply_input_or_context(input, model_data=None):
if model_data:
return model_data.data()
else:
return "hello " + input
def apply_successful_manifest_parsing(input, model_data):
if model_data:
return "all model files were successfully loaded"
else:
return "model files were not loaded correctly"
# -- Loading functions --- #
def loading_text(modelData):
modelData['message'] = 'This message was loaded prior to runtime'
return modelData
def loading_exception(modelData):
raise Exception("This exception was thrown in loading")
def loading_file_from_algorithmia(modelData):
modelData['data_url'] = 'data://demo/collection/somefile.json'
modelData['data'] = modelData.client.file(modelData['data_url']).getJson()
return modelData
def loading_with_manifest(modelData):
modelData["squeezenet"] = modelData.get_model("squeezenet")
modelData['labels'] = modelData.get_model("labels")
# optional model
modelData['mobilenet'] = modelData.get_model("mobilenet")
return modelData