From 64c1049d7bf008c45de0f82790e7d2733afac562 Mon Sep 17 00:00:00 2001 From: deng Date: Sat, 19 Jul 2025 22:56:43 +0800 Subject: [PATCH] 1) apply multi stage build, 2) rm gemini --- .gitignore | 3 +- Dockerfile | 40 ++++++++--------- requirements.txt | 97 ------------------------------------------ translator/app.py | 7 --- translator/config.yaml | 9 +--- 5 files changed, 22 insertions(+), 134 deletions(-) delete mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index 96d38ee..40844ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__ .ruff_cache -.venv \ No newline at end of file +.venv +*.tar \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 2b237d2..200fd4e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,29 +1,25 @@ -FROM python:3.13-slim +# Stage1 +FROM python:3.13-slim-bullseye AS builder -# Set timezone -ARG WTH -ENV WTH=$WTH -ENV TZ="Asia/Taipei" -RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - -# Init workspace -RUN mkdir -p /app +RUN apt update && apt install -y curl +RUN curl -sSL https://install.python-poetry.org | python3 - +ENV PATH="/root/.local/bin:$PATH" +RUN poetry config virtualenvs.create false WORKDIR /app +COPY pyproject.toml poetry.lock ./ +RUN poetry install --with main -# Install dependencies -# Poetry exportation cmd: poetry export --without-hashes --without dev -f requirements.txt -o requirements.tx -COPY ./requirements.txt . -RUN pip install --no-cache-dir -r requirements.txt +# Stage2 +FROM python:3.13-slim-bullseye AS final -# Copy source copy +ENV TZ="Asia/Taipei" +RUN apt update && apt install -y curl +COPY --from=builder /usr/local/lib/python3.13/site-packages /usr/local/lib/python3.13/site-packages +WORKDIR /app COPY ./translator . - -# Install tools -RUN apt update -RUN apt install -y curl - -# Run app -CMD streamlit run app.py --server.port=8501 --server.enableCORS=false --server.enableXsrfProtection=false +EXPOSE 8501 +CMD ["python", "-m", "streamlit", "run", "app.py", "--server.port=8501", "--server.enableCORS=false", "--server.enableXsrfProtection=false"] # Build -# docker build -t translator:latest . \ No newline at end of file +# docker build --platform=linux/amd64 -t translator:latest . +# docker save -o translator.tar translator:latest \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 0c8f774..0000000 --- a/requirements.txt +++ /dev/null @@ -1,97 +0,0 @@ -aiohappyeyeballs==2.6.1 ; python_version >= "3.13" and python_version < "4.0" -aiohttp==3.12.8 ; python_version >= "3.13" and python_version < "4.0" -aiosignal==1.3.2 ; python_version >= "3.13" and python_version < "4.0" -altair==5.5.0 ; python_version >= "3.13" and python_version < "4.0" -annotated-types==0.7.0 ; python_version >= "3.13" and python_version < "4.0" -anyio==4.9.0 ; python_version >= "3.13" and python_version < "4.0" -attrs==25.3.0 ; python_version >= "3.13" and python_version < "4.0" -blinker==1.9.0 ; python_version >= "3.13" and python_version < "4.0" -cachetools==5.5.2 ; python_version >= "3.13" and python_version < "4.0" -certifi==2025.4.26 ; python_version >= "3.13" and python_version < "4.0" -cffi==1.17.1 ; python_version >= "3.13" and python_version < "4.0" and platform_python_implementation == "PyPy" -charset-normalizer==3.4.2 ; python_version >= "3.13" and python_version < "4.0" -click==8.2.1 ; python_version >= "3.13" and python_version < "4.0" -colorama==0.4.6 ; python_version >= "3.13" and python_version < "4.0" and platform_system == "Windows" -dataclasses-json==0.6.7 ; python_version >= "3.13" and python_version < "4.0" -distro==1.9.0 ; python_version >= "3.13" and python_version < "4.0" -filetype==1.2.0 ; python_version >= "3.13" and python_version < "4.0" -frozenlist==1.6.2 ; python_version >= "3.13" and python_version < "4.0" -gitdb==4.0.12 ; python_version >= "3.13" and python_version < "4.0" -gitpython==3.1.44 ; python_version >= "3.13" and python_version < "4.0" -google-ai-generativelanguage==0.6.18 ; python_version >= "3.13" and python_version < "4.0" -google-api-core==2.25.1 ; python_version >= "3.13" and python_version < "4.0" -google-auth==2.40.3 ; python_version >= "3.13" and python_version < "4.0" -googleapis-common-protos==1.70.0 ; python_version >= "3.13" and python_version < "4.0" -greenlet==3.2.2 ; python_version == "3.13" and (platform_machine == "aarch64" or platform_machine == "ppc64le" or platform_machine == "x86_64" or platform_machine == "amd64" or platform_machine == "AMD64" or platform_machine == "win32" or platform_machine == "WIN32") -grpcio-status==1.73.0 ; python_version >= "3.13" and python_version < "4.0" -grpcio==1.73.0 ; python_version >= "3.13" and python_version < "4.0" -h11==0.16.0 ; python_version >= "3.13" and python_version < "4.0" -httpcore==1.0.9 ; python_version >= "3.13" and python_version < "4.0" -httpx-sse==0.4.0 ; python_version >= "3.13" and python_version < "4.0" -httpx==0.28.1 ; python_version >= "3.13" and python_version < "4.0" -idna==3.10 ; python_version >= "3.13" and python_version < "4.0" -jinja2==3.1.6 ; python_version >= "3.13" and python_version < "4.0" -jiter==0.10.0 ; python_version >= "3.13" and python_version < "4.0" -jsonpatch==1.33 ; python_version >= "3.13" and python_version < "4.0" -jsonpointer==3.0.0 ; python_version >= "3.13" and python_version < "4.0" -jsonschema-specifications==2025.4.1 ; python_version >= "3.13" and python_version < "4.0" -jsonschema==4.24.0 ; python_version >= "3.13" and python_version < "4.0" -langchain-community==0.3.24 ; python_version >= "3.13" and python_version < "4.0" -langchain-core==0.3.65 ; python_version >= "3.13" and python_version < "4.0" -langchain-google-genai==2.1.5 ; python_version >= "3.13" and python_version < "4.0" -langchain-ollama==0.3.3 ; python_version >= "3.13" and python_version < "4.0" -langchain-openai==0.3.24 ; python_version >= "3.13" and python_version < "4.0" -langchain-text-splitters==0.3.8 ; python_version >= "3.13" and python_version < "4.0" -langchain==0.3.25 ; python_version >= "3.13" and python_version < "4.0" -langsmith==0.3.45 ; python_version >= "3.13" and python_version < "4.0" -markupsafe==3.0.2 ; python_version >= "3.13" and python_version < "4.0" -marshmallow==3.26.1 ; python_version >= "3.13" and python_version < "4.0" -multidict==6.4.4 ; python_version >= "3.13" and python_version < "4.0" -mypy-extensions==1.1.0 ; python_version >= "3.13" and python_version < "4.0" -narwhals==1.41.0 ; python_version >= "3.13" and python_version < "4.0" -numpy==2.2.6 ; python_version >= "3.13" and python_version < "4.0" -ollama==0.5.1 ; python_version >= "3.13" and python_version < "4.0" -openai==1.88.0 ; python_version >= "3.13" and python_version < "4.0" -orjson==3.10.18 ; python_version >= "3.13" and python_version < "4.0" and platform_python_implementation != "PyPy" -packaging==24.2 ; python_version >= "3.13" and python_version < "4.0" -pandas==2.2.3 ; python_version >= "3.13" and python_version < "4.0" -pillow==11.2.1 ; python_version >= "3.13" and python_version < "4.0" -propcache==0.3.1 ; python_version >= "3.13" and python_version < "4.0" -proto-plus==1.26.1 ; python_version >= "3.13" and python_version < "4.0" -protobuf==6.31.1 ; python_version >= "3.13" and python_version < "4.0" -pyarrow==20.0.0 ; python_version >= "3.13" and python_version < "4.0" -pyasn1-modules==0.4.2 ; python_version >= "3.13" and python_version < "4.0" -pyasn1==0.6.1 ; python_version >= "3.13" and python_version < "4.0" -pycparser==2.22 ; python_version >= "3.13" and python_version < "4.0" and platform_python_implementation == "PyPy" -pydantic-core==2.33.2 ; python_version >= "3.13" and python_version < "4.0" -pydantic-settings==2.9.1 ; python_version >= "3.13" and python_version < "4.0" -pydantic==2.11.5 ; python_version >= "3.13" and python_version < "4.0" -pydeck==0.9.1 ; python_version >= "3.13" and python_version < "4.0" -python-dateutil==2.9.0.post0 ; python_version >= "3.13" and python_version < "4.0" -python-dotenv==1.1.0 ; python_version >= "3.13" and python_version < "4.0" -pytz==2025.2 ; python_version >= "3.13" and python_version < "4.0" -pyyaml==6.0.2 ; python_version >= "3.13" and python_version < "4.0" -referencing==0.36.2 ; python_version >= "3.13" and python_version < "4.0" -regex==2024.11.6 ; python_version >= "3.13" and python_version < "4.0" -requests-toolbelt==1.0.0 ; python_version >= "3.13" and python_version < "4.0" -requests==2.32.3 ; python_version >= "3.13" and python_version < "4.0" -rpds-py==0.25.1 ; python_version >= "3.13" and python_version < "4.0" -rsa==4.9.1 ; python_version >= "3.13" and python_version < "4.0" -six==1.17.0 ; python_version >= "3.13" and python_version < "4.0" -smmap==5.0.2 ; python_version >= "3.13" and python_version < "4.0" -sniffio==1.3.1 ; python_version >= "3.13" and python_version < "4.0" -sqlalchemy==2.0.41 ; python_version >= "3.13" and python_version < "4.0" -streamlit==1.45.1 ; python_version >= "3.13" and python_version < "4.0" -tenacity==9.1.2 ; python_version >= "3.13" and python_version < "4.0" -tiktoken==0.9.0 ; python_version >= "3.13" and python_version < "4.0" -toml==0.10.2 ; python_version >= "3.13" and python_version < "4.0" -tornado==6.5.1 ; python_version >= "3.13" and python_version < "4.0" -tqdm==4.67.1 ; python_version >= "3.13" and python_version < "4.0" -typing-extensions==4.14.0 ; python_version >= "3.13" and python_version < "4.0" -typing-inspect==0.9.0 ; python_version >= "3.13" and python_version < "4.0" -typing-inspection==0.4.1 ; python_version >= "3.13" and python_version < "4.0" -tzdata==2025.2 ; python_version >= "3.13" and python_version < "4.0" -urllib3==2.4.0 ; python_version >= "3.13" and python_version < "4.0" -watchdog==6.0.0 ; python_version >= "3.13" and python_version < "4.0" -yarl==1.20.0 ; python_version >= "3.13" and python_version < "4.0" -zstandard==0.23.0 ; python_version >= "3.13" and python_version < "4.0" diff --git a/translator/app.py b/translator/app.py index ef1525a..2894cb6 100644 --- a/translator/app.py +++ b/translator/app.py @@ -36,13 +36,6 @@ class TranslatorApp: keep_alive=self._config['app']['ollama']['keep_alive'], stop=None ) - elif self._config['app']['llm_mode'] == 'gemini': - llm = ChatGoogleGenerativeAI( - model=self._config['app']['gemini']['model_name'], - temperature=self._config['app']['gemini']['temperature'], - max_tokens=self._config['app']['gemini']['max_tokens'], - top_p=self._config['app']['gemini']['top_p'] - ) elif self._config['app']['llm_mode'] == 'openai': llm = ChatOpenAI( model=self._config['app']['openai']['model_name'], diff --git a/translator/config.yaml b/translator/config.yaml index 29983ff..5283052 100644 --- a/translator/config.yaml +++ b/translator/config.yaml @@ -5,18 +5,13 @@ app: ollama: url: http://localhost:11434 model_name: gemma3:12b-it-qat - max_tokens: 256 + max_tokens: 512 temperature: 0.2 top_p: 0.9 keep_alive: 2m - gemini: - model_name: gemini-2.5-flash - max_tokens: 512 - temperature: 0.2 - top_p: 0.9 openai: model_name: gpt-4.1-nano - max_tokens: 512 + max_tokens: 1024 temperature: 0.2 top_p: 0.9 lang_directions: