Example showing how to connect your NLP models to tagtog. We will use Python, Flask, spaCy, tagtog webhooks and tagtog API.
An introduction to webhooks and the full step-by-step guide is here: https://tagtog.medium.com/connect-your-nlp-models-to-tagtog-using-webhooks-13d422ae4dff
With this repo, you will learn how to setup a tagtog webhook and how to manage an event notification generated by the webhook:
- Upon document upload to tagtog, to get the document's content from tagtog using the document ID.
- To annotate the document text using the spaCy model
en_core_web_sm
and to transform the spaCy annotations into the ann.json format. - To push the annotated document back to tagtog
- Create a virtual environment
# Create the virtual environment (.venv)
# Python ^3.6
python3 -m venv .venv
# Activate the virtualenv (macOS & Linux)
source .venv/bin/activate
- Install the dependencies
pip install -r requirements.txt
- Download the spaCy model
python3 -m spacy download en_core_web_sm
-
Create a project at tagtog.net
-
Go to your tagtog project and create three entity types at Settings > Entity Types:
PERSON
ORG
MONEY
- (OPTIONALLY) you can add more, as many (and with the exact names) as supported and listed in en_core_web_sm > Label Scheme > NER (e.g.
DATE
orLANGUAGE
).
-
Setup the environment variables
export MY_TAGTOG_USERNAME='your_username'
export MY_TAGTOG_PASSWORD='your_password'
export MY_TAGTOG_PROJECT='project_name'
- Run the app
export FLASK_APP=app.py
export FLASK_ENV=development # this enables live reloading
flask run --port 5005
- In another console, make your app reachable from the outside using ngrok
# on macOS: brew install ngrok
ngrok http 5005
-
Add a webhook to your project at Settings > Webhooks:
- Endpoint: Use the endpoint given by ngrok (e.g. https://d6a6da136156.ngrok.io)
- Payload: Choose the payload
tagtogID
- Check the flag to
Trigger only if change originates in the GUI
- Authentication: we won't use any authentication mechanism for this example, therefore we choose
none
.
-
Upload a document to your tagtog project 🪄 it will be automatically annotated by our spaCy model!
Sample document text:
Paypal Holdings Inc (PYPL) President and CEO Daniel Schulman Sold $2.7 million of Shares.