Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +138 -39
Dockerfile
CHANGED
|
@@ -1,47 +1,146 @@
|
|
| 1 |
-
#
|
| 2 |
-
FROM
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
&& apt-get clean \
|
| 11 |
-
&& rm -rf /var/lib/apt
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
COPY . .
|
| 16 |
-
|
| 17 |
-
# Install package from source code, compile translations
|
| 18 |
-
RUN ./venv/bin/pip install Babel==2.12.1 && ./venv/bin/python scripts/compile_locales.py \
|
| 19 |
-
&& ./venv/bin/pip install torch==2.2.0 --extra-index-url https://download.pytorch.org/whl/cpu \
|
| 20 |
-
&& ./venv/bin/pip install "numpy<2" \
|
| 21 |
-
&& ./venv/bin/pip install . \
|
| 22 |
-
&& ./venv/bin/pip cache purge
|
| 23 |
-
|
| 24 |
-
FROM python:3.11.11-slim-bullseye
|
| 25 |
-
|
| 26 |
-
ARG with_models=false
|
| 27 |
-
ARG models=""
|
| 28 |
-
|
| 29 |
-
RUN addgroup --system --gid 1032 libretranslate && adduser --system --uid 1032 libretranslate && mkdir -p /home/libretranslate/.local && chown -R libretranslate:libretranslate /home/libretranslate/.local
|
| 30 |
USER libretranslate
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
./venv/bin/python scripts/install_models.py --load_only_lang_codes "$models"; \
|
| 41 |
-
else \
|
| 42 |
-
./venv/bin/python scripts/install_models.py; \
|
| 43 |
-
fi \
|
| 44 |
-
fi
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# LibreTranslate Dockerfile with all 22 Indian Regional Languages
|
| 2 |
+
FROM libretranslate/libretranslate:latest
|
| 3 |
|
| 4 |
+
# Set environment variables for Indian languages
|
| 5 |
+
ENV LT_HOST=0.0.0.0
|
| 6 |
+
ENV LT_PORT=7860
|
| 7 |
+
ENV LT_THREADS=6
|
| 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 |
+
# Create necessary directories
|
| 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 |
+
# Switch back to libretranslate user
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
USER libretranslate
|
| 18 |
|
| 19 |
+
# Pre-install all 22 Indian regional languages plus English
|
| 20 |
+
RUN python -c "\
|
| 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 |
+
# Expose port
|
| 134 |
+
EXPOSE 5000
|
| 135 |
|
| 136 |
+
# Health check optimized for Indian languages
|
| 137 |
+
HEALTHCHECK --interval=30s --timeout=15s --start-period=60s --retries=3 \
|
| 138 |
+
CMD curl -f http://localhost:5000/health || exit 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
+
# Default command with Indian language optimization
|
| 141 |
+
CMD ["libretranslate", \
|
| 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"]
|