Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component Error when attempting to use pre-defined label List #7

Open
BillCM opened this issue Feb 5, 2024 · 3 comments
Open

Component Error when attempting to use pre-defined label List #7

BillCM opened this issue Feb 5, 2024 · 3 comments

Comments

@BillCM
Copy link

BillCM commented Feb 5, 2024

I've started receiving this error whenever I try to pass a label list as input to the text_labeler().

Dependencies:
python 3.11.4
streamlit==1.31.0
streamlit-annotation-tools==1.0.1

col1, col2 = st.columns(2)

with col1:
    st.header("Document")
    annotations = text_labeler(text=get_document(), labels=['one', 'two', 'three'])

with col2:
    st.header("Abstracted Fields")
    st.write(annotations)

ERROR: text_labeler component is not presented. However, the annotations object is presented as expected

Component Error
n.sort is not a function. (In 'n.sort(((e,t)=>e.start-t.start))', 'n.sort' is undefined)

Chrome Inspector shows the following error, but JS is enabled. Same on Brave and Safari.
<noscript>You need to enable JavaScript to run this app.</noscript>

Removing the labels allows the text_labeler to render.
annotations = text_labeler(doc_text)

  • web component loads and I can label without error
@rmarquet21
Copy link
Owner

Look at the example https://github.com/rmarquet21/streamlit-annotation-tools/blob/master/examples/example.py

You have here the format of parameter labels

def labeler_page():
    st.title("Text Labeling Tool")

    text = "Yesterday, at 3 PM, Emily Johnson and Michael Smith met at the Central Park in New York to discuss the merger between TechCorp and Global Solutions. The deal, worth approximately 500 million dollars, is expected to significantly impact the tech industry. Later, at 6 PM, they joined a conference call with the CEO of TechCorp, David Brown, who was in London for a technology summit. During the call, they discussed the market trends in Asia and Europe and planned for the next quarterly meeting, which is scheduled for January 15th, 2024, in Paris."

    labels = {
        "Personal names": [
            {"start": 20, "end": 33, "label": "Emily Johnson"},
            {"start": 38, "end": 51, "label": "Michael Smith"},
            {"start": 327, "end": 338, "label": "David Brown"},
        ],
        "Organizations": [
            {"start": 118, "end": 126, "label": "TechCorp"},
            {"start": 131, "end": 147, "label": "Global Solutions"},
        ],
        "Locations": [
            {"start": 63, "end": 75, "label": "Central Park"},
            {"start": 79, "end": 87, "label": "New York"},
            {"start": 351, "end": 357, "label": "London"},
            {"start": 436, "end": 440, "label": "Asia"},
            {"start": 445, "end": 451, "label": "Europe"},
            {"start": 542, "end": 547, "label": "Paris"},
        ],
        "Time": [
            {"start": 0, "end": 9, "label": "Yesterday"},
            {"start": 14, "end": 18, "label": "3 PM"},
            {"start": 265, "end": 269, "label": "6 PM"},
            {"start": 519, "end": 531, "label": "January 15th"},
            {"start": 533, "end": 537, "label": "2024"},
        ],
        "Money": [{"start": 179, "end": 198, "label": "500 million dollars"}],
    }

    labels = text_labeler(text, labels)

@BillCM
Copy link
Author

BillCM commented Feb 6, 2024

OK. Perhaps there is an opportunity to clarify the code doc here.

The labels input isn't a list as defined in the code. It's actually a Dict.

def text_labeler(text: str, labels=[], in_snake_case=False):
    """Create a new instance of "text_labeler".

    Parameters
    ----------
    text : str
        The text to be labeled

    labels : list

@rmarquet21
Copy link
Owner

You're right, I'll take care of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants