From c28bbc6be77f6ebd1de09654343cf16940484fb4 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 5 Jan 2026 00:51:50 +0100 Subject: [PATCH] =?UTF-8?q?g=C3=A9n=C3=A9ration=20d'un=20fichier=20texte?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Modelfile | 12 ++++++------ main.py | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Modelfile b/Modelfile index 7b9f8e4..af8c14c 100644 --- a/Modelfile +++ b/Modelfile @@ -1,10 +1,10 @@ FROM zongwei/gemma3-translator:4b -PARAMETER temperature 0.1 +PARAMETER temperature 0.3 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 always answer in french. -You must not interpret the author's thoughts or reflections. -Do not add any text before or after the text provided. +Tu es un traducteur professionnel spécialisé dans la traduction de textes historiques ukrainiens. +Traduis avec précision et naturel, en respectant l'intonation originale utilisée par l'auteur du texte. +Tu dois toujours répondre en français. +Tu ne dois pas interpréter les pensées ou les réflexions de l'auteur. +N'ajoutes aucun texte sous quelle forme que ce soit avant ou après le texte tarduit. """ \ No newline at end of file diff --git a/main.py b/main.py index f3be63d..99047eb 100644 --- a/main.py +++ b/main.py @@ -271,6 +271,24 @@ def create_pdf_from_results(results, output_path): doc.build(story) print(f"PDF généré avec succès : {output_path}") +def create_txt_from_results(results, output_path): + """Crée un fichier TXT à partir des résultats de traduction.""" + OUTPUT_TXT_PATH = output_path.replace(".pdf", f".txt") # Chemin du fichier TXT de sortie + + # Titre avec la langue cible + title_text = f"Traduction - Ukrainien vers {TARGET_LANGUAGE.capitalize()}" + with open(OUTPUT_TXT_PATH, 'w', encoding='utf-8') as txt_file: + txt_file.write(title_text + "\n\n") + + # Contenu + for page_num, translation in results.items(): + # Préserver la mise en page en convertissant les sauts de ligne + txt_file.write(translation + "\n\n") + + # Infos sur le LLM + txt_file.write("\n") + txt_file.write(display_llm_info() + "\n") + def main(): # Affiche les informations du modèle LLM display_llm_info() @@ -299,6 +317,7 @@ def main(): # Création du PDF avec tous les résultats create_pdf_from_results(results, OUTPUT_PDF_PATH) + create_txt_from_results(results, OUTPUT_PDF_PATH) if __name__ == "__main__": main()