diff --git a/__pycache__/x2_master_export2translate.cpython-310.pyc b/__pycache__/x2_master_export2translate.cpython-310.pyc index 22cca8f..91351e7 100644 Binary files a/__pycache__/x2_master_export2translate.cpython-310.pyc and b/__pycache__/x2_master_export2translate.cpython-310.pyc differ diff --git a/__pycache__/x3_llm_auto_translate.cpython-310.pyc b/__pycache__/x3_llm_auto_translate.cpython-310.pyc index 942c869..8437a19 100644 Binary files a/__pycache__/x3_llm_auto_translate.cpython-310.pyc and b/__pycache__/x3_llm_auto_translate.cpython-310.pyc differ diff --git a/__pycache__/x6_update_from_master.cpython-310.pyc b/__pycache__/x6_update_from_master.cpython-310.pyc index 05ab2e8..bdd55f8 100644 Binary files a/__pycache__/x6_update_from_master.cpython-310.pyc and b/__pycache__/x6_update_from_master.cpython-310.pyc differ diff --git a/translation_config.json b/translation_config.json index c621fd1..2cf5701 100644 --- a/translation_config.json +++ b/translation_config.json @@ -1,12 +1,12 @@ { - "codigo_tipo_PLC": "allenbradley", - "codigo_columna_maestra": "en-US", - "codigo_idioma_seleccionado": "it-IT", - "codigo_idioma_secundario": "en-US", - "work_dir": "C:/Trabajo/VM/35 - 9.4023 - Shibuya - Mayo - Usa/Reporte/Language", - "master_name": "1_hmi_master_translates_allenbradley.xlsx", - "translate_name": "2_master_export2translate_allenbradley_it-IT.xlsx", - "auto_translate_name": "3_master_export2translate_translated_allenbradley_it-IT.xlsx", + "codigo_tipo_PLC": "siemens", + "codigo_columna_maestra": "it-IT", + "codigo_idioma_seleccionado": "es-ES", + "codigo_idioma_secundario": "en-GB", + "work_dir": "C:/Trabajo/VM/38 - 93998 - Sipa - PortoRico/Reporte/Language", + "master_name": "1_hmi_master_translates_siemens.xlsx", + "translate_name": "2_master_export2translate_siemens_es-ES.xlsx", + "auto_translate_name": "3_master_export2translate_translated_siemens_es-ES.xlsx", "nivel_afinidad_minimo": 0.5, "traducir_todo": false } \ No newline at end of file diff --git a/x2_master_export2translate.py b/x2_master_export2translate.py index 4586df0..3b79bf5 100644 --- a/x2_master_export2translate.py +++ b/x2_master_export2translate.py @@ -6,12 +6,10 @@ import langid from openpyxl import load_workbook from openpyxl.styles import PatternFill, Alignment, Font from collections import defaultdict -from openai import OpenAI from openai_api_key import openai_api_key # Definir el logger a nivel de módulo logger = None -openai_client = OpenAI(api_key=openai_api_key()) def configurar_detector_idiomas(): @@ -153,6 +151,10 @@ def exportar_para_traduccion(config: TranslationConfig): progress_bar.finish() + # Configurar el modelo a usar + modelo_llm = fc.LLM_MODELS["OpenAI"] # o el que se prefiera + api_key = openai_api_key() # solo necesario para OpenAI y Grok + # Segunda fase: Procesar textos idénticos y calcular afinidades en lote if config.codigo_columna_maestra != config.codigo_idioma_seleccionado: # Asignar afinidad 1 a textos idénticos @@ -165,11 +167,13 @@ def exportar_para_traduccion(config: TranslationConfig): if texts_to_check: logger.info(f"Calculando afinidad para {len(texts_to_check)} textos diferentes") try: - affinities = fc.calculate_batch_affinities( + # Calcular afinidades + affinities = fc.calcular_afinidad_batch( texts_to_check, config.codigo_tipo_PLC, - openai_client, - logger + modelo_llm, + logger, + api_key ) # Aplicar resultados de afinidad diff --git a/x3_llm_auto_translate.py b/x3_llm_auto_translate.py index d714454..99e495a 100644 --- a/x3_llm_auto_translate.py +++ b/x3_llm_auto_translate.py @@ -15,13 +15,15 @@ from translation_config import TranslationConfig from openpyxl.styles import PatternFill, Alignment import sys -openai_client = OpenAI(api_key=openai_api_key()) GOOGLE_APPLICATION_CREDENTIALS = "translate-431108-020c17463fbb.json" batch_size = 20 # Definir el logger a nivel de módulo logger = None +# Crear el cliente OpenAI +openai_client = OpenAI(api_key=openai_api_key()) + def init_google_translate_client(): if os.path.exists(GOOGLE_APPLICATION_CREDENTIALS): @@ -232,6 +234,10 @@ def main(config: TranslationConfig): update_progress.finish() + # Configurar el modelo a usar + modelo_llm = fc.LLM_MODELS["OpenAI"] # o el que se prefiera + api_key = openai_api_key() # solo necesario para OpenAI y Grok + # Afinidades # Los textos ya vienen del proceso de traducción texts_to_check = {} @@ -240,11 +246,8 @@ def main(config: TranslationConfig): texts_to_check[key] = translated_text # Calcular afinidades usando LLM - affinities_dict = fc.calculate_batch_affinities( - texts_to_check, - config.codigo_tipo_PLC, - openai_client, - logger + affinities_dict = fc.calcular_afinidad_batch( + texts_to_check, config.codigo_tipo_PLC, modelo_llm, logger, api_key ) # Asignar resultados al DataFrame @@ -252,7 +255,7 @@ def main(config: TranslationConfig): key = str(row[source_col]) if key in affinities_dict: df.at[index, affinity_col] = affinities_dict[key] - + output_path = config.get_auto_translate_path() with pd.ExcelWriter(output_path, engine="openpyxl") as writer: diff --git a/x6_update_from_master.py b/x6_update_from_master.py index e376a7d..363b48d 100644 --- a/x6_update_from_master.py +++ b/x6_update_from_master.py @@ -79,10 +79,10 @@ def update_from_master(config: TranslationConfig, archivo_to_update): nuevo_nombre = f"{nombre}_import{extension}" with pd.ExcelWriter(nuevo_nombre, engine='openpyxl') as writer: - df_to_update.to_excel(writer, index=False) + df_to_update.to_excel(writer, sheet_name="User Texts", index=False) workbook = writer.book - worksheet = writer.sheets['Sheet1'] + worksheet = writer.sheets["User Texts"] # Format columns from openpyxl.utils import get_column_letter @@ -113,7 +113,7 @@ def update_from_master(config: TranslationConfig, archivo_to_update): df_changes.to_excel(writer, index=False) workbook = writer.book - worksheet = writer.sheets["Sheet1"] + worksheet = writer.sheets["User Texts"] light_blue = PatternFill(start_color="ADD8E6", end_color="ADD8E6", fill_type="solid")