Welcome to the UBIAI Developer Documentation! This guide is designed to help developers integrate and utilize UBIAI's APIs effectively. UBIAI provides a cutting-edge text labeling platform for natural language processing. By leveraging our APIs, developers can enhance their applications with advanced AI capabilities.
import requests
import json
url ="https://api.ubiai.tools:8443/api_v1/project"
headers = {"Authorization": "Token put_your_acess_token"}
project_name = ""
# must be one of these values:
# 'Chinese', 'Danish', 'Dutch', 'English', 'French'
# 'German', 'Greek', 'Italian', 'Lithuanian', 'Multi-language',
# 'Norwegian Bokmål', 'Polish', 'Polish', 'Romanian', 'Spanish',
# 'Afrikaans', 'Albanian', 'Arabic', 'Armenian', 'Basque',
# 'Bengali', 'Bulgarian', 'Catalan', 'Croatian', 'Czech'
# 'Estonian', 'Finnish', 'Gujarati', 'Hebrew', 'Hindi', 'Hungarian', 'Tamil'
language = "English"
description = ""
# project type must be 'Text Annotation' for span based
# 'Character Based Annotation' for character based
# 'Native PDF Annotation' for ocr
# 'Image Classification'
project_type = "Text Annotation"
# label object must be in this format {'text': 'example', 'shortcut': '1'}
entities_labels = []
# label object must be in this format {'text': 'example', 'shortcut': '1'}
relations_labels = []
# classification_type must be 'binary' for positive or negative
# 'single' for single classification
# 'multi' for multi classifications
classification_type = "Binary"
# fill this only when classification type is different then binary
# label object must be in this format {'text': 'example', 'shortcut': '1'}
classifications_labels = []
project = {
"name": project_name,
"language": language,
"description": description,
"type": project_type,
"entities_labels" : entities_labels,
"relations_labels": relations_labels,
"classification_type": classification_type,
"classifications_labels": classifications_labels
}
response = requests.post(url , json=project, headers=headers)
if response.status_code == 200:
# Access the response content
data = json.loads(response.content.decode("utf-8"))
print("Response Data:", data)
else:
# Handle the error
print("Error:", response.status_code, response.text)
Annotate project
import requests
# Define the API endpoint with token and file_type in the URL
api_url = "https://app.ubiai.tools:8443/api_v1/annotate_project/{token}/{project_id}"
# Replace placeholders with actual values
api_url = api_url.format(token="your_access_token", project_id="your_project_id")
# Make a POST request to the API with headers and files
response = requests.post(api_url)
# Check the response
if response.status_code == 200:
# Access the response content
data = json.loads(response.content.decode("utf-8"))
print("Response Data:", data)
else:
# Handle the error
print("Error:", response.status_code, response.text)
Annotate snippets
import requests
import json
url ="https://api.ubiai.tools:8443/api_v1/annotate"
my_token = "/put-your_acess_token"
data = {
# inputs is a list of text
"inputs" : ["John works at Google.",
"John works at Google." ],
# entities is a list of list
# Each list is a list of dict
# Each dict must have this format :
# {start : represent the offset of the start character
# end : represent the offset of the end character + 1
# label : represent the label of entity}
"entities" : [
[{'start': 0, 'end': 4, 'label': 'PER'},
{'start': 14, 'end': 20, 'label': 'COMPANY'}],
[{'start': 0, 'end': 4, 'label': 'PER'},
{'start': 14, 'end': 20, 'label': 'COMPANY'}]]}
response = requests.post(url+ my_token,json= data)
print(response.status_code)
res = json.loads(response.content.decode("utf-8"))
print(res)
Export data
import requests
# Define the API endpoint with token and file_type in the URL
api_url = "https://app.ubiai.tools:8443/api_v1/download/{token}/{type}"
# Replace placeholders with actual values
api_url = api_url.format(token="your_model_token", type="aws/Lists")
split_ratio = ""
params = {'splitRatio': split_ratio}
# Make a GETrequest to the API with headers and files
response = requests.get(api_url, params=params)
# Check the response
if response.status_code == 200:
# Access the response content
data = json.loads(response.content.decode("utf-8"))
print("Response Data:", data)
else:
# Handle the error
print("Error:", response.status_code, response.text)
Download options
Type options
aws/Lists
spacy/Json
DocBin_NER/Json
spacy_training/Json
classification/Json
ocr1,ocr2,ocr1
stanford
iob
iob_pos
iob_chatbot
Download model
import requests
# Define the API endpoint with token and file_type in the URL
api_url = "https://app.ubiai.tools:8443/api_v1/download_model/{token}/{model_name}"
# Replace placeholders with actual values
api_url = api_url.format(token="your_access_token", model_name="your_name")
# Make a POST request to the API with headers and files
response = requests.get(api_url)
# Check the response
if response.status_code == 200:
# Access the response content
data = json.loads(response.content.decode("utf-8"))
print("Response Data:", data)
else:
# Handle the error
print("Error:", response.status_code, response.text)
Perform OCR & layoutLM inference with API
import requests
# Define the API endpoint with token and file_type in the URL
api_url = "https://app.ubiai.tools:8443/api_v1/ocr_layoutlm_inference/{token}/{file_type}"
# Replace placeholders with actual values
api_url = api_url.format(token="your_access_token", file_type="your_file_type")
# Define the file and other parameters to be sent with the request
file_paths = [] # add local files urls here
file_urls = [] # add urls of files online (must be public/accessible)
files = []
for path in file_paths:
files.append(
(
"file",
(os.path.basename(path), open(path, "rb"), mimetypes.guess_type(path)[0]),
)
)
data = {
"ocr_engine": "DEFAULT", # ocr engine to use
"filesUrls": file_urls, # urls of files online
}
# Make a POST request to the API with headers and files
response = requests.post(api_url, body=body, headers=headers)
# Check the response
if response.status_code == 200:
# Access the response content
data = json.loads(response.content.decode("utf-8"))
print("Response Data:", data)
else:
# Handle the error
print("Error:", response.status_code, response.text)
OCR_ENGINES
DEFAULT
ENGINE1
ENGINE2
ENGINE3
type
pdf
image
Upload files
import requests
import json
import mimetypes
import os
# Define the API endpoint with token and file_type in the URL
api_url = "https://app.ubiai.tools:8443/api/upload/{token}/{file_type}/"
# Replace placeholders with actual values
api_url = api_url.format(token="your_access_token", file_type="zip")
# Define the file and other parameters to be sent with the request
file_type = "/json"
list_of_file_path = ['']
urls = []
files = []
for file_path in list_of_file_path :
files.append(('file',(os.path.basename(file_path ),open(file_path, 'rb'),mimetypes.guess_type(file_path)[0])))
data = {
'autoAssignToCollab' :False,
'taskType' :'TASK',
'nbUsersPerDoc' :'',
'selectedUsers' :'',
'filesUrls' : urls
}
# Make a POST request to the API with headers and files
response = requests.post(api_url, files=files, data=data)
# Check the response
if response.status_code == 200:
# Access the response content
data = json.loads(response.content.decode("utf-8"))
print("Response Data:", data)
else:
# Handle the error
print("Error:", response.status_code, response.text)