|
|
|
@@ -9,29 +9,6 @@ Ce projet permet de traduire un document PDF page par page en utilisant un modè |
|
|
|
- **Python** (version 3.8 ou supérieure) |
|
|
|
- **Ollama** installé et en cours d'exécution sur ta machine (en mode "serveur") |
|
|
|
- Un **document PDF** à traduire |
|
|
|
- Un modèle LLM spécialisé dans la traduction avec un context long. |
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
## Création d'un modèle LLM de traduction avec Ollama |
|
|
|
En partant du LLM [zongwei/gemma3-translator:4b](https://ollama.com/zongwei/gemma3-translator), nous allons créer un modèle optimisé pour la traduction avec Ollama. |
|
|
|
Pour info : Inutile de le downloader, il le serra automatiquement au lancement de la commande. |
|
|
|
|
|
|
|
```shell |
|
|
|
FROM zongwei/gemma3-translator:4b |
|
|
|
PARAMETER temperature 0.1 |
|
|
|
PARAMETER num_ctx 131072 |
|
|
|
SYSTEM """ |
|
|
|
You are a professional translator specialising in translating Ukrainian text into English. |
|
|
|
Translate accurately and naturally, respecting the original intonation used by the author of the text. |
|
|
|
You must not interpret the author's thoughts or reflections. |
|
|
|
Do not add any text before or after the text provided. |
|
|
|
""" |
|
|
|
``` |
|
|
|
Il faut ensuite compiler le modèle avec la commande : |
|
|
|
``` |
|
|
|
ollama create traductionUkrainienVersFrancais -f .\Modelfile |
|
|
|
``` |
|
|
|
|
|
|
|
## Installation |
|
|
|
|
|
|
|
@@ -44,11 +21,16 @@ ollama create traductionUkrainienVersFrancais -f .\Modelfile |
|
|
|
``` |
|
|
|
|
|
|
|
2. **Installer les dépendances Python** |
|
|
|
```bash |
|
|
|
pip install -r requirements.txt |
|
|
|
``` |
|
|
|
```bash |
|
|
|
pip install -r requirements.txt |
|
|
|
``` |
|
|
|
|
|
|
|
Puis faire : |
|
|
|
```bash |
|
|
|
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 |
|
|
|
``` |
|
|
|
|
|
|
|
3. **Placer votre fichier PDF** dans le répertoire du projet avec le nom configuré dans `main.py` (par défaut : `TaniaBorecMemoir(Ukr).pdf`) |
|
|
|
3. **Placer votre fichier PDF** dans le répertoire `Traduction` du projet avec le nom configuré dans `main.py` (par défaut : `TaniaBorecMemoir(Ukr).pdf`) |
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
@@ -57,37 +39,16 @@ ollama create traductionUkrainienVersFrancais -f .\Modelfile |
|
|
|
### Préparation |
|
|
|
|
|
|
|
1. **Démarrer Ollama en mode serveur** sur votre machine (port 11434 par défaut) |
|
|
|
```bash |
|
|
|
ollama serve |
|
|
|
``` |
|
|
|
|
|
|
|
2. **Vérifier que le modèle de traduction est disponible** |
|
|
|
```bash |
|
|
|
ollama list |
|
|
|
``` |
|
|
|
Vous devez voir `traductionUkrainienVersFrancais` dans la liste. |
|
|
|
|
|
|
|
Si ce n'est pas le cas, vous devez le générer comme décrit plus haut (paragraphe "Création d'un modèle LLM de traduction avec Ollama") |
|
|
|
|
|
|
|
3. **Placer votre PDF** dans le même répertoire que le script `main.py` |
|
|
|
### Paramétrage du script |
|
|
|
`PDF_PATH`= "TaniaBorecMemoir(Ukr).pdf" <- Le nom du fichier pdf à traduire. |
|
|
|
`OLLAMA_MODEL` = "mitmul/plamo-2-translate:latest" <- Le nom |
|
|
|
`OLLAMA_URL` = "http://localhost:11434/api/generate" <- URL par défaut d'Ollama |
|
|
|
`TARGET_LANGUAGE` = "français" <- Langue cible (ex: "français", "anglais", "allemand", "espagnol", etc.) |
|
|
|
`SYSTEM_PROMPT` = """You are a professional translator specialising in Ukrainian text translation. |
|
|
|
Translate accurately and naturally, respecting the original intonation used by the author of the text. |
|
|
|
You must not interpret the author's thoughts or reflections. |
|
|
|
Do not add any text before or after the text provided. |
|
|
|
Preserve the layout and structure of the original text.""" |
|
|
|
|
|
|
|
```bash |
|
|
|
ollama serve |
|
|
|
``` |
|
|
|
|
|
|
|
### Exécution |
|
|
|
|
|
|
|
1. **Lancer le script de traduction** |
|
|
|
```bash |
|
|
|
python main.py |
|
|
|
``` |
|
|
|
```bash |
|
|
|
python main.py |
|
|
|
``` |
|
|
|
|
|
|
|
2. **Le programme va :** |
|
|
|
- Extraire le texte de toutes les pages du PDF |
|
|
|
@@ -97,8 +58,8 @@ Preserve the layout and structure of the original text.""" |
|
|
|
- Envoyer chaque chunk au LLM pour traduction |
|
|
|
- Afficher la progression dans le terminal |
|
|
|
|
|
|
|
3. **Le résultat final** sera généré dans un fichier PDF nommé `[nom_original] (FR).pdf` |
|
|
|
- Exemple : `TaniaBorecMemoir(Ukr) (FR).pdf` |
|
|
|
3. **Le résultat final** sera généré dans un fichier PDF nommé `[nom_original](FR).pdf` |
|
|
|
- Exemple : `TaniaBorecMemoir(Ukr)(FR).pdf` |
|
|
|
|
|
|
|
### Fichier de sortie |
|
|
|
|
|
|
|
@@ -119,19 +80,3 @@ Vous pouvez modifier les paramètres suivants dans `main.py` : |
|
|
|
- `OUTPUT_PDF_PATH` : Chemin et nom du fichier PDF de sortie (généré autoamtiquement) |
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
## Dépannage |
|
|
|
|
|
|
|
### Erreur : "Connexion refusée à Ollama" |
|
|
|
- Vérifiez que Ollama est en cours d'exécution avec `ollama serve` |
|
|
|
- Vérifiez que l'URL est correcte (par défaut : `http://localhost:11434`) |
|
|
|
|
|
|
|
### Erreur : "Modèle non trouvé" |
|
|
|
- Exécutez : `ollama create traductionUkrainienVersFrancais -f .\Modelfile` |
|
|
|
|
|
|
|
### Le texte n'est pas bien séparé en paragraphes |
|
|
|
- Le script détecte automatiquement les doubles sauts de ligne |
|
|
|
- Si absent, il divise par phrases et regroupe en chunks de 1500 caractères |
|
|
|
|
|
|
|
--- |
|
|
|
|