@@ -21,7 +21,10 @@ def retry_translation(prompt, model, step_name):
21
21
## Step 1: Faithful to the Original Text
22
22
prompt1 = get_prompt_faithfulness (lines , shared_prompt )
23
23
faith_result = retry_translation (prompt1 , step4_2_translate_direct_model , 'faithfulness' )
24
-
24
+ # ! Replace '\n' with ' ' in faith_result[i]["Direct Translation"], sometimes gpt will add '\n'
25
+ for i in faith_result :
26
+ faith_result [i ]["Direct Translation" ] = faith_result [i ]["Direct Translation" ].replace ('\n ' , ' ' )
27
+
25
28
for i in faith_result :
26
29
print (f'📄 Original Subtitle: { faith_result [i ]["Original Subtitle" ]} ' )
27
30
print (f'📚 Direct Translation: { faith_result [i ]["Direct Translation" ]} ' )
@@ -34,11 +37,14 @@ def retry_translation(prompt, model, step_name):
34
37
print (f'📄 Original Subtitle: { express_result [i ]["Original Subtitle" ]} ' )
35
38
print (f'🧠 Free Translation: { express_result [i ]["Free Translation" ]} ' )
36
39
37
- translate_result = "\n " .join ([express_result [i ]["Free Translation" ].strip () for i in express_result ])
40
+ # ! Replace '\n' with ' ', sometimes gpt will add '\n' in the result and will cause the length of the original text and the translated text to be different
41
+ translate_result = "\n " .join ([express_result [i ]["Free Translation" ].replace ('\n ' , ' ' ).strip () for i in express_result ])
38
42
39
43
if len (lines .split ('\n ' )) != len (translate_result .split ('\n ' )):
40
- print (f'❌ Translation of block { index } failed' )
41
- print (f'✅ Translation of block { index } completed' )
44
+ print (f'❌ Translation of block { index } failed, Length Mismatch, Please check `output\gpt_log\t ranslate_expressiveness.json`, expected { len (lines .split ("\n " ))} lines, but got { len (translate_result .split ("\n " ))} lines.' )
45
+ raise ValueError (f'Original ···{ lines } ···,\n but got ···{ translate_result } ···' )
46
+ else :
47
+ print (f'✅ Translation of block { index } completed' )
42
48
43
49
return translate_result , lines
44
50
0 commit comments