Upgrade spacy to 3.7.4. Dockerfile rewrites

parent 0bc4c6b3
Pipeline #5779 failed
use_nix
export LANG=C.UTF-8
...@@ -8,11 +8,18 @@ WORKDIR /tmp ...@@ -8,11 +8,18 @@ WORKDIR /tmp
# Install dependencies: # Install dependencies:
COPY ./requirements.txt . COPY ./requirements.txt .
RUN pip install -r requirements.txt RUN pip install -r requirements.txt -f https://download.pytorch.org/whl/torch_stable.html
# Build args
# https://docs.docker.com/build/guide/build-args/
#ARG PORT 8001
# https://spacy.io/usage/models/ # https://spacy.io/usage/models/
ARG MODEL en_core_web_trf
RUN python -m spacy download ${MODEL}
#RUN python -m spacy download en_core_web_trf #RUN python -m spacy download en_core_web_trf
RUN python -m spacy download fr_dep_news_trf # 8001 #RUN python -m spacy download fr_dep_news_trf # 8001
#RUN python -m spacy download de_dep_news_trf # 8002 #RUN python -m spacy download de_dep_news_trf # 8002
#RUN python -m spacy download uk_core_news_trf # 8003 #RUN python -m spacy download uk_core_news_trf # 8003
#RUN python -m spacy download ru_core_news_trf # 8004 #RUN python -m spacy download ru_core_news_trf # 8004
...@@ -30,4 +37,5 @@ WORKDIR /code ...@@ -30,4 +37,5 @@ WORKDIR /code
COPY src/main.py . COPY src/main.py .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8001"] ENV SPACY_MODEL=${MODEL}
CMD uvicorn main:app --host 0.0.0.0 --port 8000
with (import <nixpkgs> {});
stdenv.mkDerivation rec {
name = "env";
env = buildEnv {
name = name;
paths = buildInputs;
};
buildInputs = [
docker-compose
];
}
services: services:
spacy-server-de:
build: ./
ports:
- 8002:8002
spacy-server: spacy-server:
build: ./ build:
context: ./
args:
MODEL: en_core_web_trf
ports: ports:
- 8001:8001 - 8000:8000
spacy-server-fr:
build:
context: ./
args:
MODEL: fr_dep_news_trf
ports:
- 8001:8000
# spacy-server-de:
# build:
# context: ./
# args:
# MODEL: de_dep_news_trf
# ports:
# - 8002:8000
# spacy-server-uk:
# build:
# context: ./
# args:
# MODEL: uk_core_news_trf
# ports:
# - 8003:8000
# spacy-server-ru:
# build:
# context: ./
# args:
# MODEL: ru_core_news_trf
# ports:
# - 8004:8000
# spacy-server-pl:
# build:
# context: ./
# args:
# PORT: 8004
# MODEL: pl_core_news_trf
# ports:
# - 8004:8000
# spacy-server-es:
# build:
# context: ./
# args:
# PORT: 8005
# MODEL: es_core_news_trf
# ports:
# - 8005:8000
# spacy-server-pt:
# build:
# context: ./
# args:
# PORT: 8006
# MODEL: es_core_news_trf
# ports:
# - 8006:8000
# spacy-server-it:
# build:
# context: ./
# args:
# PORT: 8007
# MODEL: it_core_news_trf
# ports:
# - 8007:8000
# spacy-server-zh:
# build:
# context: ./
# args:
# PORT: 8008
# MODEL: it_core_news_trf
# ports:
# - 8008:8000
# spacy-server-el:
# build:
# context: ./
# args:
# PORT: 8009
# MODEL: el_core_news_trf
# ports:
# - 8009:8000
# spacy-server-xx:
# build:
# context: ./
# args:
# PORT: 8010
# MODEL: xx_ent_wiki_trf
# ports:
# - 8010:8000
...@@ -4,11 +4,16 @@ ...@@ -4,11 +4,16 @@
spacy-transformers spacy-transformers
setuptools setuptools
numpy==1.24.2 fastapi==0.110.0
sense2vec==2.0.0 numpy==1.26.4
ujson==4.2.0
fastapi==0.55.0
uvicorn==0.15.0
pytest==6.2.5 pytest==6.2.5
requests==2.26.0 sense2vec==2.0.2
spacy==3.1.3 six==1.16.0
spacy==3.7.4
uvicorn==0.28.0
# If you need GPU support, just change the following lines
# https://stackoverflow.com/questions/68845314/install-pytorch-cpu-only-in-dockerfile
# https://download.pytorch.org/whl/torch_stable.html
# torch==2.2.1
torch==2.2.1+cpu
...@@ -6,20 +6,20 @@ from typing import List ...@@ -6,20 +6,20 @@ from typing import List
import spacy import spacy
from dataclasses import dataclass from dataclasses import dataclass
from fastapi import FastAPI, HTTPException from fastapi import FastAPI, HTTPException
from pydantic import BaseModel, root_validator from pydantic import BaseModel, model_validator
from sense2vec import Sense2VecComponent from sense2vec import Sense2VecComponent
from starlette.responses import Response from starlette.responses import Response
from starlette.status import HTTP_204_NO_CONTENT from starlette.status import HTTP_204_NO_CONTENT
# download model before # download model before
import fr_core_news_md #import fr_core_news_md
app: FastAPI = FastAPI() app: FastAPI = FastAPI()
#model: str = os.getenv('SPACY_MODEL') model: str = os.getenv('SPACY_MODEL') or 'en_core_web_trf'
#pipeline_error: str = f"The model ({model}) doesn't support " + '{}.' #pipeline_error: str = f"The model ({model}) doesn't support " + '{}.'
#nlp: spacy = spacy.load(model) nlp: spacy = spacy.load(model)
nlp: spacy = fr_core_news_md.load() #nlp: spacy = fr_core_news_md.load()
if os.getenv('SENSE2VEC') == '1': if os.getenv('SENSE2VEC') == '1':
s2v = nlp.add_pipe("sense2vec") s2v = nlp.add_pipe("sense2vec")
...@@ -131,7 +131,7 @@ class PhraseInSentence(BaseModel): ...@@ -131,7 +131,7 @@ class PhraseInSentence(BaseModel):
sentence: str sentence: str
phrase: str phrase: str
@root_validator @model_validator(mode='after')
def phrase_must_be_in_sentence(cls, values): def phrase_must_be_in_sentence(cls, values):
if values.get('phrase') not in values.get('sentence'): if values.get('phrase') not in values.get('sentence'):
raise ValueError('phrase must be in sentence') raise ValueError('phrase must be in sentence')
...@@ -195,7 +195,7 @@ class Token: ...@@ -195,7 +195,7 @@ class Token:
tag: str tag: str
dep: str dep: str
lang: str lang: str
prob: int prob: float
char_offset: int char_offset: int
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment