|
|
2 周前 | |
|---|---|---|
| Modelfile | 2 周前 | |
| README.md | 2 周前 | |
| TaniaBorecMemoir(Ukr).pdf | 2 周前 | |
| main.py | 2 周前 | |
| requirements.txt | 2 周前 | |
Ce projet permet de traduire un document PDF page par page en utilisant un modèle LLM local (Ollama) optimisé pour la traduction.
En partant du LLM zongwei/gemma3-translator:4b, 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.
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
Cloner ou télécharger le projet
cd chemin/vers/votre/projet
git pull https://git.alex-design.fr/Alex/python.traduction
Installer les dépendances Python
pip install -r requirements.txt
Placer votre fichier PDF dans le répertoire du projet avec le nom configuré dans main.py (par défaut : TaniaBorecMemoir(Ukr).pdf)
Démarrer Ollama en mode serveur sur votre machine (port 11434 par défaut)
ollama serve
Vérifier que le modèle de traduction est disponible
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”)
Placer votre PDF dans le même répertoire que le script main.py
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.“””
Lancer le script de traduction
python main.py
Le programme va :
Le résultat final sera généré dans un fichier PDF nommé [nom_original] (FR).pdf
TaniaBorecMemoir(Ukr) (FR).pdfLe PDF généré contient :
Vous pouvez modifier les paramètres suivants dans main.py :
PDF_PATH : Chemin du fichier PDF à traduireOLLAMA_MODEL : Nom du modèle Ollama à utiliserOLLAMA_URL : URL du serveur Ollama (par défaut : http://localhost:11434/api/generate)OUTPUT_PDF_PATH : Chemin et nom du fichier PDF de sortie (généré autoamtiquement)ollama servehttp://localhost:11434)ollama create traductionUkrainienVersFrancais -f .\Modelfile