question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to connect to a local REST API for auto annotation?

See original GitHub issue

How to reproduce the behaviour

I want to use a local auto-annotator using spaCy. So I made a simple API using FastAPI as follows - NOTE: Right now it does not annotate, but the idea is to be able to communicate first. Atleast for now I should get the input text back as it is. Also, since the rest api is local, I exposed port 7000 of container to 7000 of my host

from fastapi import FastAPI
import uvicorn
from pydantic import BaseModel


class TextToAnnotate(BaseModel):
    text: str

app = FastAPI()

@app.post("/auto_annotate")
async def auto_annotate(doc: TextToAnnotate):
    return {"message": doc.text}

if __name__=="__main__":
    uvicorn.run("auto_annotate:app", host='0.0.0.0', port=7000)

I checked this API from Postman by sending a simple text from body and was able to get the message back - image

Then in doccano, I tried to setup the Auto Annotator as follows -

  1. Config Template - Custom REST Request image

  2. Parameters, headers, Body and Testing url - 0.0.0.0:7000/auto_annotate method - POST image

  3. Params - Nothing

  4. Headers - Content-Type - application/json

  5. Body - Just provided the key as text image

  6. Test the parameters - Sample Text - “Does this work?” image I don’t get any output. it says that it Failed to establish a connection

Your Environment

  • Operating System: Windows 10
  • Python Version Used: Whatever ships with the Docker image
  • When you install doccano: 17th June 2021
  • How did you install doccano (Heroku button etc): Dockerfile

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:18

github_iconTop GitHub Comments

6reactions
EnzoNcltcommented, Jun 23, 2021

I think you’re pretty close, maybe try with the “if not loop.last” param like this it could work:

[
    {% for entity in input %}
        {
            "start_offset": {{ entity.start_offset }},
            "end_offset": {{ entity.end_offset}},
            "label": "{{ entity.label }}"
        }{% if not loop.last %},{% endif %}
    {% endfor %}
]
2reactions
uklftcommented, Jun 22, 2021

Assuming you are running doccano and your API in seperated containers with exposed ports you would need to specify your docker hosts public IP, eg. 192.168.0.10, as 0.0.0.0 refers to each container’s public address. Otherwise you could add them to a docker network and refer to the container name.

If you didn’t find out yet, you can specify the text to be sent to your api by setting it as jinja2 variable in your body: key: text, value: {{ text }}. Your annotated Sample Text then should be returned by the API.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the REST Client - Quarkus
Package and run the application​​ Open your browser to http://localhost:8080/extension/id/io.quarkus:quarkus-rest-client. You should see a JSON object containing ...
Read more >
Create a REST API with Attribute Routing in ASP.NET Web API 2
In Solution Explorer, right-click the Controllers folder. Select Add, then select Controller. In the Add Scaffold dialog, select Web API 2 ...
Read more >
Python and REST APIs: Interacting With Web Services
In this tutorial, you'll learn how to use Python to communicate with REST APIs. You'll learn about REST architecture and how to use...
Read more >
How to create a REST API using Spring Boot, Maven, and ...
Go to http://localhost:8081/swagger-ui/ to access the documentation and test that our APIs are still working properly. Use the Swagger API ...
Read more >
Spring Restful Web Services Example with JSON, Jackson ...
The tutorial is developed in Spring STS IDE for creating Spring MVC skeleton code easily and then extended to implement Restful architecture.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found