pure-almaz / Renerd-max

Config files for my GitHub profile.
https://github.com/Renerd-max
0 stars 0 forks source link

Create a new project on kili using GraphQL and Python #2

Open pure-almaz opened 2 years ago

pure-almaz commented 2 years ago

This issue shows you how you can create a new project on kili using python and graphql

Visit kili documentation to learn more: https://cloud.kili-technology.com/docs/python-graphql-api/recipes/create_project/

pure-almaz commented 2 years ago

Import kili

pip install kili

pure-almaz commented 2 years ago

Authenticate the operating system using user API and endpoints.

If you use the saas platform, your API endpoint will be https://cloud.kili-technology.com/api/label/v2/graphql

Note: Change API version to latest kili version, at the time of writing, its version is 2.103.0


import os
from kili.client import kili
kili = Kili(api_key='YOUR_API_KEY', api_endpoint='THE_API_ENDPOINT')
pure-almaz commented 2 years ago

Create your project


project=kili.create_project(title='Text Classification', description='Classifying texts according to underlying sentiments', input_type='TEXTS', json_interface={"jobRendererWidth": 0.3, "jobs": { "CLASSIFICATION_JOB": { "mlTask": "CLASSIFICATION", "content":{ "categories": { "POSITIVE": { "name": "Positive" }, "NEGATIVE": { "name": "Negative" }, "NEUTRAL": { "name": "Neutral" } }, "input": "checkbox" }, "required": 1, 

"isChild": False, "instruction": "Label at your discreetion"} } })

print(a'Created project {project["id"]}')
pure-almaz commented 2 years ago

Add collaborators


emails = ['email_a@domain.com', 'email_b@domain.com'] for email in emails: kili.append_to_roles( project_id=project['id'], user_email=emails, role='ADMIN')
pure-almaz commented 2 years ago

Add assets


assets = ["file_url_or_path", "file_url_or_path", "file_url_or_path"," file_url_or_path","file_url_or_path"]

id_assets = kili.append_many_to_dataset( project_id=project['id'], content_array=assets, external_id_array=['Reviews' + str(a) for a in range(len(assets))])