Save current changes

This commit is contained in:
Dazed 2023-12-15 11:26:52 -06:00
parent baf6f9a8ca
commit 76f9a7e714
2 changed files with 53 additions and 42 deletions

View file

@ -48,7 +48,7 @@ if 'gpt-3.5' in MODEL:
elif 'gpt-4' in MODEL:
INPUTAPICOST = .01
OUTPUTAPICOST = .03
BATCHSIZE = 5
BATCHSIZE = 1
def handleAlice(filename, estimate):
global ESTIMATE
@ -157,10 +157,15 @@ def translateLines(linesList, pbar):
try:
while i < len(linesList):
# Check if Proper Message
match = re.findall(r'm\[[0-9]+\] = \"(.*)\"', linesList[i])
match = re.findall(r's\[[0-9]+\] = \"(.*)\"', linesList[i])
if len(match) > 0:
jaString = match[0]
# Skip Files
if '' in jaString:
i += 1
continue
### Translate
# Remove any textwrap
jaString = re.sub(r'\\n', ' ', jaString)
@ -181,16 +186,16 @@ def translateLines(linesList, pbar):
# Check if next line should be merged
if insertBool is True:
linesList[i] = re.sub(r'(m\[[0-9]+\]) = \"(.+)\"', rf'\1 = ""', linesList[i])
linesList[i] = re.sub(r'(s\[[0-9]+\]) = \"(.+)\"', rf'\1 = ""', linesList[i])
linesList[i] = linesList[i].replace(';', '')
start = i
while (len(linesList) > i+1 and re.search(r'm\[[0-9]+\] = \"\s+(.*)\"', linesList[i+1]) != None):
while (len(linesList) > i+1 and re.search(r's\[[0-9]+\] = \"\s+(.*)\"', linesList[i+1]) != None):
multiLine = True
i += 1
match = re.findall(r'm\[[0-9]+\] = \"\s+(.*)\"', linesList[i])
match = re.findall(r's\[[0-9]+\] = \"\s+(.*)\"', linesList[i])
currentGroup.append(match[0])
if insertBool is True:
linesList[i] = re.sub(r'(m\[[0-9]+\]) = \"\s+(.+)\"', rf'\1 = ""', linesList[i])
linesList[i] = re.sub(r'(s\[[0-9]+\]) = \"\s+(.+)\"', rf'\1 = ""', linesList[i])
linesList[i] = linesList[i].replace(';', '')
i += 1
@ -247,7 +252,7 @@ def translateLines(linesList, pbar):
textList = translatedText.split("\n")
for t in textList:
translatedText = translatedText.replace(';', '')
translatedText = re.sub(r'(m\[[0-9]+\]) = \"(.*)\"', rf'\1 = "{t}"', linesList[start])
translatedText = re.sub(r'(s\[[0-9]+\]) = \"(.*)\"', rf'\1 = "{t}"', linesList[start])
translatedText = translatedText.replace(';', '')
linesList[start] = translatedText
pbar.update(1)
@ -258,7 +263,7 @@ def translateLines(linesList, pbar):
else:
# Remove any textwrap
translatedText = translatedText.replace('\n', ' ')
translatedText = re.sub(r'(m\[[0-9]+\]) = \"(.*)\"', rf'\1 = "{translatedText}"', linesList[start])
translatedText = re.sub(r'(s\[[0-9]+\]) = \"(.*)\"', rf'\1 = "{translatedText}"', linesList[start])
translatedText = translatedText.replace(';', '')
linesList[start] = translatedText
pbar.update(1)
@ -402,21 +407,21 @@ def batchList(input_list, batch_size):
return [input_list[i:i + batch_size] for i in range(0, len(input_list), batch_size)]
def createContext(fullPromptFlag, subbedT):
characters = 'Game Characters (Format: Last Name, First Name - Gender):\
== Mamoru - Male\
神代 一騎 == Kamishiro, Ikki - Male\
神代 琴音 == Kamishiro, Kotone - Female\
神代 莉々子 == Kamishiro, Ririko - Female\
神代 紗夜 == Kamishiro, Saya - Female\
篠原漣 == Shinohara, Ren - Male\
藪井 == Yabui - Male\
舟木 == Funaki - Male\
貞二 == Jouji - Male\
兼田 響子 == Kaneda, Kyouko - Female\
兼田 真人 == Kaneda, Masato - Male\
小出 == Koide - Male\
進士 == Shinji - Male\
雪乃 == Yukino - Male'
characters = 'Game Characters:\
== Name: Mamoru - Male\
神代 一騎 == Last Name: Kamishiro, First Name: Ikki - Male\
神代 琴音 == Last Name: Kamishiro, First Name: Kotone - Female\
神代 莉々子 == Last Name: Kamishiro, First Name: Ririko - Female\
神代 紗夜 == Last Name: Kamishiro, First Name: Saya - Female\
篠原漣 == Last Name: Shinohara, First Name: Ren - Male\
藪井 == Name: Yabui - Male\
舟木 == Name: Funaki - Male\
貞二 == Name: Jouji - Male\
兼田 響子 == Last Name: Kaneda, First Name: Kyouko - Female\
兼田 真人 == Last Name: Kaneda, First Name: Masato - Male\
小出 == Name: Koide - Male\
進士 == Name: Shinji - Male\
雪乃 == Name: Yukino - Female'
system = PROMPT if fullPromptFlag else \
f'Output ONLY the {LANGUAGE} translation in the following format: `Translation: <{LANGUAGE.upper()}_TRANSLATION>`'
@ -441,8 +446,8 @@ def translateText(characters, system, user, history):
response = openai.chat.completions.create(
temperature=0.1,
top_p = 0.2,
frequency_penalty=0,
presence_penalty=0,
frequency_penalty=0.1,
presence_penalty=0.1,
model=MODEL,
messages=msg,
)
@ -453,6 +458,9 @@ def cleanTranslatedText(translatedText, varResponse):
f'{LANGUAGE} Translation: ': '',
'Translation: ': '',
'': '',
'': '~',
'': '-',
'': ''
# Add more replacements as needed
}
for target, replacement in placeholders.items():

View file

@ -1843,21 +1843,21 @@ def batchList(input_list, batch_size):
return [input_list[i:i + batch_size] for i in range(0, len(input_list), batch_size)]
def createContext(fullPromptFlag, subbedT):
characters = 'Game Characters (Format: Last Name, First Name - Gender):\
== Mamoru - Male\
神代 一騎 == Kamishiro, Ikki - Male\
神代 琴音 == Kamishiro, Kotone - Female\
神代 莉々子 == Kamishiro, Ririko - Female\
神代 紗夜 == Kamishiro, Saya - Female\
篠原漣 == Shinohara, Ren - Male\
藪井 == Yabui - Male\
舟木 == Funaki - Male\
貞二 == Jouji - Male\
兼田 響子 == Kaneda, Kyouko - Female\
兼田 真人 == Kaneda, Masato - Male\
小出 == Koide - Male\
進士 == Shinji - Male\
雪乃 == Yukino - Male'
characters = 'Game Characters:\
== Name: Mamoru - Male\
神代 一騎 == Last Name: Kamishiro, First Name: Ikki - Male\
神代 琴音 == Last Name: Kamishiro, First Name: Kotone - Female\
神代 莉々子 == Last Name: Kamishiro, First Name: Ririko - Female\
神代 紗夜 == Last Name: Kamishiro, First Name: Saya - Female\
篠原漣 == Last Name: Shinohara, First Name: Ren - Male\
藪井 == Name: Yabui - Male\
舟木 == Name: Funaki - Male\
貞二 == Name: Jouji - Male\
兼田 響子 == Last Name: Kaneda, First Name: Kyouko - Female\
兼田 真人 == Last Name: Kaneda, First Name: Masato - Male\
小出 == Name: Koide - Male\
進士 == Name: Shinji - Male\
雪乃 == Name: Yukino - Female'
system = PROMPT if fullPromptFlag else \
f'Output ONLY the {LANGUAGE} translation in the following format: `Translation: <{LANGUAGE.upper()}_TRANSLATION>`'
@ -1882,8 +1882,8 @@ def translateText(characters, system, user, history):
response = openai.chat.completions.create(
temperature=0.1,
top_p = 0.2,
frequency_penalty=FREQUENCY_PENALTY,
presence_penalty=FREQUENCY_PENALTY,
frequency_penalty=0.1,
presence_penalty=0.1,
model=MODEL,
messages=msg,
)
@ -1894,6 +1894,9 @@ def cleanTranslatedText(translatedText, varResponse):
f'{LANGUAGE} Translation: ': '',
'Translation: ': '',
'': '',
'': '~',
'': '-',
'': ''
# Add more replacements as needed
}
for target, replacement in placeholders.items():