The data upload API can be used to upload examples of images and texts to an AI Block, either in the “Unlabelled” bucket or in a specific label.
If no label is specified in the headers, then the example is uploaded to the “Unlabelled” bucket. Otherwise, if a “labels” item is specified, the example is uploaded to the specific label.
Uploading to the AI Block examples on which the model made a live prediction with a low confidence score (<75%), then re-labelling those examples and re-training is an effective strategy to improve model performance.
The following lines of code in python serve as examples.
## Image, "Unalabelled" bucket
import requests
import json
# the Token is visible in the API box within the Connect page of the AI Block
# the aiblockid is taken from the url of the block https://app.levity.ai/blocks/<aiblockid>/integrate
response = requests.post('https://upload.levity.ai/upload/labelled-image/',
files={'file': open('<file_name>','rb')},
headers={
"Authorization": "Token <Token>",
'aiblockid': '<aiblockid>'
})
print(response.json())
## Image, specific label
import requests
import json
# the Token is visible in the API box within the Connect page of the AI Block
# the aiblockid is taken from the url of the block - https://app.levity.ai/blocks/<aiblockid>/integrate
# the label ID is visible in the url of the block, after clicking on the relevant label in the Build tab - https://app.levity.ai/blocks/<aiblockid>/organise/<labelid>
response = requests.post('https://upload.levity.ai/upload/labelled-image/',
files={'file': open('<file_name>','rb')},
headers={
"Authorization": "Token <Token>",
'aiblockid': '<aiblockid>',
'labels': '<labelid>'
})
print(response.json())
## Text, "Unalabelled" bucket
import http.client
import json
# the Token is visible in the API box within the Connect page of the AI Block
# the aiblockid is taken from the url of the block https://app.levity.ai/blocks/<aiblockid>/integrate
conn = http.client.HTTPSConnection("upload.levity.ai")
payload = json.dumps({
"text": "This is a negative comment. bci4What do you think?"
})
headers = {
'Authorization': 'Token <Token>',
'aiblockid': '<aiblockid>',
'Content-Type': 'application/json',
}
conn.request("POST", "/upload/labelled-text/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
## Image URL, "Unalabelled" bucket
import http.client
import json
# the Token is visible in the API box within the Connect page of the AI Block
# the aiblockid is taken from the url of the block https://app.levity.ai/blocks/<aiblockid>/integrate
conn = http.client.HTTPSConnection("upload.levity.ai")
payload = json.dumps({
"url": "<url>"
})
headers = {
'Authorization': 'Token <Token>',
'aiblockid': '<aiblockid>',
'Content-Type': 'application/json'
}
conn.request("POST", "/upload/labelled-image-url/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))