label-studio icon indicating copy to clipboard operation
label-studio copied to clipboard

interactive annotation about <TextArea> with perRegion="true"

Open Michel-liu opened this issue 1 year ago • 1 comments

Hi~ Thanks for this wonderful project. Currently, I try to perform interactive annotation for automatically polishing the description of each bbox region via a LLM, which looks like

<Image name="image" value="$image">
<RectangleLabels name="bbox" toName="image">
<Label value="car" />
<Label value="cat" />
</RectangleLabels>
<TextArea name="description" toName="image" perRegion="true" maxSubmissions="1" editable="true" required="true"/>

However, when I submit the text, I am unable to transmit the annotated description to the predict function in the label-studio-ml backend. It seems perRegion="true" disables this process. How could I address this issue? Thanks.

Michel-liu avatar Jun 12 '25 05:06 Michel-liu

Hello,

Thanks for the details and the config snippet. What you’re running into is expected: when you attach a TextArea as a perRegion control, Label Studio does not include its value in the top-level params of the ML request. Instead, your user-entered text shows up only in the tasks[0].annotations[0].result list.

Two ways to work around this:

  1. Parse the description out of tasks[0].annotations[0].result in your predict function In your ML-backend code, pull the textarea value for the region by matching the region ID (region_id is passed in kwargs). For example:

    def predict(self, tasks, **kwargs): task = tasks[0] # single‐task region_id = kwargs.get("region_id") # passed by LS for interactive calls results = task["annotations"][0]["result"] # find the description text for this region desc = "" for r in results: if r["type"] == "textarea" and r["id"] == region_id: desc = r["value"]["text"][0] break # now you have the per-region description to feed into your LLM polished = call_your_llm(desc) return [{ "result": [{ "id": region_id, "type": "textarea", "from_name": "description", "to_name": "image", "value": { "text": [polished] } }] }]

  2. If you don’t strictly need per-region text, remove perRegion="true" A non-perRegionTextArea will have its value sent in params["context"], which some ML backends read automatically. But that applies the same description to the whole image, not each box.

Thank you, Abu

Comment by Abubakar Saad Workflow Run

heidi-humansignal avatar Jun 17 '25 17:06 heidi-humansignal