LibreTranslate API de traduction
LibreTranslate fournit une API de traduction open source. Auto-hébergeable, fonctionne offline, facile à mettre en place. LibreTranslate est écrit en python et utilise la librairie de traduction argos.
Liens
LibreTranslate python pip
Vous pouvez exécuter votre propre serveur API avec seulement quelques lignes de configuration!
Assurez-vous que Python est installé (3.8 ou plus est recommandé)
Prérequis
Pyton pip et msgpack
1
sudo apt install python3-pip python3-msgpack
Mise à jour pip
1
python3 -m pip install --upgrade pip
Environnement virtuel libretranslate
Installer environnement virtuel
1
pip3 install virtualenv
Créer un dossier
1
2
mkdir ~/LibreTranslate
cd ~/LibreTranslate
Créer un environnement pour l’application
1
virtualenv LibreTranslateDev
activer l’environnement virtuel
1
source LibreTranslateDev/bin/activate
On arrive sur un prompt (LibreTranslateDev) bullsvm@vm-debian11:~/LibreTranslate$
Mettre à jour pip dans l’environnement
1
/home/bullsvm/LibreTranslate/LibreTranslateDev/bin/python -m pip install --upgrade pip
Installer libretranslate
1
pip install libretranslate
Tester libretranslate
1
libretranslate [args]
Puis ouvrez un navigateur Web à http://localhost:5000
How To Serve Flask Applications with Gunicorn and Nginx on Ubuntu 18.04
LibreTranslate reconstruit
Prérequis
Pyton pip et msgpack
1
sudo apt install python3-pip python3-msgpack
Mise à jour pip
1
python3 -m pip install --upgrade pip
Cloner le dépôt
Cloner le dépôt LibreTranslate original https://github.com/LibreTranslate/LibreTranslate.git
OU
Cloner le dépôt LibreTranslate modifié https://gitea.xoyize.xyz/yako/LibreTranslate.git
Se rendre dans le dossier utilisateur
1
2
cd /sharenfs/rnmkcy/
git clone https://github.com/LibreTranslate/LibreTranslate.git
Python environnement Venv
Créer un environnement dans le dossier en utilisant Venv de Python 3
1
python3 -m venv LibreTranslate
Activer l’environnement virtuel
1
source LibreTranslate/bin/activate
Votre invite de commande sera désormais préfixée avec le nom de votre environnement (LibreTranslate) yick@rnmkcy:~$
Installer et tester libretranslate
Installer libretranslate
1
2
cd LibreTranslate
pip install .
Veuillez patienter… Tester
1
2
libretranslate # sans arguments
libretranslate [args] # avec arguments
Note le premier lancement construit les modèles de traduction, patienter quelques minutes…
1
2
3
4
5
6
7
Updating language models
Found 86 models
[...]
Downloading English → French (1.0) ...
[...]
Loaded support for 44 languages (86 models total)!
Running on http://127.0.0.1:5000
Puis ouvrir un navigateur Web localement http://localhost:5000
Depuis un poste ayant un accès SSH au serveur
1
ssh -L 9500:localhost:5000 leno@192.168.0.215 -p 55215 -i /home/yann/.ssh/lenovo-ed25519
Ouvrir un navigateur sur le client et saisir localhost:9500
LibreTranslate - Service et Proxy ngiginx
Service systemd LibreTranslate
Créer un service pour s’assurer que notre application fonctionne juste après le démarrage du système.
1
sudo nano /etc/systemd/system/LibreTranslate.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[Unit]
Description=libretranslate
[Service]
Type=exec
User=leno
WorkingDirectory=/sharenfs/rnmkcy/LibreTranslate
ExecStart=/sharenfs/rnmkcy/LibreTranslate/bin/libretranslate
Restart=on-failure
RestartSec=30s
# Optional hardening to improve security
ReadWritePaths=/sharenfs/rnmkcy/LibreTranslate
[Install]
WantedBy=multi-user.target
Le fichier d’unité, le fichier de configuration source ou les drop-ins de LibreTranslate.service
ont changé sur le disque. Exécutez ‘sudo systemctl daemon-reload’ pour recharger les unités.
1
2
sudo systemctl daemon-reload
sudo systemctl start LibreTranslate
Activer le service
1
sudo systemctl enable LibreTranslate
Status
1
sudo systemctl status LibreTranslate
Proxy nginx
Le fichier de configuration nginx /etc/nginx/conf.d/traduction.conf
pour le domaine traduction.rnmkcy.eu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
server {
listen 80;
server_name traduction.rnmkcy.eu;
return 301 https://$server_name$request_uri;
}
server {
listen 443 http2 ssl;
server_name traduction.rnmkcy.eu;
#access_log off;
#error_log off;
# SSL Section
ssl_certificate /etc/ssl/private/rnmkcy.eu-fullchain.pem;
ssl_certificate_key /etc/ssl/private/rnmkcy.eu-key.pem;
ssl_protocols TLSv1.2 TLSv1.3;
# Using the recommended cipher suite from: https://wiki.mozilla.org/Security/Server_Side_TLS
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384';
ssl_session_timeout 10m;
ssl_session_cache shared:MozSSL:10m; # about 40000 sessions
ssl_session_tickets off;
# Specifies a curve for ECDHE ciphers.
ssl_ecdh_curve prime256v1;
# Server should determine the ciphers, not the client
ssl_prefer_server_ciphers on;
# Header section
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
add_header Referrer-Policy "strict-origin" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Download-Options "noopen" always;
add_header X-Robots-Tag "none" always;
add_header Feature-Policy "microphone 'none'; camera 'none'; geolocation 'none';" always;
# Newer header but not everywhere supported
add_header Permissions-Policy "microphone=(), camera=(), geolocation=()" always;
# Remove X-Powered-By, which is an information leak
fastcgi_hide_header X-Powered-By;
# Do not send nginx server header
server_tokens off;
# GZIP Section
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types text/xml text/javascript font/ttf font/eot font/otf application/x-javascript application/atom+xml application/javascript application/json application/manifest+json application/rss+xml application/x-web-app-manifest+json application/xhtml+xml application/xml image/svg+xml image/x-icon text/css text/plain;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 0;
}
}
Pour un site https , fichier /etc/nginx/conf.d/traduction.rnmkcy.eu.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
server {
listen 80;
listen [::]:80;
server_name traduction.rnmkcy.eu;
# redirect all plain HTTP requests to HTTPS
return 301 https://traduction.rnmkcy.eu$request_uri;
}
server {
# ipv4 listening port/protocol
listen 443 ssl http2;
# ipv6 listening port/protocol
listen [::]:443 ssl http2;
server_name traduction.rnmkcy.eu;
include /etc/nginx/conf.d/security.conf.inc;
location / {
proxy_pass http://127.0.0.1:5000;
}
}
Vérifier nginx
1
sudo nginx -t
Redémarrer nginx
1
sudo systemctl reload nginx