How to connect to a local REST API for auto annotation?
See original GitHub issueHow 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 -
Then in doccano, I tried to setup the Auto Annotator as follows -
-
Config Template - Custom REST Request
-
Parameters, headers, Body and Testing url -
0.0.0.0:7000/auto_annotate
method -POST
-
Params - Nothing
-
Headers -
Content-Type
-application/json
-
Body - Just provided the key as
text
-
Test the parameters - Sample Text - “Does this work?”
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:
- Created 2 years ago
- Reactions:1
- Comments:18
I think you’re pretty close, maybe try with the “if not loop.last” param like this it could work:
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.