Skip to content

Quick example to connect a spaCy model to tagtog using webhooks 🤖

Notifications You must be signed in to change notification settings

tagtog/demo-webhooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 

Repository files navigation

demo-webhooks

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:

  1. Upon document upload to tagtog, to get the document's content from tagtog using the document ID.
  2. To annotate the document text using the spaCy model en_core_web_sm and to transform the spaCy annotations into the ann.json format.
  3. To push the annotated document back to tagtog

⚡️ Setup and running

  1. 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
  1. Install the dependencies
pip install -r requirements.txt
  1. Download the spaCy model
python3 -m spacy download en_core_web_sm
  1. Create a project at tagtog.net

  2. Go to your tagtog project and create three entity types at Settings > Entity Types:

    1. PERSON
    2. ORG
    3. MONEY
    4. (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 or LANGUAGE).
  3. Setup the environment variables

export MY_TAGTOG_USERNAME='your_username'
export MY_TAGTOG_PASSWORD='your_password'
export MY_TAGTOG_PROJECT='project_name'
  1. Run the app
export FLASK_APP=app.py
export FLASK_ENV=development  # this enables live reloading
flask run --port 5005
  1. In another console, make your app reachable from the outside using ngrok
# on macOS: brew install ngrok
ngrok http 5005
  1. 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.
  2. 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.

    Sample PDF