-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_mlmodel.py
55 lines (51 loc) · 1.42 KB
/
create_mlmodel.py
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
from ctes import AT_CONTEXT
from ctes import URL_ENTITIES
import requests
import json
MLMODEL_UUID = 'urn:ngsi-ld:MLModel:d490e4ec-a007-493a-ba16-d00ed0ddd578'
MLMODEL_NAME = "Consumption prediction"
MLMODEL_DESCRIPTION = "Consumption prediction from litres information on a specific DMA"
MLMODEL_ALGORITHM = "Multi-Layer Perceptron"
MLMODEL_VERSION = 0.2
MLMODEL_PREDICT_URL = "http://127.0.0.1:5000/predict"
HEADERS = {
'Content-Type': 'application/ld+json'
}
# Template for a MLModel entity, adapt the variables above
json_d = {
'@context': AT_CONTEXT,
'id': MLMODEL_UUID,
'type': 'MLModel',
'name': {
'type': 'Property',
'value': MLMODEL_NAME
},
'description': {
'type': 'Property',
'value': MLMODEL_DESCRIPTION
},
'algorithm': {
'type': 'Property',
'value': MLMODEL_ALGORITHM
},
'version': {
'type': 'Property',
'value': MLMODEL_VERSION
},
'inputAttributes': {
'type': 'Property',
'value': ['litres']
},
'outputAttributes': {
'type': 'Property',
'value': 'consumption'
},
'bentoPredictUrl': {
'type': 'Property',
'value': MLMODEL_PREDICT_URL
}
}
r = requests.post(URL_ENTITIES, json=json_d, headers=HEADERS)
print(f'Status code creation of MLModel entity: {r.status_code}')
if (r.status_code != 201):
print(f'Error response is {json.dumps(r.json(), indent=2)}')