Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions docs/sdk/tutorials/plugins_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,28 +125,33 @@ class PluginHandler(PluginCore):
Custom plugin instance
"""

def on_submit(self, label: Dict, asset_id: str) -> None:
def on_event(self, payload: dict) -> None:
"""
Dedicated handler for Submit action
"""
self.logger.info("On submit called")
event = payload.get("event")

issues_array = check_rules_on_label(label)
if event == 'labels.created.submit':
label = payload["label"]
asset_id = label["assetId"]
self.logger.info("On submit called")

project_id = self.project_id
issues_array = check_rules_on_label(label)

if len(issues_array) > 0:
print("Creating an issue...")
project_id = self.project_id

self.kili.create_issues(
project_id=project_id,
label_id_array=[label['id']] * len(issues_array),
text_array=issues_array,
)
if len(issues_array) > 0:
print("Creating an issue...")

print("Issue created!")
self.kili.create_issues(
project_id=project_id,
label_id_array=[label['id']] * len(issues_array),
text_array=issues_array,
)

self.kili.send_back_to_queue(asset_ids=[asset_id])
print("Issue created!")

self.kili.send_back_to_queue(asset_ids=[asset_id])

```

Expand Down Expand Up @@ -208,7 +213,7 @@ plugin_name = "Plugin bbox count"
from kili.exceptions import GraphQLError

try:
kili.upload_plugin(plugin_folder, plugin_name)
kili.upload_plugin(plugin_folder, plugin_name, event_matcher=["labels.created.submit"])
except GraphQLError as error:
print(str(error))
```
Expand All @@ -231,7 +236,9 @@ path_to_plugin = Path(plugin_folder) / "main.py"
plugin_name_file = "Plugin bbox count - file"

try:
kili.upload_plugin(str(path_to_plugin), plugin_name_file)
kili.upload_plugin(
str(path_to_plugin), plugin_name_file, event_matcher=["labels.created.submit"]
)
except GraphQLError as error:
print(str(error))
```
Expand Down
1 change: 0 additions & 1 deletion docs/sdk/tutorials/plugins_library.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Let's imagine a project where we want to process images and detect some objects.
Let's imagine another project where we process invoices. The project has two jobs and several transcription tasks associated with them. One of the jobs is about payment information and must contain a proper IBAN number as well as currency. The IBAN must start with FR, and the currency should be one of: *EURO* or *DOLLAR*. Kili's interface customization options are powerful and flexible, but won't help us in this specific situation so we have to turn to Kili plugins for help. We'll set up our Kili plugin to check these two rules when labelers click *Submit*. If the annotations don't match our predefined rules, our QA bot will add issues to the asset and send the asset back to the labeling queue. At the end, our script will calculate labeling accuracy and insert the accuracy metric in the json_metadata of the asset. All that with no need to engage a human reviewer.

- Plugin file: [`plugin_document.py`](https://github.com/kili-technology/kili-python-sdk/blob/main/recipes/plugins_library/plugin_document.py){target=_blank}
- End-to-end notebook showcasing this example: [`plugins_example_document.ipynb`](https://github.com/kili-technology/kili-python-sdk/blob/main/recipes/plugins_example_document.ipynb){target=_blank}

### 2. Consensus resolution

Expand Down
37 changes: 22 additions & 15 deletions recipes/plugins_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -205,28 +205,33 @@
" Custom plugin instance\n",
" \"\"\"\n",
"\n",
" def on_submit(self, label: Dict, asset_id: str) -> None:\n",
" def on_event(self, payload: dict) -> None:\n",
" \"\"\"\n",
" Dedicated handler for Submit action \n",
" \"\"\"\n",
" self.logger.info(\"On submit called\")\n",
" event = payload.get(\"event\")\n",
"\n",
" issues_array = check_rules_on_label(label)\n",
" if event == 'labels.created.submit':\n",
" label = payload[\"label\"]\n",
" asset_id = label[\"assetId\"]\n",
" self.logger.info(\"On submit called\")\n",
"\n",
" project_id = self.project_id\n",
" issues_array = check_rules_on_label(label)\n",
"\n",
" if len(issues_array) > 0:\n",
" print(\"Creating an issue...\")\n",
" project_id = self.project_id\n",
"\n",
" self.kili.create_issues(\n",
" project_id=project_id,\n",
" label_id_array=[label['id']] * len(issues_array),\n",
" text_array=issues_array,\n",
" )\n",
" if len(issues_array) > 0:\n",
" print(\"Creating an issue...\")\n",
"\n",
" print(\"Issue created!\")\n",
" self.kili.create_issues(\n",
" project_id=project_id,\n",
" label_id_array=[label['id']] * len(issues_array),\n",
" text_array=issues_array,\n",
" )\n",
"\n",
" self.kili.send_back_to_queue(asset_ids=[asset_id])\n",
" print(\"Issue created!\")\n",
"\n",
" self.kili.send_back_to_queue(asset_ids=[asset_id])\n",
"\n",
"```"
]
Expand Down Expand Up @@ -319,7 +324,7 @@
"from kili.exceptions import GraphQLError\n",
"\n",
"try:\n",
" kili.upload_plugin(plugin_folder, plugin_name)\n",
" kili.upload_plugin(plugin_folder, plugin_name, event_matcher=[\"labels.created.submit\"])\n",
"except GraphQLError as error:\n",
" print(str(error))"
]
Expand Down Expand Up @@ -359,7 +364,9 @@
"plugin_name_file = \"Plugin bbox count - file\"\n",
"\n",
"try:\n",
" kili.upload_plugin(str(path_to_plugin), plugin_name_file)\n",
" kili.upload_plugin(\n",
" str(path_to_plugin), plugin_name_file, event_matcher=[\"labels.created.submit\"]\n",
" )\n",
"except GraphQLError as error:\n",
" print(str(error))"
]
Expand Down
Loading