Skip to content

Commit 8a00471

Browse files
committed
migration
1 parent fd93feb commit 8a00471

23 files changed

+1288
-79
lines changed

.envdefault

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1+
# APPLICATION PARAMETERS
12
APP_LANG=fr en
23
ASSETS_PATH_ON_HOST=./assets
34
ASSETS_PATH_IN_CONTAINER=/app/assets
4-
WORKER_NUMBER=1
5+
6+
# SERVING PARAMETERS
7+
SERVICE_MODE=http
8+
CONCURRENCY=1
9+
10+
# MICRO-SERVICE PARAMETERS
11+
SERVICE_NAME=extsumm
12+
SERVICES_BROKER=redis://172.17.0.1:6379
13+
BROKER_PASS=

Dockerfile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
FROM lintoai/linto-platform-nlp-core:latest
22
LABEL maintainer="gshang@linagora.com"
33

4-
WORKDIR /app
4+
WORKDIR /usr/src/app
55

6-
COPY ./requirements.txt /app/
6+
COPY requirements.txt ./
77
RUN pip install --no-cache-dir -r requirements.txt
88

9-
COPY .envdefault /app/
10-
COPY ./scripts /app/scripts
11-
COPY ./components /app/components
9+
COPY extsumm /usr/src/app/extsumm
10+
COPY components /usr/src/app/components
11+
COPY celery_app /usr/src/app/celery_app
12+
COPY http_server /usr/src/app/http_server
13+
COPY document /usr/src/app/document
14+
COPY docker-entrypoint.sh wait-for-it.sh healthcheck.sh ./
1215

13-
HEALTHCHECK --interval=15s CMD curl -fs http://0.0.0.0/health || exit 1
16+
ENV PYTHONPATH="${PYTHONPATH}:/usr/src/app/extsumm"
1417

15-
ENTRYPOINT ["/opt/conda/bin/gunicorn", "scripts.main:app", "--worker-class", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:80", "--access-logfile", "-", "--error-logfile", "-"]
16-
CMD ["--workers", "1"]
18+
HEALTHCHECK CMD ./healthcheck.sh
19+
20+
ENTRYPOINT ["./docker-entrypoint.sh"]

LICENSE

Lines changed: 661 additions & 0 deletions
Large diffs are not rendered by default.

RELEASE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 0.2.0
2+
- Migration to the [template]((https://github.com/linto-ai/linto-template-microservice)) of LinTO microservices.
3+
14
# 0.1.0
25
- Initial commit.
36
- Extractive Summarization.
File renamed without changes.

celery_app/celeryapp.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import os
2+
from celery import Celery
3+
4+
from extsumm import logger
5+
6+
celery = Celery(__name__, include=['celery_app.tasks'])
7+
service_name = os.environ.get("SERVICE_NAME", "extsumm")
8+
broker_url = os.environ.get("SERVICES_BROKER")
9+
if os.environ.get("BROKER_PASS", False):
10+
components = broker_url.split('//')
11+
broker_url = f'{components[0]}//:{os.environ.get("BROKER_PASS")}@{components[1]}'
12+
celery.conf.broker_url = "{}/0".format(broker_url)
13+
celery.conf.result_backend = "{}/1".format(broker_url)
14+
celery.conf.update(
15+
result_expires=3600,
16+
task_acks_late=True,
17+
task_track_started = True)
18+
19+
# Queues
20+
celery.conf.update(
21+
{'task_routes': {
22+
'extsumm_task' : {'queue': 'extsumm'},}
23+
}
24+
)
25+
26+
logger.info(
27+
f"Celery configured for broker located at {broker_url} with service name {service_name}"
28+
)

celery_app/tasks.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import spacy
2+
import components
3+
4+
from typing import Dict, List
5+
6+
from celery_app.celeryapp import celery
7+
8+
from extsumm import logger
9+
from extsumm.processing import LM_MAP, MODELS, get_model
10+
from extsumm.processing.utils import get_data
11+
12+
13+
@celery.task(name="extsumm_task")
14+
def extsumm_task(lang: str, texts: List[str], component_cfg: Dict = {}):
15+
"""Process a batch of articles and return the extractive summary predicted by the
16+
given model. Each record in the data should have a key "text".
17+
"""
18+
logger.info('ExtSumm task received')
19+
20+
# Check language availability
21+
if lang in LM_MAP.keys():
22+
model_name = LM_MAP[lang]
23+
if model_name not in MODELS.keys():
24+
raise RuntimeError(f"Model {model_name} for language {lang} is not loaded.")
25+
nlp = spacy.blank(lang)
26+
nlp.add_pipe("sentencizer", config={"punct_chars": ['|']})
27+
nlp.add_pipe("extsumm", config={"model": {"@misc": "get_model", "name": model_name}})
28+
else:
29+
raise ValueError(f"Language {lang} is not supported.")
30+
31+
response_body = []
32+
33+
for doc in nlp.pipe(texts, component_cfg=component_cfg):
34+
response_body.append(get_data(doc))
35+
36+
return {"extsumm": response_body}

docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ services:
99
- .env
1010
volumes:
1111
- $ASSETS_PATH_ON_HOST:$ASSETS_PATH_IN_CONTAINER:ro
12-
command: ["--workers", $WORKER_NUMBER]
13-
runtime: nvidia
12+
#runtime: nvidia

docker-entrypoint.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
set -ea
3+
4+
echo "RUNNING SERVICE"
5+
6+
# Launch parameters, environement variables and dependencies check
7+
if [ -z "$SERVICE_MODE" ]
8+
then
9+
echo "ERROR: Must specify a serving mode: [ http | task ]"
10+
exit -1
11+
else
12+
if [ "$SERVICE_MODE" = "http" ]
13+
then
14+
echo "RUNNING HTTP SERVER"
15+
python http_server/ingress.py --debug
16+
elif [ "$SERVICE_MODE" == "task" ]
17+
then
18+
if [[ -z "$SERVICES_BROKER" ]]
19+
then
20+
echo "ERROR: SERVICES_BROKER variable not specified, cannot start celery worker."
21+
return -1
22+
fi
23+
/usr/src/app/wait-for-it.sh $(echo $SERVICES_BROKER | cut -d'/' -f 3) --timeout=20 --strict -- echo " $SERVICES_BROKER (Service Broker) is up"
24+
echo "RUNNING CELERY WORKER"
25+
celery --app=celery_app.celeryapp worker -Ofair -n nlp_${SERVICE_NAME}_worker@%h --queues=${SERVICE_NAME} -c ${CONCURRENCY}
26+
else
27+
echo "ERROR: Wrong serving command: $1"
28+
exit -1
29+
fi
30+
fi
31+
32+
echo "Service stopped"
File renamed without changes.

0 commit comments

Comments
 (0)