From 7158934d87655fc55859ee22ee51dfe177a535ac Mon Sep 17 00:00:00 2001 From: DazedAnon Date: Sat, 7 Sep 2024 19:15:57 -0500 Subject: [PATCH] Update pricing and other stuff --- modules/csv.py | 3 ++- modules/rpgmakerace.py | 14 +++++++++----- modules/rpgmakerplugin.py | 3 ++- modules/wolf.py | 21 ++++++++++++++++----- modules/wolf2.py | 9 +++++---- 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/modules/csv.py b/modules/csv.py index 5a27e99..83cfdb2 100644 --- a/modules/csv.py +++ b/modules/csv.py @@ -572,6 +572,7 @@ def elongateCharacters(text): def extractTranslation(translatedTextList, is_list): try: + translatedTextList = re.sub(r'\\"+\"([^,\n}])', r'\\"\1', translatedTextList) line_dict = json.loads(translatedTextList) # If it's a batch (i.e., list), extract with tags; otherwise, return the single item. string_list = list(line_dict.values()) @@ -581,7 +582,7 @@ def extractTranslation(translatedTextList, is_list): return string_list[0] except Exception as e: - print(f'extractTranslation Error: {translatedTextList}') + PBAR.write(f'extractTranslation Error: {e} on String {translatedTextList}') return None diff --git a/modules/rpgmakerace.py b/modules/rpgmakerace.py index 8ba6cfb..64b53fd 100644 --- a/modules/rpgmakerace.py +++ b/modules/rpgmakerace.py @@ -49,8 +49,8 @@ if 'gpt-3.5' in MODEL: BATCHSIZE = 10 FREQUENCY_PENALTY = 0.2 elif 'gpt-4' in MODEL: - INPUTAPICOST = .005 - OUTPUTAPICOST = .015 + INPUTAPICOST = .0025 + OUTPUTAPICOST = .01 BATCHSIZE = 20 FREQUENCY_PENALTY = 0.1 @@ -820,7 +820,10 @@ def searchCodes(page, pbar, jobList, filename): and len(codeList[i+1]['p']) > 0 \ and len(codeList[i+1]['p'][0]) > 0: if codeList[i+1]['p'][0].strip()[0] in ['「', '"', '(', '(', '*', '[']: - speakerList = re.findall(r'.+', jaString) + # Make sure there aren't any codes. + speakerList = re.findall(r'[\\]\w\[.*?\](.*)', jaString) + if len(speakerList) == 0: + speakerList = re.findall(r'.*', jaString) if len(speakerList) != 0 and codeList[i+1]['c'] in [401, 405, -1]: # Get Speaker @@ -2143,7 +2146,7 @@ def createContext(fullPromptFlag, subbedT, format): characters = 'Game Characters:\n\ アーベント (Abent) - Male\n\ グイーネ (Guine) - Female\n\ -ゲオルイース (Geoluis) - Female\n\ +ゲオルイース (Geolouise) - Female\n\ サミダレクモ (Samidarekumo) - Female\n\ スティアラ (Stiara) - Female\n\ ブルウ (Blue) - Male\n\ @@ -2238,6 +2241,7 @@ def elongateCharacters(text): def extractTranslation(translatedTextList, is_list): try: + translatedTextList = re.sub(r'\\"+\"([^,\n}])', r'\\"\1', translatedTextList) line_dict = json.loads(translatedTextList) # If it's a batch (i.e., list), extract with tags; otherwise, return the single item. string_list = list(line_dict.values()) @@ -2247,7 +2251,7 @@ def extractTranslation(translatedTextList, is_list): return string_list[0] except Exception as e: - print(f'extractTranslation Error: {e}') + PBAR.write(f'extractTranslation Error: {e} on String {translatedTextList}') return None diff --git a/modules/rpgmakerplugin.py b/modules/rpgmakerplugin.py index c534798..ffc3775 100644 --- a/modules/rpgmakerplugin.py +++ b/modules/rpgmakerplugin.py @@ -493,6 +493,7 @@ def elongateCharacters(text): def extractTranslation(translatedTextList, is_list): try: + translatedTextList = re.sub(r'\\"+\"([^,\n}])', r'\\"\1', translatedTextList) line_dict = json.loads(translatedTextList) # If it's a batch (i.e., list), extract with tags; otherwise, return the single item. string_list = list(line_dict.values()) @@ -502,7 +503,7 @@ def extractTranslation(translatedTextList, is_list): return string_list[0] except Exception as e: - print(f'extractTranslation Error: {translatedTextList}') + PBAR.write(f'extractTranslation Error: {e} on String {translatedTextList}') return None diff --git a/modules/wolf.py b/modules/wolf.py index 6365437..1a35f28 100644 --- a/modules/wolf.py +++ b/modules/wolf.py @@ -483,7 +483,7 @@ def searchCodes(events, pbar, jobList, filename): codeList[i]['stringArgs'][0] = translatedText ### Event Code: 300 Common Events - if codeList[i]['code'] == 300 and CODE300 == True: + if codeList[i]['code'] == 300 and CODE300 == True and len(codeList[i]['stringArgs']) > 1: # Choices if codeList[i]['stringArgs'][0] == "選択肢/確認": # Grab String @@ -514,8 +514,10 @@ def searchCodes(events, pbar, jobList, filename): codeList[i]['stringArgs'][1] = translatedText # Dialogue - elif codeList[i]['stringArgs'][0] == "Hメッセージ": - imageRegex = r'(\\?r?\\?n?_\w+\r\n)|(@-?\d?)(\d?-?\d?[^\r]+?)(\r\n|$)|(_PDC)|(>\r\n)|(^[#])|(\r\n@$)|(/)|(_SS_)|(\r\n[@/]-?\d?\r\n)' + elif codeList[i]['stringArgs'][0] == "Hメッセージ" \ + or codeList[i]['stringArgs'][0] == 'Hしらべる' \ + or codeList[i]['stringArgs'][0] == '[移]サウンドノベル': + imageRegex = r'(\r?\n?_\w+\r?\n?)|(@-?\d?\r\n)|(@-?\d?[^\r])(\d?-?\d?[^\r]+?)(\r\n|$)|(_PDC)|(>\r\n)|(^[#])|(\r\n@$)|(/)|(_SS_)|(\r\n[@/]-?\d?\r\n)' fontSize = 24 # Grab String @@ -533,7 +535,7 @@ def searchCodes(events, pbar, jobList, filename): j = 0 translatedText = '' while j < len(cleanedList): - if ('@' in cleanedList[j] or '/' in cleanedList[j]) and j < len(cleanedList)-1 and re.search(r'(\r\n[@/]-?\d?\r\n)', cleanedList[j]) is None: + if ('@' in cleanedList[j] or '/' in cleanedList[j]) and j < len(cleanedList)-1 and re.search(r'([@/]-?\d?\r\n)', cleanedList[j]) is None: # Setup @ if j > 0 and '@' not in cleanedList[j-1] and '/' not in cleanedList[j-1] and '_' not in cleanedList[j-1]: cleanedList[j-1] = cleanedList[j-1] + cleanedList[j+1] @@ -556,6 +558,12 @@ def searchCodes(events, pbar, jobList, filename): # Pass 2 else: if all(x not in str for x in ['_', '@', '>', '/',]) and str != '\r\n': + # Decide Wrap + if codeList[i]['stringArgs'][0] == '[移]サウンドノベル': + width = 50 + else: + width = WIDTH + # Add Textwrap and Font list300[0] = textwrap.fill(list300[0], WIDTH) list300[0] = list300[0].replace('\n', f'\r\n\\f[{fontSize}]') @@ -569,6 +577,7 @@ def searchCodes(events, pbar, jobList, filename): if setData: # Formatting Fixes translatedText = translatedText.replace('*"', '* "') + translatedText = re.sub(r'[^\S\r\n]+', ' ', translatedText) codeList[i]['stringArgs'][1] = translatedText ### Event Code: 250 Common Events @@ -1545,6 +1554,7 @@ def createContext(fullPromptFlag, subbedT): ブライ (Buraimu) - Male\n\ ハッサン (Hassan) - Male\n\ アロマ (Aroma) - Female\n\ +ピッケ (Pikke) - Female\n\ ' system = PROMPT + VOCAB if fullPromptFlag else \ @@ -1634,6 +1644,7 @@ def elongateCharacters(text): def extractTranslation(translatedTextList, is_list): try: + translatedTextList = re.sub(r'\\"+\"([^,\n}])', r'\\"\1', translatedTextList) line_dict = json.loads(translatedTextList) # If it's a batch (i.e., list), extract with tags; otherwise, return the single item. string_list = list(line_dict.values()) @@ -1643,7 +1654,7 @@ def extractTranslation(translatedTextList, is_list): return string_list[0] except Exception as e: - print(f'extractTranslation Error: {translatedTextList}') + PBAR.write(f'extractTranslation Error: {e} on String {translatedTextList}') return None diff --git a/modules/wolf2.py b/modules/wolf2.py index 3324fc9..d4ea8bc 100644 --- a/modules/wolf2.py +++ b/modules/wolf2.py @@ -205,13 +205,13 @@ def translateWOLF(data, translatedList, pbar, filename): MISMATCH.append(filename) # Lines - if r'/' not in data[i] and data[i] != '\n': + if r'/' not in data[i] and '@' not in data[i] and data[i] != '\n': # Pass 1 if translatedList == []: # Grab Consecutive Strings currentGroup.append(data[i]) i += 1 - while i < len(data) and r'/' not in data[i] and data[i] != '\n': + while i < len(data) and r'/' not in data[i] and '@' not in data[i] and data[i] != '\n': currentGroup.append(data[i]) i += 1 @@ -234,7 +234,7 @@ def translateWOLF(data, translatedList, pbar, filename): # Pass 2 else: # Insert Strings - while i < len(data) and r'/' not in data[i] and data[i] != '\n': + while i < len(data) and r'/' not in data[i] and '@' not in data[i] and data[i] != '\n': data.pop(i) # Get Text @@ -449,6 +449,7 @@ def elongateCharacters(text): def extractTranslation(translatedTextList, is_list): try: + translatedTextList = re.sub(r'\\"+\"([^,\n}])', r'\\"\1', translatedTextList) line_dict = json.loads(translatedTextList) # If it's a batch (i.e., list), extract with tags; otherwise, return the single item. string_list = list(line_dict.values()) @@ -458,7 +459,7 @@ def extractTranslation(translatedTextList, is_list): return string_list[0] except Exception as e: - print(f'extractTranslation Error: {translatedTextList}') + PBAR.write(f'extractTranslation Error: {e} on String {translatedTextList}') return None