Merge commit '28fa95b09b5e69c5c3b25768befa9b30a3f80aab'

pull/2/head
Kai Labusch 4 years ago
commit 980f8b62b8

@ -168,7 +168,8 @@ Output:
] ]
] ]
``` ```
The JSON above is the expected input format of the [SBB named entity disambiguation system](sbb_ned/). The JSON above is the expected input format of the
[SBB named entity linking and disambiguation system](https://github.com/qurator-spk/sbb_ned).
# Model-Training # Model-Training
*** ***

@ -1,6 +1,8 @@
import os import os
import logging import logging
from flask import Flask, send_from_directory, redirect, jsonify, request from flask import Flask, send_from_directory, redirect, jsonify, request
from flask_caching import Cache
from hashlib import sha256
import html import html
import json import json
import torch import torch
@ -16,6 +18,8 @@ app = Flask(__name__)
app.config.from_json('config.json' if not os.environ.get('CONFIG') else os.environ.get('CONFIG')) app.config.from_json('config.json' if not os.environ.get('CONFIG') else os.environ.get('CONFIG'))
cache = Cache(app)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -149,6 +153,10 @@ predictor_store = PredictorStore()
tokenizer = NERTokenizer() tokenizer = NERTokenizer()
def key_prefix():
return "{}:{}".format(request.path, sha256(str(request.json).encode('utf-8')).hexdigest())
@app.route('/') @app.route('/')
def entry(): def entry():
return redirect("/index.html", code=302) return redirect("/index.html", code=302)
@ -160,6 +168,7 @@ def get_models():
@app.route('/tokenized', methods=['GET', 'POST']) @app.route('/tokenized', methods=['GET', 'POST'])
@cache.cached(key_prefix=key_prefix)
def tokenized(): def tokenized():
raw_text = request.json['text'] raw_text = request.json['text']
@ -173,6 +182,7 @@ def tokenized():
@app.route('/ner-bert-tokens', methods=['GET', 'POST']) @app.route('/ner-bert-tokens', methods=['GET', 'POST'])
@app.route('/ner-bert-tokens/<model_id>', methods=['GET', 'POST']) @app.route('/ner-bert-tokens/<model_id>', methods=['GET', 'POST'])
@cache.cached(key_prefix=key_prefix)
def ner_bert_tokens(model_id=None): def ner_bert_tokens(model_id=None):
raw_text = request.json['text'] raw_text = request.json['text']
@ -198,6 +208,7 @@ def ner_bert_tokens(model_id=None):
@app.route('/ner', methods=['GET', 'POST']) @app.route('/ner', methods=['GET', 'POST'])
@app.route('/ner/<model_id>', methods=['GET', 'POST']) @app.route('/ner/<model_id>', methods=['GET', 'POST'])
@cache.cached(key_prefix=key_prefix)
def ner(model_id=None): def ner(model_id=None):
raw_text = request.json['text'] raw_text = request.json['text']

@ -14,5 +14,6 @@ cloudpickle
pytest pytest
pytest-cov pytest-cov
flask flask
Flask-Caching
gunicorn gunicorn
somajo somajo

Loading…
Cancel
Save