HumanSignal / HumanSignal/label-studio

Hide `Choices` on condition

Open
#6,516 2 comments 0 reactions 0 assignees View on GitHub
community_reviewed
Dominant language
TypeScript
Stars
28.3k
Forks
3.7k
Avg merge
14h
Merged PRs (30d)
15

Description

Say I have a dataset of items of variable length and the list of their pre-annotations (0,1 or 2), e.g.

| item | preannotation |
|---------------------|---------------|
| [a1, a2]. | [0, 2] |
| [b1, b2, b3, b4] | [1, 2, 2, 0]|
| [c1] | [0] |

As it seems like that the label configuration has to be of fixed length, I am computing the maximum length of the `item` entry and adding some empty "padding entries". However, hiding them using a condition such as `name == ''` would be nice.

Here's a minimal reproducible example:

```py
from label_studio_sdk import Client

def generate_label_config(max_items):
items = ""
for i in range(max_items):
items += f"""








"""
return f"""



{items}

"""

if __name__ == '__main__':
fake_data = [
{
"data": {
'title': 'title0',
'item_0_name': 'a0',
'item_0_label': 'label0',
'item_1_name': 'a1',
'item_1_label': 'label1',
'item_2_name': '', # padding
'item_2_label': '', # padding
'item_3_name': '', # padding
'item_3_label': '', # padding
},
"predictions": [
{
"result": [
{
"from_name": "item_0_label",
"to_name": "item_0_name",
"type": "choices",
"value": {"choices": ["0"]}
},
{
"from_name": "item_1_label",
"to_name": "item_1_name",
"type": "choices",
"value": {"choices": ["2"]}
}
]
}
]
},
{
"data": {
'title': 'title1',
'item_0_name': 'b0',
'item_0_label': 'label0',
'item_1_name': 'b1',
'item_1_label': 'label1',
'item_2_name': 'b2',
'item_2_label': 'label2',
'item_3_name': 'b3',
'item_3_label': 'label3',
},
"predictions": [
{
"result": [
{
"from_name": "item_0_label",
"to_name": "item_0_name",
"type": "choices",
"value": {"choices": ["1"]}
},
{
"from_name": "item_1_label",
"to_name": "item_1_name",
"type": "choices",
"value": {"choices": ["2"]}
},
{
"from_name": "item_2_label",
"to_name": "item_2_name",
"type": "choices",
"value": {"choices": ["2"]}
},
{
"from_name": "item_3_label",
"to_name": "item_3_name",
"type": "choices",
"value": {"choices": ["0"]}
}
]
}
]
},
{
"data": {
'title': 'title2',
'item_0_name': 'c0',
'item_0_label': 'label0',
'item_1_name': '', # padding
'item_1_label': '', # padding
'item_2_name': '', # padding
'item_2_label': '', # padding
'item_3_name': '', # padding
'item_3_label': '', # padding
},
"predictions": [
{
"result": [
{
"from_name": "item_0_label",
"to_name": "item_0_name",
"type": "choices",
"value": {"choices": ["0"]}
}
]
}
]
},
]

max_items = 4
ls = Client(url='http://localhost:8080', api_key='API-KEY')
label_config = generate_label_config(max_items)

project = ls.start_project(
title="Fo project",
label_config=label_config
)
project.import_tasks(fake_data)

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.