-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Any documentation about using as REST service #299
Comments
Documenting about API is now in progress. Please wait for a little! https://github.com/chakki-works/doccano/projects/3#card-22665439 |
Any update for the next release with this? I would also like this feature for an annotation project I'm currently working on. |
@luispsantos, @Hironsan in #6 gave a sample class to illustrate the interaction with I noticed that due to recent changes authentication works through the API token now, so you only need to adapt the authentication scheme in that code and pass the authentication headers each time with your request. class Client(object):
def __init__(self, entrypoint, username=None, password=None):
self.entrypoint = entrypoint
self.client = requests.Session()
api_token = self.get_api_token(username, password)
self.auth_headers = {"Authorization": "Token {}".format(api_token)}
def get_api_token(self, username, password):
url = f"{self.entrypoint}/v1/auth-token"
login = {"username": username, "password": password}
response = self.client.post(url, json=login)
return response.json()["token"]
def fetch_projects(self):
url = f"{self.entrypoint}/v1/projects"
response = self.client.get(url, headers=self.auth_headers)
return response |
@rbagd Thanks for the example class, it should be useful for others who stumble upon this issue on how to interact with Doccano at the API level (especially with the added token authentication on this example). I agree that the example given by @Hironsan is fairly intuitive, and in the meantime I managed to adapt it to my use case using token authentication 👍 |
The question proposed at #410 . Question 1: /v1/projects/{project_id}/docs endpointI managed to create the project and upload documents using this endpoint Question 2: /v1/projects/{project_id}/docs/upload endpointI tried to upload documents using this endpoint What is the type of the |
To follow-up on my question above, here is some reproducible code. The client I use class Client(object):
"""
Client code was inspired by: https://github.com/chakki-works/doccano/issues/6#issuecomment-489924577
Endpoints can be found here: https://github.com/chakki-works/doccano/blob/master/app/api/urls.py
"""
def __init__(self, entrypoint, username=None, password=None):
self.entrypoint = entrypoint
self.client = requests.Session()
self._login(username, password)
def _login(self, username, password):
url = f"{self.entrypoint}/v1/auth-token"
login = {"username": username, "password": password}
response = self.client.post(url, json=login)
api_token = response.json()["token"]
self.client.headers.update({"Authorization": f"Token {api_token}"})
def add_document(self, project_id, data):
url = f'{self.entrypoint}/v1/projects/{project_id}/docs'
response = self.client.post(url, data=data)
return response.json()
def upload_data(self, project_id, file, file_format='csv'):
"""
file is (?) of type file object (BytesIO or StringIO ...)
"""
data = {
'file': file,
'format': file_format
}
url = f'{self.entrypoint}/v1/projects/{project_id}/docs/upload'
response = self.client.post(url, data=data)
return response Question 1>>> c = Client(
'https://labelling-onefootball.herokuapp.com',
os.environ.get('DOCANNO_ADMIN'),
os.environ.get('DOCANNO_PWD')
)
>>> doc = {'text': 'Mercato / PSG\xa0: ce qu’a dit Tuchel à Neymar va vous surprendre',
'meta': {'article_id': 27551814,
'published_at_str': '2019-10-08 08:23:35',
'provider_name': 'InfoMercato',
'article_link': 'https://consumer-web.onefootball.com/cms/fr/27551814'}}
>>> c.add_document(project_id, doc)
# meta fields are not uploaded Question 2>>> jsonline_dataset = '{"text":"Mercato \\/ PSG\\u00a0: ce qu\\u2019a dit Tuchel \\u00e0 Neymar va vous surprendre","meta":{"article_id":27551814,"published_at_str":"2019-10-08 08:23:35","provider_name":"InfoMercato","article_link":"https:\\/\\/consumer-web.onefootball.com\\/cms\\/fr\\/27551814"}}\n{"text":"Bingo Challenge : Le num\\u00e9ro \\u00ab\\u00a0Tres\\u00a0\\u00bb","meta":{"article_id":27577681,"published_at_str":"2019-10-10 10:30:01","provider_name":"Furia Liga","article_link":"https:\\/\\/consumer-web.onefootball.com\\/cms\\/fr\\/27577681"}}'
>>> file_obj = io.StringIO(jsonline_dataset)
>>> r = c.upload_data(4, file_obj, 'json')
# I get <iframe src="//www.herokucdn.com/error-pages/application-error.html"></iframe> |
@louisguitton Were you ever able to find a solution? I'm using very similar code and unfortunately receiving the following response with
Simple @icoxfog417 You referenced documentation back in June; can I find this documentation somewhere? |
Nope, waiting for the documentation too. But they were quite busy dealing with frontend refactoring for v1.0.0 so I don't mind waiting. |
Small update: I think it might be of Content-Type
So that is at least different. We'll see if that constitutes as progress or not. Update 2: I got a requests.post(
'http://<URL>/v1/projects/1/docs/upload',
files={'file': ('d1.json', open('d1.json', 'rb'))},
data={'file': ('d1.json', open('d1.json', 'rb')), 'format': 'json'},
headers = {
'Authorization': 'Token {token}'.format(token=token)
}
) Although the response is positive, the document does not appear to have been added to the project. Update 3: Confirmed working! This also works with a preauthorized # this is part of the Client class
def upload(
self,
project_id: str,
file_format: str,
file_name: str,
file_path: str = './',
) -> requests.models.Response:
"""
"""
url = '{}/v1/projects/{}/docs/upload'.format(self.entrypoint, project_id)
files = {'file': (file_name, open(os.path.join(file_path, file_name), 'rb'))}
data = {'file': (file_name, open(os.path.join(file_path, file_name), 'rb')), 'format': file_format}
return self.client.post(url, files=files, data=data) |
Plan
|
I made a simple API wrapper for temporary use while the team works on building an official client. @luispsantos - I forgot to tag you but you were also interested at some point I think. |
I've noticed that the Any suggestions on implementing the |
Hi @Hironsan, where is the API doc available? Just an OpenAPI spec would be appreciated too. Thanks! |
I have deployed doccano to aws and now trying to use the client to upload data from an airflow pipeline but I can't seem to connect with the doccano-client. I am following the instructions but i keep getting an error:
I then get the error below
|
Anyone having issue with the method |
Did you solve the problem? |
No I didn’t not solve the problem, I just had to use a work around.
Kind regards,
Esther
… On 24 Feb 2022, at 15:03, 海中灯塔 ***@***.***> wrote:
Anyone having issue with the method get_doc_download ? The data doesn't seem to be downloading.
Did you solve the problem?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you commented.
|
How could use as REST API service. Send raw text and doccano response the parsed data?
The text was updated successfully, but these errors were encountered: