Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +34 -138
Dockerfile
CHANGED
|
@@ -1,146 +1,42 @@
|
|
| 1 |
-
|
| 2 |
-
FROM libretranslate/libretranslate:latest
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
ENV LT_CHAR_LIMIT=2000
|
| 9 |
-
ENV LT_LOAD_ONLY=en,hi,bn,te,mr,ta,ur,gu,kn,ml,or,pa,as,mai,mag,bh,sa,ne,ks,sd,kok,mni,sat,doi,bo
|
| 10 |
|
| 11 |
-
|
| 12 |
-
USER root
|
| 13 |
-
RUN mkdir -p /app/db /home/libretranslate/.local/share/argos-translate/packages
|
| 14 |
-
RUN chown -R libretranslate:libretranslate /app/db /home/libretranslate/.local/share/argos-translate/packages
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
USER libretranslate
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
import argostranslate.package; \
|
| 22 |
-
import argostranslate.translate; \\
|
| 23 |
-
# Download and install language packages; \
|
| 24 |
-
available_packages = argostranslate.package.get_available_packages(); \
|
| 25 |
-
\
|
| 26 |
-
# All 22 official Indian languages (ISO 639-1/639-3 codes); \
|
| 27 |
-
indian_languages = [ \
|
| 28 |
-
'hi', # Hindi; \
|
| 29 |
-
'bn', # Bengali; \
|
| 30 |
-
'te', # Telugu; \
|
| 31 |
-
'mr', # Marathi; \
|
| 32 |
-
'ta', # Tamil; \
|
| 33 |
-
'ur', # Urdu; \
|
| 34 |
-
'gu', # Gujarati; \
|
| 35 |
-
'kn', # Kannada; \
|
| 36 |
-
'ml', # Malayalam; \
|
| 37 |
-
'or', # Odia; \
|
| 38 |
-
'pa', # Punjabi; \
|
| 39 |
-
'as', # Assamese; \
|
| 40 |
-
'mai', # Maithili; \
|
| 41 |
-
'mag', # Magahi; \
|
| 42 |
-
'bh', # Bhojpuri; \
|
| 43 |
-
'sa', # Sanskrit; \
|
| 44 |
-
'ne', # Nepali; \
|
| 45 |
-
'ks', # Kashmiri; \
|
| 46 |
-
'sd', # Sindhi; \
|
| 47 |
-
'kok', # Konkani; \
|
| 48 |
-
'mni', # Manipuri; \
|
| 49 |
-
'sat', # Santali; \
|
| 50 |
-
'doi', # Dogri; \
|
| 51 |
-
'bo', # Bodo; \
|
| 52 |
-
]; \\
|
| 53 |
-
# Create comprehensive language pairs; \
|
| 54 |
-
language_pairs = []; \
|
| 55 |
-
\
|
| 56 |
-
# Primary focus: English to/from all Indian languages (PRIORITY PAIRS); \
|
| 57 |
-
print('Adding English <-> Indian language pairs...'); \
|
| 58 |
-
for lang in indian_languages: \
|
| 59 |
-
language_pairs.extend([('en', lang), (lang, 'en')]); \
|
| 60 |
-
\
|
| 61 |
-
# Add ALL possible inter-Indian language combinations; \
|
| 62 |
-
print('Adding inter-Indian language pairs...'); \
|
| 63 |
-
for i, lang1 in enumerate(indian_languages): \
|
| 64 |
-
for j, lang2 in enumerate(indian_languages): \
|
| 65 |
-
if i != j: \
|
| 66 |
-
language_pairs.append((lang1, lang2)); \
|
| 67 |
-
\
|
| 68 |
-
# Additional international language pairs with Indian languages; \
|
| 69 |
-
international_languages = ['es', 'fr', 'de', 'it', 'pt', 'ru', 'zh', 'ja', 'ar', 'ko']; \
|
| 70 |
-
print('Adding international language pairs with Indian languages...'); \
|
| 71 |
-
for indian_lang in indian_languages: \
|
| 72 |
-
for intl_lang in international_languages: \
|
| 73 |
-
language_pairs.extend([(indian_lang, intl_lang), (intl_lang, indian_lang)]); \\
|
| 74 |
-
# Install available packages with priority system; \
|
| 75 |
-
installed_count = 0; \
|
| 76 |
-
failed_count = 0; \
|
| 77 |
-
priority_installed = 0; \
|
| 78 |
-
\
|
| 79 |
-
print('Starting installation of language models...'); \
|
| 80 |
-
print('Total language pairs to attempt:', len(language_pairs)); \
|
| 81 |
-
print('Priority: English <-> Indian languages first'); \
|
| 82 |
-
\
|
| 83 |
-
# Separate English-Indian pairs for priority installation; \
|
| 84 |
-
english_indian_pairs = [(f, t) for f, t in language_pairs if 'en' in (f, t)]; \
|
| 85 |
-
other_pairs = [(f, t) for f, t in language_pairs if 'en' not in (f, t)]; \
|
| 86 |
-
\
|
| 87 |
-
print('English-Indian priority pairs:', len(english_indian_pairs)); \
|
| 88 |
-
print('Other language pairs:', len(other_pairs)); \
|
| 89 |
-
\
|
| 90 |
-
# Install English-Indian pairs first (PRIORITY); \
|
| 91 |
-
print('Installing Priority Pairs (English <-> Indian)'); \
|
| 92 |
-
for from_code, to_code in english_indian_pairs: \
|
| 93 |
-
package_to_install = next((pkg for pkg in available_packages if pkg.from_code == from_code and pkg.to_code == to_code), None); \
|
| 94 |
-
if package_to_install: \
|
| 95 |
-
try: \
|
| 96 |
-
argostranslate.package.install_from_path(package_to_install.download()); \
|
| 97 |
-
print('PRIORITY: Successfully installed', from_code, '->', to_code); \
|
| 98 |
-
installed_count += 1; \
|
| 99 |
-
priority_installed += 1; \
|
| 100 |
-
except Exception as e: \
|
| 101 |
-
print('PRIORITY: Failed to install', from_code, '->', to_code, ':', str(e)); \
|
| 102 |
-
failed_count += 1; \
|
| 103 |
-
else: \
|
| 104 |
-
print('PRIORITY: Package not available:', from_code, '->', to_code); \
|
| 105 |
-
failed_count += 1; \
|
| 106 |
-
\
|
| 107 |
-
# Install other pairs (inter-Indian and international); \
|
| 108 |
-
print('Installing Additional Pairs (Inter-Indian & International)'); \
|
| 109 |
-
for from_code, to_code in other_pairs: \
|
| 110 |
-
package_to_install = next((pkg for pkg in available_packages if pkg.from_code == from_code and pkg.to_code == to_code), None); \
|
| 111 |
-
if package_to_install: \
|
| 112 |
-
try: \
|
| 113 |
-
argostranslate.package.install_from_path(package_to_install.download()); \
|
| 114 |
-
print('Successfully installed', from_code, '->', to_code); \
|
| 115 |
-
installed_count += 1; \
|
| 116 |
-
except Exception as e: \
|
| 117 |
-
print('Failed to install', from_code, '->', to_code, ':', str(e)); \
|
| 118 |
-
failed_count += 1; \
|
| 119 |
-
else: \
|
| 120 |
-
failed_count += 1; \\
|
| 121 |
-
print('Final Installation Summary'); \
|
| 122 |
-
print('Priority pairs (English <-> Indian):', priority_installed, 'installed'); \
|
| 123 |
-
print('Total successfully installed:', installed_count, 'language pairs'); \
|
| 124 |
-
print('Failed or unavailable:', failed_count, 'language pairs'); \
|
| 125 |
-
print('FOCUS: English to Indian Regional Languages Translation Server Ready!'); \
|
| 126 |
-
print('Supported: All available English <-> Indian language pairs'); \
|
| 127 |
-
print('Bonus: Inter-Indian and international language pairs where available'); \
|
| 128 |
-
print('Note: Some regional languages may not be available in Argos Translate yet.'); \
|
| 129 |
-
print('Available languages will be loaded automatically on server start.'); \
|
| 130 |
-
print('Server optimized for English to Indian regional language translation!'); \
|
| 131 |
-
"
|
| 132 |
|
| 133 |
-
|
| 134 |
-
EXPOSE 5000
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
"--host", "0.0.0.0", \
|
| 143 |
-
"--port", "7860", \
|
| 144 |
-
"--threads", "6", \
|
| 145 |
-
"--char-limit", "2000", \
|
| 146 |
-
"--load-only", "en,hi,bn,te,mr,ta,ur,gu,kn,ml,or,pa,as,ne,sa"]
|
|
|
|
| 1 |
+
FROM python:3.11.11-slim-bullseye as builder
|
|
|
|
| 2 |
|
| 3 |
+
RUN apt-get update -qq \
|
| 4 |
+
&& apt-get -qqq install --no-install-recommends -y pkg-config gcc g++ \
|
| 5 |
+
&& apt-get clean \
|
| 6 |
+
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
RUN python -mvenv venv && ./venv/bin/pip install --upgrade pip
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
COPY . .
|
| 11 |
+
|
| 12 |
+
# Install package from source code, compile translations
|
| 13 |
+
RUN ./venv/bin/pip install Babel==2.12.1 && ./venv/bin/python scripts/compile_locales.py \
|
| 14 |
+
&& ./venv/bin/pip install torch==2.2.0 --extra-index-url https://download.pytorch.org/whl/cpu \
|
| 15 |
+
&& ./venv/bin/pip install "numpy<2" \
|
| 16 |
+
&& ./venv/bin/pip install . \
|
| 17 |
+
&& ./venv/bin/pip cache purge
|
| 18 |
+
|
| 19 |
+
FROM python:3.11.11-slim-bullseye
|
| 20 |
+
|
| 21 |
+
ARG with_models=false
|
| 22 |
+
ARG models=""
|
| 23 |
+
|
| 24 |
+
RUN addgroup --system --gid 1032 libretranslate && adduser --system --uid 1032 libretranslate && mkdir -p /home/libretranslate/.local && chown -R libretranslate:libretranslate /home/libretranslate/.local
|
| 25 |
USER libretranslate
|
| 26 |
|
| 27 |
+
COPY --from=builder --chown=1032:1032 /app /app
|
| 28 |
+
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
COPY --from=builder --chown=1032:1032 /app/venv/bin/ltmanage /usr/bin/
|
|
|
|
| 31 |
|
| 32 |
+
RUN if [ "$with_models" = "true" ]; then \
|
| 33 |
+
# initialize the language models
|
| 34 |
+
if [ ! -z "$models" ]; then \
|
| 35 |
+
./venv/bin/python scripts/install_models.py --load_only_lang_codes "$models"; \
|
| 36 |
+
else \
|
| 37 |
+
./venv/bin/python scripts/install_models.py; \
|
| 38 |
+
fi \
|
| 39 |
+
fi
|
| 40 |
|
| 41 |
+
EXPOSE 5000
|
| 42 |
+
ENTRYPOINT [ "./venv/bin/libretranslate", "--host", "*" ]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|