HumanSignal / label-studio-ml-backend

Configs and boilerplates for Label Studio's Machine Learning backend
Apache License 2.0
585 stars 261 forks source link

label_interface error in the backend. #566

Closed hh1985 closed 4 months ago

hh1985 commented 5 months ago

Hi

I was connecting my label studio UI to the backend and had following error:

[2024-06-14 14:57:13,452] [ERROR] [label_studio_ml.exceptions::exception_f::53] Traceback (most recent call last):
  File "/share/home/hanh/code-repository/label-studio-ml-backend/label_studio_ml/exceptions.py", line 39, in exception_f
    return f(*args, **kwargs)
  File "/share/home/hanh/code-repository/label-studio-ml-backend/label_studio_ml/api.py", line 99, in _setup
    model = MODEL_CLASS(project_id=project_id,
  File "/share/home/hanh/code-repository/label-studio-ml-backend/label_studio_ml/model.py", line 81, in __init__
    self.use_label_config(label_config)
  File "/share/home/hanh/code-repository/label-studio-ml-backend/label_studio_ml/model.py", line 106, in use_label_config
    self.label_interface = LabelInterface(config=label_config)
  File "/home/hanh/.conda/envs/ner_ls_backend/lib/python3.9/site-packages/label_studio_sdk/label_interface/interface.py", line 215, in __init__
    controls, objects, labels, tree = self.parse(config)
  File "/home/hanh/.conda/envs/ner_ls_backend/lib/python3.9/site-packages/label_studio_sdk/label_interface/interface.py", line 432, in parse
    labels[lb.parent_name][lb.value] = lb
AttributeError: 'NoneType' object has no attribute 'parent_name'

Traceback (most recent call last):
  File "/share/home/hanh/code-repository/label-studio-ml-backend/label_studio_ml/exceptions.py", line 39, in exception_f
    return f(*args, **kwargs)
  File "/share/home/hanh/code-repository/label-studio-ml-backend/label_studio_ml/api.py", line 99, in _setup
    model = MODEL_CLASS(project_id=project_id,
  File "/share/home/hanh/code-repository/label-studio-ml-backend/label_studio_ml/model.py", line 81, in __init__
    self.use_label_config(label_config)
  File "/share/home/hanh/code-repository/label-studio-ml-backend/label_studio_ml/model.py", line 106, in use_label_config
    self.label_interface = LabelInterface(config=label_config)
  File "/home/hanh/.conda/envs/ner_ls_backend/lib/python3.9/site-packages/label_studio_sdk/label_interface/interface.py", line 215, in __init__
    controls, objects, labels, tree = self.parse(config)
  File "/home/hanh/.conda/envs/ner_ls_backend/lib/python3.9/site-packages/label_studio_sdk/label_interface/interface.py", line 432, in parse
    labels[lb.parent_name][lb.value] = lb
AttributeError: 'NoneType' object has no attribute 'parent_name'

The label config is like the following, and I noticed that the tag caused the error.

    <View>
        <Relations>
            <Relation value="biomarker_of" />
            <Relation value="member_of" />
        </Relations>
        <Text name="abstract" valueType="text" value="$abstract"/>
        <Labels name="entity_type" toName="abstract" showInline="true">
            <Label value="gene/protein" background="orange"/>
            <Label value="compound" background="orange"/>
            <Label value="microbe" background="orange"/>
            <Label value="fibre" background="orange"/>
            <Label value="minerals" background="orange"/>
            <Label value="regulator" background="orange"/>
            <Label value="cellular component" background="blue"/>
            <Label value="cell line" background="blue"/>
            <Label value="anatomy" background="blue"/>
            <Label value="organism" background="blue"/>
            <Label value="population" background="blue"/>
            <Label value="space/time" background="blue"/>
            <Label value="other_context" background="blue"/>
            <Label value="molecular function" background="green"/>
            <Label value="biological process" background="green"/>
            <Label value="disease" background="purple"/>
            <Label value="health_status_group" background="purple"/>
            <Label value="symptom" background="purple"/>
            <Label value="drug" background="#FFC470"/>
            <Label value="food" background="#FFC470"/>
            <Label value="medical_treatment" background="#FFC470"/>
            <Label value="formula" background="#FFC470"/>
            <Label value="environmental_factor" background="#FFC470"/>
        </Labels>
        <Header value="Prompt:" />
        <TextArea name="prompt" toName="abstract" rows="4" editable="true" maxSubmissions="1" showSubmitButton="false"
            placeholder="Type your prompt here then Shift+Enter..." />
        <Header value="Response:" />
        <TextArea name="response" toName="abstract" rows="6" editable="false" maxSubmissions="1" showSubmitButton="false" 
            smart="false" placeholder="Generated response will appear here..." />
    </View>

The error can be produced by

from label_studio_sdk.label_interface import LabelInterface
from label_studio_sdk import Client

ls = Client(url=LABEL_STUDIO_URL, api_key=API_KEY)
project = ls.get_project(id=30)
label_config = project.label_config
li = LabelInterface(label_config)

where the version of label_studio_sdk is 0.0.34 (the one used for label-studio-ml-backend).

However, I also noticed that it works without error in label_studio_sdk 1.0.1

# Import the SDK and the client module
from label_studio_sdk.client import LabelStudio
from label_studio_sdk.label_interface.interface import LabelInterface

ls = LabelStudio(base_url=LABEL_STUDIO_URL, api_key=API_KEY)
project = ls.projects.get(id=30)
label_config = project.label_config

li = LabelInterface(label_config)
print(li._control_tags, li._object_tags)
print(li._labels.keys())
# {'prompt', 'entity_type', 'response'} {'abstract'}
# dict_keys(['entity_type', 'prompt', 'response'])

If I want to get the code work for the label-studio-ml-backend (with label_studio_sdk 0.0.34), what should I do? Thanks a lot!

hh1985 commented 4 months ago

Solved with the updated fix.