Extend ruff format line length
This commit is contained in:
parent
cc65eac115
commit
a20788ca11
25 changed files with 252 additions and 831 deletions
|
|
@ -117,19 +117,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] == None:
|
if translatedData[2] == None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
|
|
@ -138,16 +133,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def parseText(data, filename):
|
def parseText(data, filename):
|
||||||
|
|
@ -201,10 +187,7 @@ def translateLines(linesList, pbar):
|
||||||
speakerMatch = re.findall(r"s\[[0-9]+\] = \"([^/]+)\"", linesList[i - 1])
|
speakerMatch = re.findall(r"s\[[0-9]+\] = \"([^/]+)\"", linesList[i - 1])
|
||||||
if len(speakerMatch) > 0:
|
if len(speakerMatch) > 0:
|
||||||
# If there isn't any Japanese in the text just skip
|
# If there isn't any Japanese in the text just skip
|
||||||
if (
|
if re.search(r"[一-龠]+|[ぁ-ゔ]+|[ァ-ヴー]+", jaString) and "_" not in speakerMatch[0]:
|
||||||
re.search(r"[一-龠]+|[ぁ-ゔ]+|[ァ-ヴー]+", jaString)
|
|
||||||
and "_" not in speakerMatch[0]
|
|
||||||
):
|
|
||||||
speaker = speakerMatch[0]
|
speaker = speakerMatch[0]
|
||||||
else:
|
else:
|
||||||
speaker = ""
|
speaker = ""
|
||||||
|
|
@ -219,18 +202,13 @@ def translateLines(linesList, pbar):
|
||||||
linesList[i] = re.sub(r"(s\[[0-9]+\]) = \"(.+)\"", r'\1 = ""', linesList[i])
|
linesList[i] = re.sub(r"(s\[[0-9]+\]) = \"(.+)\"", r'\1 = ""', linesList[i])
|
||||||
linesList[i] = linesList[i].replace(";", "")
|
linesList[i] = linesList[i].replace(";", "")
|
||||||
start = i
|
start = i
|
||||||
while (
|
while len(linesList) > i + 1 and re.search(r"s\[[0-9]+\] = \"\s+(.*)\"", linesList[i + 1]) != None:
|
||||||
len(linesList) > i + 1
|
|
||||||
and re.search(r"s\[[0-9]+\] = \"\s+(.*)\"", linesList[i + 1]) != None
|
|
||||||
):
|
|
||||||
multiLine = True
|
multiLine = True
|
||||||
i += 1
|
i += 1
|
||||||
match = re.findall(r"s\[[0-9]+\] = \"\s+(.*)\"", linesList[i])
|
match = re.findall(r"s\[[0-9]+\] = \"\s+(.*)\"", linesList[i])
|
||||||
currentGroup.append(match[0])
|
currentGroup.append(match[0])
|
||||||
if insertBool is True:
|
if insertBool is True:
|
||||||
linesList[i] = re.sub(
|
linesList[i] = re.sub(r"(s\[[0-9]+\]) = \"\s+(.+)\"", r'\1 = ""', linesList[i])
|
||||||
r"(s\[[0-9]+\]) = \"\s+(.+)\"", r'\1 = ""', linesList[i]
|
|
||||||
)
|
|
||||||
linesList[i] = linesList[i].replace(";", "")
|
linesList[i] = linesList[i].replace(";", "")
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
|
@ -527,11 +505,7 @@ def extractTranslation(translatedTextList, is_list):
|
||||||
pattern = r"<Line(\d+)>[\\]*`?(.*?)[\\]*?`?</?Line\d+>"
|
pattern = r"<Line(\d+)>[\\]*`?(.*?)[\\]*?`?</?Line\d+>"
|
||||||
# If it's a batch (i.e., list), extract with tags; otherwise, return the single item.
|
# If it's a batch (i.e., list), extract with tags; otherwise, return the single item.
|
||||||
if is_list:
|
if is_list:
|
||||||
return [
|
return [re.findall(pattern, line)[0][1] for line in translatedTextList if re.search(pattern, line)]
|
||||||
re.findall(pattern, line)[0][1]
|
|
||||||
for line in translatedTextList
|
|
||||||
if re.search(pattern, line)
|
|
||||||
]
|
|
||||||
else:
|
else:
|
||||||
matchList = re.findall(pattern, translatedTextList)
|
matchList = re.findall(pattern, translatedTextList)
|
||||||
return matchList[0][1] if matchList else translatedTextList
|
return matchList[0][1] if matchList else translatedTextList
|
||||||
|
|
|
||||||
|
|
@ -124,19 +124,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] == None:
|
if translatedData[2] == None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
|
|
@ -145,16 +140,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def parseJSON(data, filename):
|
def parseJSON(data, filename):
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,7 @@ INPUTAPICOST = 0.002 # Depends on the model https://openai.com/pricing
|
||||||
OUTPUTAPICOST = 0.002
|
OUTPUTAPICOST = 0.002
|
||||||
PROMPT = Path("prompt.txt").read_text(encoding="utf-8")
|
PROMPT = Path("prompt.txt").read_text(encoding="utf-8")
|
||||||
VOCAB = Path("vocab.txt").read_text(encoding="utf-8")
|
VOCAB = Path("vocab.txt").read_text(encoding="utf-8")
|
||||||
THREADS = int(
|
THREADS = int(os.getenv("threads")) # Controls how many threads are working on a single file (May have to drop this)
|
||||||
os.getenv("threads")
|
|
||||||
) # Controls how many threads are working on a single file (May have to drop this)
|
|
||||||
LOCK = threading.Lock()
|
LOCK = threading.Lock()
|
||||||
WIDTH = int(os.getenv("width"))
|
WIDTH = int(os.getenv("width"))
|
||||||
LISTWIDTH = int(os.getenv("listWidth"))
|
LISTWIDTH = int(os.getenv("listWidth"))
|
||||||
|
|
@ -98,19 +96,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] is None:
|
if translatedData[2] is None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
|
|
@ -118,16 +111,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
raise translatedData[2]
|
raise translatedData[2]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def parseText(data, filename):
|
def parseText(data, filename):
|
||||||
|
|
@ -356,13 +340,7 @@ def translateGPT(t, history, fullPromptFlag):
|
||||||
system = PROMPT
|
system = PROMPT
|
||||||
user = "Line to Translate = " + subbedT
|
user = "Line to Translate = " + subbedT
|
||||||
else:
|
else:
|
||||||
system = (
|
system = "Output ONLY the " + LANGUAGE + " translation in the following format: `Translation: <" + LANGUAGE.upper() + "_TRANSLATION>`"
|
||||||
"Output ONLY the "
|
|
||||||
+ LANGUAGE
|
|
||||||
+ " translation in the following format: `Translation: <"
|
|
||||||
+ LANGUAGE.upper()
|
|
||||||
+ "_TRANSLATION>`"
|
|
||||||
)
|
|
||||||
user = "Line to Translate = " + subbedT
|
user = "Line to Translate = " + subbedT
|
||||||
|
|
||||||
# Create Message List
|
# Create Message List
|
||||||
|
|
@ -412,10 +390,7 @@ def translateGPT(t, history, fullPromptFlag):
|
||||||
translatedText = translatedText.replace("!", "!")
|
translatedText = translatedText.replace("!", "!")
|
||||||
|
|
||||||
# Return Translation
|
# Return Translation
|
||||||
if (
|
if len(translatedText) > 15 * len(t) or "I'm sorry, but I'm unable to assist with that translation" in translatedText:
|
||||||
len(translatedText) > 15 * len(t)
|
|
||||||
or "I'm sorry, but I'm unable to assist with that translation" in translatedText
|
|
||||||
):
|
|
||||||
raise Exception
|
raise Exception
|
||||||
else:
|
else:
|
||||||
return [translatedText, totalTokens]
|
return [translatedText, totalTokens]
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ BAR_FORMAT = "{l_bar}{bar:10}{r_bar}{bar:-10b}"
|
||||||
POSITION = 0
|
POSITION = 0
|
||||||
LEAVE = False
|
LEAVE = False
|
||||||
PBAR = None
|
PBAR = None
|
||||||
|
ENCODING = "cp932"
|
||||||
|
|
||||||
|
|
||||||
def handleCSV(filename, estimate):
|
def handleCSV(filename, estimate):
|
||||||
|
|
@ -70,7 +71,7 @@ def handleCSV(filename, estimate):
|
||||||
ESTIMATE = estimate
|
ESTIMATE = estimate
|
||||||
|
|
||||||
if not ESTIMATE:
|
if not ESTIMATE:
|
||||||
with open("translated/" + filename, "w+t", newline="", encoding="utf-8-sig") as writeFile:
|
with open("translated/" + filename, "w+t", newline="", encoding=ENCODING) as writeFile:
|
||||||
# Translate
|
# Translate
|
||||||
start = time.time()
|
start = time.time()
|
||||||
translatedData = openFiles(filename, writeFile)
|
translatedData = openFiles(filename, writeFile)
|
||||||
|
|
@ -104,14 +105,14 @@ def handleCSV(filename, estimate):
|
||||||
|
|
||||||
|
|
||||||
def openFiles(filename, writeFile):
|
def openFiles(filename, writeFile):
|
||||||
with open("files/" + filename, "r", encoding="utf-8-sig") as readFile, writeFile:
|
with open("files/" + filename, "r", encoding="cp932") as readFile, writeFile:
|
||||||
translatedData = parseCSV(readFile, writeFile, filename)
|
translatedData = parseCSV(readFile, writeFile, filename)
|
||||||
|
|
||||||
return translatedData
|
return translatedData
|
||||||
|
|
||||||
|
|
||||||
def openFilesEstimate(filename):
|
def openFilesEstimate(filename):
|
||||||
with open("files/" + filename, "r", encoding="utf-8-sig") as readFile:
|
with open("files/" + filename, "r", encoding="cp932") as readFile:
|
||||||
translatedData = parseCSV(readFile, "", filename)
|
translatedData = parseCSV(readFile, "", filename)
|
||||||
|
|
||||||
return translatedData
|
return translatedData
|
||||||
|
|
@ -123,19 +124,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] is None:
|
if translatedData[2] is None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
try:
|
try:
|
||||||
|
|
@ -143,16 +139,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def parseCSV(readFile, writeFile, filename):
|
def parseCSV(readFile, writeFile, filename):
|
||||||
|
|
@ -161,8 +148,8 @@ def parseCSV(readFile, writeFile, filename):
|
||||||
global LOCK
|
global LOCK
|
||||||
|
|
||||||
format = ""
|
format = ""
|
||||||
while format not in ["1", "2", "3"]:
|
while format not in ["1", "2", "3", "4"]:
|
||||||
format = input("\n\nSelect the CSV Format:\n\n1. Translator++\n2. Single\n3. Multiple\n")
|
format = input("\n\nSelect the CSV Format:\n\n1. Translator++\n2. Single\n3. Multiple\n4. Speaker&Text\n")
|
||||||
match format:
|
match format:
|
||||||
case "1":
|
case "1":
|
||||||
format = "1"
|
format = "1"
|
||||||
|
|
@ -170,6 +157,8 @@ def parseCSV(readFile, writeFile, filename):
|
||||||
format = "2"
|
format = "2"
|
||||||
case "3":
|
case "3":
|
||||||
format = "3"
|
format = "3"
|
||||||
|
case "4":
|
||||||
|
format = "4"
|
||||||
|
|
||||||
# Get total for progress bar
|
# Get total for progress bar
|
||||||
totalLines = len(readFile.readlines())
|
totalLines = len(readFile.readlines())
|
||||||
|
|
@ -275,7 +264,7 @@ def translateCSV(data, pbar, writer, filename, translatedList, format):
|
||||||
# Iterate
|
# Iterate
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
# All Format
|
# In Place Format
|
||||||
case "3":
|
case "3":
|
||||||
# Set columns to translate. Leave empty to translate all.
|
# Set columns to translate. Leave empty to translate all.
|
||||||
targetColumns = []
|
targetColumns = []
|
||||||
|
|
@ -315,6 +304,52 @@ def translateCSV(data, pbar, writer, filename, translatedList, format):
|
||||||
# Iterate
|
# Iterate
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
# Speaker & Text Format
|
||||||
|
case "4":
|
||||||
|
# Set columns to translate. Leave empty to translate all.
|
||||||
|
speakerColumn = 8
|
||||||
|
textColumn = 20
|
||||||
|
speaker = ""
|
||||||
|
|
||||||
|
if len(data[i]) > textColumn:
|
||||||
|
# Speaker
|
||||||
|
if data[i][speakerColumn]:
|
||||||
|
speakerResponse = getSpeaker(data[i][speakerColumn])
|
||||||
|
totalTokens[0] += speakerResponse[1][0]
|
||||||
|
totalTokens[1] += speakerResponse[1][1]
|
||||||
|
speaker = speakerResponse[0]
|
||||||
|
data[i][speakerColumn] = speaker
|
||||||
|
|
||||||
|
# Check if Translated
|
||||||
|
jaString = data[i][textColumn]
|
||||||
|
|
||||||
|
# Remove Textwrap
|
||||||
|
jaString = jaString.replace("\\n", " ")
|
||||||
|
|
||||||
|
# Pass 1
|
||||||
|
if not translatedList:
|
||||||
|
stringList.append(jaString)
|
||||||
|
|
||||||
|
# Pass 2
|
||||||
|
else:
|
||||||
|
# Grab and Pop
|
||||||
|
translatedText = translatedList[0]
|
||||||
|
translatedList.pop(0)
|
||||||
|
|
||||||
|
# Remove speaker
|
||||||
|
if speaker:
|
||||||
|
translatedText = re.sub(r"^\[?(.+?)\]?\s?[|:]\s?", "", translatedText)
|
||||||
|
|
||||||
|
# Add Wordwrap
|
||||||
|
translatedText = textwrap.fill(translatedText, WIDTH)
|
||||||
|
translatedText = translatedText.replace("\n", "\\n")
|
||||||
|
|
||||||
|
# Set Data
|
||||||
|
data[i][textColumn] = translatedText
|
||||||
|
|
||||||
|
# Iterate
|
||||||
|
i += 1
|
||||||
|
|
||||||
# EOF
|
# EOF
|
||||||
if len(stringList) > 0:
|
if len(stringList) > 0:
|
||||||
# Set Progress
|
# Set Progress
|
||||||
|
|
@ -369,6 +404,10 @@ def getSpeaker(speaker):
|
||||||
if speaker == NAMESLIST[i][0]:
|
if speaker == NAMESLIST[i][0]:
|
||||||
return [NAMESLIST[i][1], [0, 0]]
|
return [NAMESLIST[i][1], [0, 0]]
|
||||||
|
|
||||||
|
# If there isn't any Japanese in the text just skip
|
||||||
|
if not re.search(r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", speaker):
|
||||||
|
return [speaker, [0, 0]]
|
||||||
|
|
||||||
# Translate and Store Speaker
|
# Translate and Store Speaker
|
||||||
response = translateGPT(
|
response = translateGPT(
|
||||||
f"{speaker}",
|
f"{speaker}",
|
||||||
|
|
@ -600,9 +639,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
translatedText = cleanTranslatedText(translatedText, varResponse)
|
translatedText = cleanTranslatedText(translatedText, varResponse)
|
||||||
if isinstance(tItem, list):
|
if isinstance(tItem, list):
|
||||||
extractedTranslations = extractTranslation(translatedText, True)
|
extractedTranslations = extractTranslation(translatedText, True)
|
||||||
if extractedTranslations == None or len(tItem) != len(
|
if extractedTranslations == None or len(tItem) != len(extractedTranslations):
|
||||||
extractedTranslations
|
|
||||||
):
|
|
||||||
mismatch = True # Just here for breakpoint
|
mismatch = True # Just here for breakpoint
|
||||||
logFile.write(f"Input:\n{subbedT}\n")
|
logFile.write(f"Input:\n{subbedT}\n")
|
||||||
logFile.write(f"Output:\n{translatedText}\n")
|
logFile.write(f"Output:\n{translatedText}\n")
|
||||||
|
|
@ -610,9 +647,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
# Set if no mismatch
|
# Set if no mismatch
|
||||||
if mismatch == False:
|
if mismatch == False:
|
||||||
tList[index] = extractedTranslations
|
tList[index] = extractedTranslations
|
||||||
history = extractedTranslations[
|
history = extractedTranslations[-MAXHISTORY:] # Update history if we have a list
|
||||||
-MAXHISTORY:
|
|
||||||
] # Update history if we have a list
|
|
||||||
else:
|
else:
|
||||||
history = text[-MAXHISTORY:]
|
history = text[-MAXHISTORY:]
|
||||||
mismatch = False
|
mismatch = False
|
||||||
|
|
|
||||||
|
|
@ -110,19 +110,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] == None:
|
if translatedData[2] == None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
|
|
@ -131,16 +126,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def openFiles(filename):
|
def openFiles(filename):
|
||||||
|
|
@ -208,9 +194,7 @@ def translateEushully(data, pbar, filename, translatedList):
|
||||||
originalString = match.group(2)
|
originalString = match.group(2)
|
||||||
jaString = match.group(2)
|
jaString = match.group(2)
|
||||||
currentGroup = [jaString]
|
currentGroup = [jaString]
|
||||||
while "end-text-line" in data[i + 1] and any(
|
while "end-text-line" in data[i + 1] and any(x in data[i + 2] for x in ["show-text"]):
|
||||||
x in data[i + 2] for x in ["show-text"]
|
|
||||||
):
|
|
||||||
match = re.search(regex, data[i + 2])
|
match = re.search(regex, data[i + 2])
|
||||||
if match != None:
|
if match != None:
|
||||||
currentGroup.append(match.group(2))
|
currentGroup.append(match.group(2))
|
||||||
|
|
|
||||||
|
|
@ -137,19 +137,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] is None:
|
if translatedData[2] is None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
try:
|
try:
|
||||||
|
|
@ -157,16 +152,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def getFontSize(text, image_width, image_height, font_path):
|
def getFontSize(text, image_width, image_height, font_path):
|
||||||
|
|
@ -262,9 +248,7 @@ def processImagesDir(directory_path, imageList):
|
||||||
line = line.replace(":", ":")
|
line = line.replace(":", ":")
|
||||||
line = line.replace("/", "/")
|
line = line.replace("/", "/")
|
||||||
line = line.replace("?", "?")
|
line = line.replace("?", "?")
|
||||||
imageList[0].append(
|
imageList[0].append(line) # Using strip() to remove any extra newlines or spaces
|
||||||
line
|
|
||||||
) # Using strip() to remove any extra newlines or spaces
|
|
||||||
imageList[1].append([104, 15])
|
imageList[1].append([104, 15])
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print(f"The file at {file_path} was not found.")
|
print(f"The file at {file_path} was not found.")
|
||||||
|
|
|
||||||
|
|
@ -109,19 +109,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] == None:
|
if translatedData[2] == None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
|
|
@ -130,16 +125,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def openFiles(filename):
|
def openFiles(filename):
|
||||||
|
|
@ -195,10 +181,7 @@ def translateIris(data, pbar, filename, translatedList):
|
||||||
if "#MSG," in data[i] or "#MSG\n" in data[i] or voice == True:
|
if "#MSG," in data[i] or "#MSG\n" in data[i] or voice == True:
|
||||||
i += 1
|
i += 1
|
||||||
# Speaker
|
# Speaker
|
||||||
if (
|
if re.search(r'^ ?([^#\/."、。*!!()\(\)\[\] \n]+)\n', data[i]) and len(data[i]) < 30:
|
||||||
re.search(r'^ ?([^#\/."、。*!!()\(\)\[\] \n]+)\n', data[i])
|
|
||||||
and len(data[i]) < 30
|
|
||||||
):
|
|
||||||
match = re.search(r"(.*)", data[i])
|
match = re.search(r"(.*)", data[i])
|
||||||
if match != None:
|
if match != None:
|
||||||
speaker = match.group(1)
|
speaker = match.group(1)
|
||||||
|
|
|
||||||
|
|
@ -109,19 +109,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] == None:
|
if translatedData[2] == None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
|
|
@ -130,16 +125,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def openFiles(filename):
|
def openFiles(filename):
|
||||||
|
|
@ -187,9 +173,7 @@ def translateJS(data, pbar):
|
||||||
modifiedStringList[j] = modifiedStringList[j].replace(r"\\\\\\\\n", r" ")
|
modifiedStringList[j] = modifiedStringList[j].replace(r"\\\\\\\\n", r" ")
|
||||||
|
|
||||||
# Translate
|
# Translate
|
||||||
response = translateGPT(
|
response = translateGPT(modifiedStringList, f"Reply with the {LANGUAGE} translation", True, pbar)
|
||||||
modifiedStringList, f"Reply with the {LANGUAGE} translation", True, pbar
|
|
||||||
)
|
|
||||||
translatedList = response[0]
|
translatedList = response[0]
|
||||||
tokens[0] = response[1][0]
|
tokens[0] = response[1][0]
|
||||||
tokens[0] = response[1][1]
|
tokens[0] = response[1][1]
|
||||||
|
|
|
||||||
|
|
@ -116,19 +116,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] == None:
|
if translatedData[2] == None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
|
|
@ -137,16 +132,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def parseJSON(data, filename):
|
def parseJSON(data, filename):
|
||||||
|
|
@ -541,9 +527,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
translatedText = cleanTranslatedText(translatedText, varResponse)
|
translatedText = cleanTranslatedText(translatedText, varResponse)
|
||||||
if isinstance(tItem, list):
|
if isinstance(tItem, list):
|
||||||
extractedTranslations = extractTranslation(translatedText, True)
|
extractedTranslations = extractTranslation(translatedText, True)
|
||||||
if extractedTranslations == None or len(tItem) != len(
|
if extractedTranslations == None or len(tItem) != len(extractedTranslations):
|
||||||
extractedTranslations
|
|
||||||
):
|
|
||||||
mismatch = True # Just here for breakpoint
|
mismatch = True # Just here for breakpoint
|
||||||
logFile.write(f"Input:\n{subbedT}\n")
|
logFile.write(f"Input:\n{subbedT}\n")
|
||||||
logFile.write(f"Output:\n{translatedText}\n")
|
logFile.write(f"Output:\n{translatedText}\n")
|
||||||
|
|
@ -551,9 +535,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
# Set if no mismatch
|
# Set if no mismatch
|
||||||
if mismatch == False:
|
if mismatch == False:
|
||||||
tList[index] = extractedTranslations
|
tList[index] = extractedTranslations
|
||||||
history = extractedTranslations[
|
history = extractedTranslations[-MAXHISTORY:] # Update history if we have a list
|
||||||
-MAXHISTORY:
|
|
||||||
] # Update history if we have a list
|
|
||||||
else:
|
else:
|
||||||
history = text[-MAXHISTORY:]
|
history = text[-MAXHISTORY:]
|
||||||
mismatch = False
|
mismatch = False
|
||||||
|
|
|
||||||
|
|
@ -85,9 +85,7 @@ def handleKansen(filename, estimate):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
with open(
|
with open("translated/" + filename, "w", encoding="shift_jis", errors="ignore") as outFile:
|
||||||
"translated/" + filename, "w", encoding="shift_jis", errors="ignore"
|
|
||||||
) as outFile:
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
translatedData = openFiles(filename)
|
translatedData = openFiles(filename)
|
||||||
|
|
||||||
|
|
@ -111,19 +109,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] == None:
|
if translatedData[2] == None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
|
|
@ -132,16 +125,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def openFiles(filename):
|
def openFiles(filename):
|
||||||
|
|
@ -624,11 +608,7 @@ def extractTranslation(translatedTextList, is_list):
|
||||||
pattern = r"`?<Line(\d+)>([\\]*.*?[\\]*?)<\/?Line\d+>`?"
|
pattern = r"`?<Line(\d+)>([\\]*.*?[\\]*?)<\/?Line\d+>`?"
|
||||||
# If it's a batch (i.e., list), extract with tags; otherwise, return the single item.
|
# If it's a batch (i.e., list), extract with tags; otherwise, return the single item.
|
||||||
if is_list:
|
if is_list:
|
||||||
return [
|
return [re.findall(pattern, line)[0][1] for line in translatedTextList if re.search(pattern, line)]
|
||||||
re.findall(pattern, line)[0][1]
|
|
||||||
for line in translatedTextList
|
|
||||||
if re.search(pattern, line)
|
|
||||||
]
|
|
||||||
else:
|
else:
|
||||||
matchList = re.findall(pattern, translatedTextList)
|
matchList = re.findall(pattern, translatedTextList)
|
||||||
return matchList[0][1] if matchList else translatedTextList
|
return matchList[0][1] if matchList else translatedTextList
|
||||||
|
|
|
||||||
|
|
@ -123,19 +123,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] == None:
|
if translatedData[2] == None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
|
|
@ -144,16 +139,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def openFiles(filename):
|
def openFiles(filename):
|
||||||
|
|
@ -584,9 +570,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
translatedText = cleanTranslatedText(translatedText, varResponse)
|
translatedText = cleanTranslatedText(translatedText, varResponse)
|
||||||
if isinstance(tItem, list):
|
if isinstance(tItem, list):
|
||||||
extractedTranslations = extractTranslation(translatedText, True)
|
extractedTranslations = extractTranslation(translatedText, True)
|
||||||
if extractedTranslations == None or len(tItem) != len(
|
if extractedTranslations == None or len(tItem) != len(extractedTranslations):
|
||||||
extractedTranslations
|
|
||||||
):
|
|
||||||
mismatch = True # Just here for breakpoint
|
mismatch = True # Just here for breakpoint
|
||||||
logFile.write(f"Input:\n{subbedT}\n")
|
logFile.write(f"Input:\n{subbedT}\n")
|
||||||
logFile.write(f"Output:\n{translatedText}\n")
|
logFile.write(f"Output:\n{translatedText}\n")
|
||||||
|
|
@ -594,9 +578,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
# Set if no mismatch
|
# Set if no mismatch
|
||||||
if mismatch == False:
|
if mismatch == False:
|
||||||
tList[index] = extractedTranslations
|
tList[index] = extractedTranslations
|
||||||
history = extractedTranslations[
|
history = extractedTranslations[-MAXHISTORY:] # Update history if we have a list
|
||||||
-MAXHISTORY:
|
|
||||||
] # Update history if we have a list
|
|
||||||
else:
|
else:
|
||||||
history = text[-MAXHISTORY:]
|
history = text[-MAXHISTORY:]
|
||||||
mismatch = False
|
mismatch = False
|
||||||
|
|
|
||||||
|
|
@ -119,19 +119,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] == None:
|
if translatedData[2] == None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
|
|
@ -140,16 +135,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def parseJSON(data, filename):
|
def parseJSON(data, filename):
|
||||||
|
|
|
||||||
|
|
@ -119,19 +119,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] == None:
|
if translatedData[2] == None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
|
|
@ -140,16 +135,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def openFiles(filename):
|
def openFiles(filename):
|
||||||
|
|
@ -600,9 +586,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
translatedText = cleanTranslatedText(translatedText, varResponse)
|
translatedText = cleanTranslatedText(translatedText, varResponse)
|
||||||
if isinstance(tItem, list):
|
if isinstance(tItem, list):
|
||||||
extractedTranslations = extractTranslation(translatedText, True)
|
extractedTranslations = extractTranslation(translatedText, True)
|
||||||
if extractedTranslations == None or len(tItem) != len(
|
if extractedTranslations == None or len(tItem) != len(extractedTranslations):
|
||||||
extractedTranslations
|
|
||||||
):
|
|
||||||
mismatch = True # Just here for breakpoint
|
mismatch = True # Just here for breakpoint
|
||||||
logFile.write(f"Input:\n{subbedT}\n")
|
logFile.write(f"Input:\n{subbedT}\n")
|
||||||
logFile.write(f"Output:\n{translatedText}\n")
|
logFile.write(f"Output:\n{translatedText}\n")
|
||||||
|
|
@ -610,9 +594,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
# Set if no mismatch
|
# Set if no mismatch
|
||||||
if mismatch == False:
|
if mismatch == False:
|
||||||
tList[index] = extractedTranslations
|
tList[index] = extractedTranslations
|
||||||
history = extractedTranslations[
|
history = extractedTranslations[-MAXHISTORY:] # Update history if we have a list
|
||||||
-MAXHISTORY:
|
|
||||||
] # Update history if we have a list
|
|
||||||
else:
|
else:
|
||||||
history = text[-MAXHISTORY:]
|
history = text[-MAXHISTORY:]
|
||||||
mismatch = False
|
mismatch = False
|
||||||
|
|
|
||||||
|
|
@ -103,19 +103,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] == None:
|
if translatedData[2] == None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
|
|
@ -124,16 +119,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def openFiles(filename):
|
def openFiles(filename):
|
||||||
|
|
@ -274,9 +260,7 @@ def translateRegex(data, translatedList):
|
||||||
|
|
||||||
# Remove Repeating Characters
|
# Remove Repeating Characters
|
||||||
pattern = re.compile(r"(.)\s*\1(?:\s*\1){" + str(20 - 1) + r",}")
|
pattern = re.compile(r"(.)\s*\1(?:\s*\1){" + str(20 - 1) + r",}")
|
||||||
translatedText = pattern.sub(
|
translatedText = pattern.sub(lambda match: match.group(0).replace(" ", "")[:20], translatedText)
|
||||||
lambda match: match.group(0).replace(" ", "")[:20], translatedText
|
|
||||||
)
|
|
||||||
|
|
||||||
# Textwrap
|
# Textwrap
|
||||||
translatedText = textwrap.fill(translatedText, width=WIDTH)
|
translatedText = textwrap.fill(translatedText, width=WIDTH)
|
||||||
|
|
@ -338,9 +322,7 @@ def translateRegex(data, translatedList):
|
||||||
|
|
||||||
# Choice List
|
# Choice List
|
||||||
if choiceList:
|
if choiceList:
|
||||||
response = translateGPT(
|
response = translateGPT(choiceList, "Reply with the English TL of the Dialogue Choice", True)
|
||||||
choiceList, "Reply with the English TL of the Dialogue Choice", True
|
|
||||||
)
|
|
||||||
tokens[0] += response[1][0]
|
tokens[0] += response[1][0]
|
||||||
tokens[1] += response[1][1]
|
tokens[1] += response[1][1]
|
||||||
choiceListTL = response[0]
|
choiceListTL = response[0]
|
||||||
|
|
@ -591,9 +573,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
extractedTranslations = extractTranslation(translatedText, True)
|
extractedTranslations = extractTranslation(translatedText, True)
|
||||||
if extractedTranslations == None or len(tItem) != len(extractedTranslations):
|
if extractedTranslations == None or len(tItem) != len(extractedTranslations):
|
||||||
# Mismatch. Try Again
|
# Mismatch. Try Again
|
||||||
response = translateText(
|
response = translateText(system, user, history, 0.05, format, "gpt-4-turbo-2024-04-09")
|
||||||
system, user, history, 0.05, format, "gpt-4-turbo-2024-04-09"
|
|
||||||
)
|
|
||||||
translatedText = response.choices[0].message.content
|
translatedText = response.choices[0].message.content
|
||||||
totalTokens[0] += response.usage.prompt_tokens
|
totalTokens[0] += response.usage.prompt_tokens
|
||||||
totalTokens[1] += response.usage.completion_tokens
|
totalTokens[1] += response.usage.completion_tokens
|
||||||
|
|
@ -602,9 +582,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
translatedText = cleanTranslatedText(translatedText, varResponse)
|
translatedText = cleanTranslatedText(translatedText, varResponse)
|
||||||
if isinstance(tItem, list):
|
if isinstance(tItem, list):
|
||||||
extractedTranslations = extractTranslation(translatedText, True)
|
extractedTranslations = extractTranslation(translatedText, True)
|
||||||
if extractedTranslations == None or len(tItem) != len(
|
if extractedTranslations == None or len(tItem) != len(extractedTranslations):
|
||||||
extractedTranslations
|
|
||||||
):
|
|
||||||
mismatch = True # Just here for breakpoint
|
mismatch = True # Just here for breakpoint
|
||||||
logFile.write(f"Input:\n{subbedT}\n")
|
logFile.write(f"Input:\n{subbedT}\n")
|
||||||
logFile.write(f"Output:\n{translatedText}\n")
|
logFile.write(f"Output:\n{translatedText}\n")
|
||||||
|
|
@ -612,9 +590,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
# Set if no mismatch
|
# Set if no mismatch
|
||||||
if mismatch == False:
|
if mismatch == False:
|
||||||
tList[index] = extractedTranslations
|
tList[index] = extractedTranslations
|
||||||
history = extractedTranslations[
|
history = extractedTranslations[-MAXHISTORY:] # Update history if we have a list
|
||||||
-MAXHISTORY:
|
|
||||||
] # Update history if we have a list
|
|
||||||
else:
|
else:
|
||||||
history = text[-MAXHISTORY:]
|
history = text[-MAXHISTORY:]
|
||||||
mismatch = False
|
mismatch = False
|
||||||
|
|
|
||||||
|
|
@ -114,19 +114,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] == None:
|
if translatedData[2] == None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
|
|
@ -135,16 +130,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def openFiles(filename):
|
def openFiles(filename):
|
||||||
|
|
@ -524,9 +510,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
translatedText = cleanTranslatedText(translatedText, varResponse)
|
translatedText = cleanTranslatedText(translatedText, varResponse)
|
||||||
if isinstance(tItem, list):
|
if isinstance(tItem, list):
|
||||||
extractedTranslations = extractTranslation(translatedText, True)
|
extractedTranslations = extractTranslation(translatedText, True)
|
||||||
if extractedTranslations == None or len(tItem) != len(
|
if extractedTranslations == None or len(tItem) != len(extractedTranslations):
|
||||||
extractedTranslations
|
|
||||||
):
|
|
||||||
mismatch = True # Just here for breakpoint
|
mismatch = True # Just here for breakpoint
|
||||||
logFile.write(f"Input:\n{subbedT}\n")
|
logFile.write(f"Input:\n{subbedT}\n")
|
||||||
logFile.write(f"Output:\n{translatedText}\n")
|
logFile.write(f"Output:\n{translatedText}\n")
|
||||||
|
|
@ -534,9 +518,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
# Set if no mismatch
|
# Set if no mismatch
|
||||||
if mismatch == False:
|
if mismatch == False:
|
||||||
tList[index] = extractedTranslations
|
tList[index] = extractedTranslations
|
||||||
history = extractedTranslations[
|
history = extractedTranslations[-MAXHISTORY:] # Update history if we have a list
|
||||||
-MAXHISTORY:
|
|
||||||
] # Update history if we have a list
|
|
||||||
else:
|
else:
|
||||||
history = text[-MAXHISTORY:]
|
history = text[-MAXHISTORY:]
|
||||||
mismatch = False
|
mismatch = False
|
||||||
|
|
|
||||||
|
|
@ -217,19 +217,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] is None:
|
if translatedData[2] is None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
try:
|
try:
|
||||||
|
|
@ -237,16 +232,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def parseMap(data, filename):
|
def parseMap(data, filename):
|
||||||
|
|
@ -272,11 +258,7 @@ def parseMap(data, filename):
|
||||||
with ThreadPoolExecutor(max_workers=THREADS) as executor:
|
with ThreadPoolExecutor(max_workers=THREADS) as executor:
|
||||||
for key in events:
|
for key in events:
|
||||||
if key is not None:
|
if key is not None:
|
||||||
futures = [
|
futures = [executor.submit(searchCodes, page, pbar, [], filename) for page in events[key]["pages"] if page is not None]
|
||||||
executor.submit(searchCodes, page, pbar, [], filename)
|
|
||||||
for page in events[key]["pages"]
|
|
||||||
if page is not None
|
|
||||||
]
|
|
||||||
for future in as_completed(futures):
|
for future in as_completed(futures):
|
||||||
try:
|
try:
|
||||||
totalTokensFuture = future.result()
|
totalTokensFuture = future.result()
|
||||||
|
|
@ -359,11 +341,7 @@ def parseCommonEvents(data, filename):
|
||||||
with tqdm(bar_format=BAR_FORMAT, position=POSITION, leave=LEAVE) as pbar:
|
with tqdm(bar_format=BAR_FORMAT, position=POSITION, leave=LEAVE) as pbar:
|
||||||
pbar.desc = filename
|
pbar.desc = filename
|
||||||
with ThreadPoolExecutor(max_workers=THREADS) as executor:
|
with ThreadPoolExecutor(max_workers=THREADS) as executor:
|
||||||
futures = [
|
futures = [executor.submit(searchCodes, page, pbar, [], filename) for page in data if page is not None]
|
||||||
executor.submit(searchCodes, page, pbar, [], filename)
|
|
||||||
for page in data
|
|
||||||
if page is not None
|
|
||||||
]
|
|
||||||
for future in as_completed(futures):
|
for future in as_completed(futures):
|
||||||
try:
|
try:
|
||||||
totalTokensFuture = future.result()
|
totalTokensFuture = future.result()
|
||||||
|
|
@ -391,11 +369,7 @@ def parseTroops(data, filename):
|
||||||
for troop in data:
|
for troop in data:
|
||||||
if troop is not None:
|
if troop is not None:
|
||||||
with ThreadPoolExecutor(max_workers=THREADS) as executor:
|
with ThreadPoolExecutor(max_workers=THREADS) as executor:
|
||||||
futures = [
|
futures = [executor.submit(searchCodes, page, pbar, [], filename) for page in troop["pages"] if page is not None]
|
||||||
executor.submit(searchCodes, page, pbar, [], filename)
|
|
||||||
for page in troop["pages"]
|
|
||||||
if page is not None
|
|
||||||
]
|
|
||||||
for future in as_completed(futures):
|
for future in as_completed(futures):
|
||||||
try:
|
try:
|
||||||
totalTokensFuture = future.result()
|
totalTokensFuture = future.result()
|
||||||
|
|
@ -481,11 +455,7 @@ def parseScenario(data, filename):
|
||||||
with tqdm(bar_format=BAR_FORMAT, position=POSITION, leave=LEAVE) as pbar:
|
with tqdm(bar_format=BAR_FORMAT, position=POSITION, leave=LEAVE) as pbar:
|
||||||
pbar.desc = filename
|
pbar.desc = filename
|
||||||
with ThreadPoolExecutor(max_workers=THREADS) as executor:
|
with ThreadPoolExecutor(max_workers=THREADS) as executor:
|
||||||
futures = [
|
futures = [executor.submit(searchCodes, page[1], pbar, [], filename) for page in data.items() if page[1] is not None]
|
||||||
executor.submit(searchCodes, page[1], pbar, [], filename)
|
|
||||||
for page in data.items()
|
|
||||||
if page[1] is not None
|
|
||||||
]
|
|
||||||
for future in as_completed(futures):
|
for future in as_completed(futures):
|
||||||
try:
|
try:
|
||||||
totalTokensFuture = future.result()
|
totalTokensFuture = future.result()
|
||||||
|
|
@ -600,9 +570,7 @@ def searchNames(data, pbar, context):
|
||||||
totalTokens[0] += tokensResponse[0]
|
totalTokens[0] += tokensResponse[0]
|
||||||
totalTokens[1] += tokensResponse[1]
|
totalTokens[1] += tokensResponse[1]
|
||||||
if "Switch Shop Description" in data[i]["note"]:
|
if "Switch Shop Description" in data[i]["note"]:
|
||||||
tokensResponse = translateNote(
|
tokensResponse = translateNote(data[i], r"<Switch Shop Description>\n(.*)\n")
|
||||||
data[i], r"<Switch Shop Description>\n(.*)\n"
|
|
||||||
)
|
|
||||||
totalTokens[0] += tokensResponse[0]
|
totalTokens[0] += tokensResponse[0]
|
||||||
totalTokens[1] += tokensResponse[1]
|
totalTokens[1] += tokensResponse[1]
|
||||||
if "<MapText:" in data[i]["note"]:
|
if "<MapText:" in data[i]["note"]:
|
||||||
|
|
@ -623,9 +591,7 @@ def searchNames(data, pbar, context):
|
||||||
number = 1
|
number = 1
|
||||||
while number < 5:
|
while number < 5:
|
||||||
if f"message{number}" in data[i]:
|
if f"message{number}" in data[i]:
|
||||||
if len(data[i][f"message{number}"]) > 0 and data[i][f"message{number}"][
|
if len(data[i][f"message{number}"]) > 0 and data[i][f"message{number}"][0] in ["は", "を", "の", "に", "が"]:
|
||||||
0
|
|
||||||
] in ["は", "を", "の", "に", "が"]:
|
|
||||||
msgResponse = translateGPT(
|
msgResponse = translateGPT(
|
||||||
"Taro" + data[i][f"message{number}"],
|
"Taro" + data[i][f"message{number}"],
|
||||||
"reply with only the gender neutral "
|
"reply with only the gender neutral "
|
||||||
|
|
@ -641,9 +607,7 @@ def searchNames(data, pbar, context):
|
||||||
else:
|
else:
|
||||||
msgResponse = translateGPT(
|
msgResponse = translateGPT(
|
||||||
data[i][f"message{number}"],
|
data[i][f"message{number}"],
|
||||||
"reply with only the gender neutral "
|
"reply with only the gender neutral " + LANGUAGE + " translation",
|
||||||
+ LANGUAGE
|
|
||||||
+ " translation",
|
|
||||||
False,
|
False,
|
||||||
)
|
)
|
||||||
data[i][f"message{number}"] = msgResponse[0]
|
data[i][f"message{number}"] = msgResponse[0]
|
||||||
|
|
@ -715,9 +679,7 @@ def searchNames(data, pbar, context):
|
||||||
data[j]["nickname"] = translatedNicknameBatch[0]
|
data[j]["nickname"] = translatedNicknameBatch[0]
|
||||||
translatedNicknameBatch.pop(0)
|
translatedNicknameBatch.pop(0)
|
||||||
if data[j]["profile"] != "":
|
if data[j]["profile"] != "":
|
||||||
data[j]["profile"] = textwrap.fill(
|
data[j]["profile"] = textwrap.fill(translatedProfileBatch[0], LISTWIDTH)
|
||||||
translatedProfileBatch[0], LISTWIDTH
|
|
||||||
)
|
|
||||||
translatedProfileBatch.pop(0)
|
translatedProfileBatch.pop(0)
|
||||||
|
|
||||||
# If Batch is empty. Move on.
|
# If Batch is empty. Move on.
|
||||||
|
|
@ -760,9 +722,7 @@ def searchNames(data, pbar, context):
|
||||||
data[j]["name"] = translatedNameBatch[0]
|
data[j]["name"] = translatedNameBatch[0]
|
||||||
translatedNameBatch.pop(0)
|
translatedNameBatch.pop(0)
|
||||||
if "description" in data[j] and data[j]["description"] != "":
|
if "description" in data[j] and data[j]["description"] != "":
|
||||||
data[j]["description"] = textwrap.fill(
|
data[j]["description"] = textwrap.fill(translatedDescriptionBatch[0], LISTWIDTH)
|
||||||
translatedDescriptionBatch[0], LISTWIDTH
|
|
||||||
)
|
|
||||||
translatedDescriptionBatch.pop(0)
|
translatedDescriptionBatch.pop(0)
|
||||||
|
|
||||||
# If Batch is empty. Move on.
|
# If Batch is empty. Move on.
|
||||||
|
|
@ -1147,15 +1107,11 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
|
|
||||||
# Remove speaker
|
# Remove speaker
|
||||||
if speaker != "":
|
if speaker != "":
|
||||||
matchSpeakerList = re.findall(
|
matchSpeakerList = re.findall(r"^\[?(.+?)\]?\s?[|:]\s?", translatedText)
|
||||||
r"^\[?(.+?)\]?\s?[|:]\s?", translatedText
|
|
||||||
)
|
|
||||||
if len(matchSpeakerList) > 0:
|
if len(matchSpeakerList) > 0:
|
||||||
newSpeaker = matchSpeakerList[0]
|
newSpeaker = matchSpeakerList[0]
|
||||||
nametag = nametag.replace(speaker, newSpeaker)
|
nametag = nametag.replace(speaker, newSpeaker)
|
||||||
translatedText = re.sub(
|
translatedText = re.sub(r"^\[?(.+?)\]?\s?[|:]\s?", "", translatedText)
|
||||||
r"^\[?(.+?)\]?\s?[|:]\s?", "", translatedText
|
|
||||||
)
|
|
||||||
|
|
||||||
# Fix '- '
|
# Fix '- '
|
||||||
translatedText = translatedText.replace("- ", "-")
|
translatedText = translatedText.replace("- ", "-")
|
||||||
|
|
@ -1474,9 +1430,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
|
|
||||||
# Center Text
|
# Center Text
|
||||||
if acExist:
|
if acExist:
|
||||||
translatedText = (
|
translatedText = f'\\ac {translatedText.replace('\n', '\n\\ac ')}'
|
||||||
f'\\ac {translatedText.replace('\n', '\n\\ac ')}'
|
|
||||||
)
|
|
||||||
|
|
||||||
# Set
|
# Set
|
||||||
codeList[i]["p"][3][argVar] = translatedText
|
codeList[i]["p"][3][argVar] = translatedText
|
||||||
|
|
@ -1604,11 +1558,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
speaker = ""
|
speaker = ""
|
||||||
|
|
||||||
## Event Code: 355 or 655 Scripts [Optional]
|
## Event Code: 355 or 655 Scripts [Optional]
|
||||||
if (
|
if "c" in codeList[i] and (codeList[i]["c"] == 355 or codeList[i]["c"] == 655) and CODE355655 is True:
|
||||||
"c" in codeList[i]
|
|
||||||
and (codeList[i]["c"] == 355 or codeList[i]["c"] == 655)
|
|
||||||
and CODE355655 is True
|
|
||||||
):
|
|
||||||
jaString = codeList[i]["p"][0]
|
jaString = codeList[i]["p"][0]
|
||||||
regex = r"BattleManager\._logWindow.addText\('(.*)'"
|
regex = r"BattleManager\._logWindow.addText\('(.*)'"
|
||||||
|
|
||||||
|
|
@ -1627,9 +1577,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
translatedText = translatedText.replace("'", "\\'")
|
translatedText = translatedText.replace("'", "\\'")
|
||||||
|
|
||||||
# Set
|
# Set
|
||||||
codeList[i]["p"][0] = codeList[i]["p"][0].replace(
|
codeList[i]["p"][0] = codeList[i]["p"][0].replace(finalJAString, translatedText)
|
||||||
finalJAString, translatedText
|
|
||||||
)
|
|
||||||
list355655.pop(0)
|
list355655.pop(0)
|
||||||
|
|
||||||
## Event Code: 408 (Script)
|
## Event Code: 408 (Script)
|
||||||
|
|
@ -1803,9 +1751,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
if len(matchList) > 0:
|
if len(matchList) > 0:
|
||||||
# Translate
|
# Translate
|
||||||
text = matchList[0]
|
text = matchList[0]
|
||||||
response = translateGPT(
|
response = translateGPT(text, "Reply with the " + LANGUAGE + " Translation", False)
|
||||||
text, "Reply with the " + LANGUAGE + " Translation", False
|
|
||||||
)
|
|
||||||
translatedText = response[0]
|
translatedText = response[0]
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
|
|
@ -1819,9 +1765,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
if len(matchList) > 0:
|
if len(matchList) > 0:
|
||||||
# Translate
|
# Translate
|
||||||
text = matchList[0]
|
text = matchList[0]
|
||||||
response = translateGPT(
|
response = translateGPT(text, "Reply with the " + LANGUAGE + " Translation", False)
|
||||||
text, "Reply with the " + LANGUAGE + " Translation", False
|
|
||||||
)
|
|
||||||
translatedText = response[0]
|
translatedText = response[0]
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
|
|
@ -1836,9 +1780,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
if len(matchList) > 0:
|
if len(matchList) > 0:
|
||||||
# Translate
|
# Translate
|
||||||
text = matchList[0]
|
text = matchList[0]
|
||||||
response = translateGPT(
|
response = translateGPT(text, "Reply with the " + LANGUAGE + " Translation", False)
|
||||||
text, "Reply with the " + LANGUAGE + " Translation", False
|
|
||||||
)
|
|
||||||
translatedText = response[0]
|
translatedText = response[0]
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
|
|
@ -1926,8 +1868,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
if len(textHistory) > 0:
|
if len(textHistory) > 0:
|
||||||
response = translateGPT(
|
response = translateGPT(
|
||||||
choiceList,
|
choiceList,
|
||||||
"This will be a dialogue option.\nPrevious text for context: "
|
"This will be a dialogue option.\nPrevious text for context: " + str(textHistory),
|
||||||
+ str(textHistory),
|
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
translatedTextList = response[0]
|
translatedTextList = response[0]
|
||||||
|
|
@ -1948,9 +1889,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
if translatedText != "":
|
if translatedText != "":
|
||||||
translatedText = (
|
translatedText = varList[choice] + translatedText[0].upper() + translatedText[1:]
|
||||||
varList[choice] + translatedText[0].upper() + translatedText[1:]
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
translatedText = varList[choice] + translatedText
|
translatedText = varList[choice] + translatedText
|
||||||
codeList[i]["p"][0][choice] = translatedText
|
codeList[i]["p"][0][choice] = translatedText
|
||||||
|
|
@ -2369,9 +2308,7 @@ def searchSystem(data, pbar):
|
||||||
for i in range(len(data["weapon_types"])):
|
for i in range(len(data["weapon_types"])):
|
||||||
response = translateGPT(
|
response = translateGPT(
|
||||||
data["weapon_types"][i],
|
data["weapon_types"][i],
|
||||||
"Reply with only the "
|
"Reply with only the " + LANGUAGE + " translation of the equipment type. No disclaimers.",
|
||||||
+ LANGUAGE
|
|
||||||
+ " translation of the equipment type. No disclaimers.",
|
|
||||||
False,
|
False,
|
||||||
)
|
)
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
|
|
@ -2656,9 +2593,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
translatedText = cleanTranslatedText(translatedText, varResponse)
|
translatedText = cleanTranslatedText(translatedText, varResponse)
|
||||||
if isinstance(tItem, list):
|
if isinstance(tItem, list):
|
||||||
extractedTranslations = extractTranslation(translatedText, True)
|
extractedTranslations = extractTranslation(translatedText, True)
|
||||||
if extractedTranslations == None or len(tItem) != len(
|
if extractedTranslations == None or len(tItem) != len(extractedTranslations):
|
||||||
extractedTranslations
|
|
||||||
):
|
|
||||||
mismatch = True # Just here for breakpoint
|
mismatch = True # Just here for breakpoint
|
||||||
logFile.write(f"Input:\n{subbedT}\n")
|
logFile.write(f"Input:\n{subbedT}\n")
|
||||||
logFile.write(f"Output:\n{translatedText}\n")
|
logFile.write(f"Output:\n{translatedText}\n")
|
||||||
|
|
@ -2666,9 +2601,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
# Set if no mismatch
|
# Set if no mismatch
|
||||||
if mismatch == False:
|
if mismatch == False:
|
||||||
tList[index] = extractedTranslations
|
tList[index] = extractedTranslations
|
||||||
history = extractedTranslations[
|
history = extractedTranslations[-MAXHISTORY:] # Update history if we have a list
|
||||||
-MAXHISTORY:
|
|
||||||
] # Update history if we have a list
|
|
||||||
else:
|
else:
|
||||||
history = text[-MAXHISTORY:]
|
history = text[-MAXHISTORY:]
|
||||||
mismatch = False
|
mismatch = False
|
||||||
|
|
|
||||||
|
|
@ -195,19 +195,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] is None:
|
if translatedData[2] is None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
try:
|
try:
|
||||||
|
|
@ -215,16 +210,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def parseMap(data, filename):
|
def parseMap(data, filename):
|
||||||
|
|
@ -270,11 +256,7 @@ def parseMap(data, filename):
|
||||||
totalTokens[0] += response[0]
|
totalTokens[0] += response[0]
|
||||||
totalTokens[1] += response[1]
|
totalTokens[1] += response[1]
|
||||||
|
|
||||||
futures = [
|
futures = [executor.submit(searchCodes, page, pbar, [], filename) for page in event["pages"] if page is not None]
|
||||||
executor.submit(searchCodes, page, pbar, [], filename)
|
|
||||||
for page in event["pages"]
|
|
||||||
if page is not None
|
|
||||||
]
|
|
||||||
for future in as_completed(futures):
|
for future in as_completed(futures):
|
||||||
try:
|
try:
|
||||||
totalTokensFuture = future.result()
|
totalTokensFuture = future.result()
|
||||||
|
|
@ -357,11 +339,7 @@ def parseCommonEvents(data, filename):
|
||||||
with tqdm(bar_format=BAR_FORMAT, position=POSITION, leave=LEAVE) as pbar:
|
with tqdm(bar_format=BAR_FORMAT, position=POSITION, leave=LEAVE) as pbar:
|
||||||
pbar.desc = filename
|
pbar.desc = filename
|
||||||
with ThreadPoolExecutor(max_workers=THREADS) as executor:
|
with ThreadPoolExecutor(max_workers=THREADS) as executor:
|
||||||
futures = [
|
futures = [executor.submit(searchCodes, page, pbar, [], filename) for page in data if page is not None]
|
||||||
executor.submit(searchCodes, page, pbar, [], filename)
|
|
||||||
for page in data
|
|
||||||
if page is not None
|
|
||||||
]
|
|
||||||
for future in as_completed(futures):
|
for future in as_completed(futures):
|
||||||
try:
|
try:
|
||||||
totalTokensFuture = future.result()
|
totalTokensFuture = future.result()
|
||||||
|
|
@ -389,11 +367,7 @@ def parseTroops(data, filename):
|
||||||
for troop in data:
|
for troop in data:
|
||||||
if troop is not None:
|
if troop is not None:
|
||||||
with ThreadPoolExecutor(max_workers=THREADS) as executor:
|
with ThreadPoolExecutor(max_workers=THREADS) as executor:
|
||||||
futures = [
|
futures = [executor.submit(searchCodes, page, pbar, [], filename) for page in troop["pages"] if page is not None]
|
||||||
executor.submit(searchCodes, page, pbar, [], filename)
|
|
||||||
for page in troop["pages"]
|
|
||||||
if page is not None
|
|
||||||
]
|
|
||||||
for future in as_completed(futures):
|
for future in as_completed(futures):
|
||||||
try:
|
try:
|
||||||
totalTokensFuture = future.result()
|
totalTokensFuture = future.result()
|
||||||
|
|
@ -480,11 +454,7 @@ def parseScenario(data, filename):
|
||||||
with tqdm(bar_format=BAR_FORMAT, position=POSITION, leave=LEAVE) as pbar:
|
with tqdm(bar_format=BAR_FORMAT, position=POSITION, leave=LEAVE) as pbar:
|
||||||
pbar.desc = filename
|
pbar.desc = filename
|
||||||
with ThreadPoolExecutor(max_workers=THREADS) as executor:
|
with ThreadPoolExecutor(max_workers=THREADS) as executor:
|
||||||
futures = [
|
futures = [executor.submit(searchCodes, page[1], pbar, [], filename) for page in data.items() if page[1] is not None]
|
||||||
executor.submit(searchCodes, page[1], pbar, [], filename)
|
|
||||||
for page in data.items()
|
|
||||||
if page[1] is not None
|
|
||||||
]
|
|
||||||
for future in as_completed(futures):
|
for future in as_completed(futures):
|
||||||
try:
|
try:
|
||||||
totalTokensFuture = future.result()
|
totalTokensFuture = future.result()
|
||||||
|
|
@ -595,9 +565,7 @@ def searchNames(data, pbar, context):
|
||||||
totalTokens[0] += tokensResponse[0]
|
totalTokens[0] += tokensResponse[0]
|
||||||
totalTokens[1] += tokensResponse[1]
|
totalTokens[1] += tokensResponse[1]
|
||||||
if "Switch Shop Description" in data[i]["note"]:
|
if "Switch Shop Description" in data[i]["note"]:
|
||||||
tokensResponse = translateNote(
|
tokensResponse = translateNote(data[i], r"<Switch Shop Description>\n(.*)\n")
|
||||||
data[i], r"<Switch Shop Description>\n(.*)\n"
|
|
||||||
)
|
|
||||||
totalTokens[0] += tokensResponse[0]
|
totalTokens[0] += tokensResponse[0]
|
||||||
totalTokens[1] += tokensResponse[1]
|
totalTokens[1] += tokensResponse[1]
|
||||||
if "<MapText:" in data[i]["note"]:
|
if "<MapText:" in data[i]["note"]:
|
||||||
|
|
@ -634,9 +602,7 @@ def searchNames(data, pbar, context):
|
||||||
else:
|
else:
|
||||||
msgResponse = translateGPT(
|
msgResponse = translateGPT(
|
||||||
data[i][f"message{number}"],
|
data[i][f"message{number}"],
|
||||||
"reply with only the gender neutral "
|
"reply with only the gender neutral " + LANGUAGE + " translation",
|
||||||
+ LANGUAGE
|
|
||||||
+ " translation",
|
|
||||||
False,
|
False,
|
||||||
)
|
)
|
||||||
data[i][f"message{number}"] = msgResponse[0]
|
data[i][f"message{number}"] = msgResponse[0]
|
||||||
|
|
@ -709,9 +675,7 @@ def searchNames(data, pbar, context):
|
||||||
data[j]["nickname"] = translatedNicknameBatch[0]
|
data[j]["nickname"] = translatedNicknameBatch[0]
|
||||||
translatedNicknameBatch.pop(0)
|
translatedNicknameBatch.pop(0)
|
||||||
if data[j]["profile"] != "":
|
if data[j]["profile"] != "":
|
||||||
data[j]["profile"] = textwrap.fill(
|
data[j]["profile"] = textwrap.fill(translatedProfileBatch[0], LISTWIDTH)
|
||||||
translatedProfileBatch[0], LISTWIDTH
|
|
||||||
)
|
|
||||||
translatedProfileBatch.pop(0)
|
translatedProfileBatch.pop(0)
|
||||||
|
|
||||||
# If Batch is empty. Move on.
|
# If Batch is empty. Move on.
|
||||||
|
|
@ -754,9 +718,7 @@ def searchNames(data, pbar, context):
|
||||||
data[j]["name"] = translatedNameBatch[0]
|
data[j]["name"] = translatedNameBatch[0]
|
||||||
translatedNameBatch.pop(0)
|
translatedNameBatch.pop(0)
|
||||||
if "description" in data[j] and data[j]["description"] != "":
|
if "description" in data[j] and data[j]["description"] != "":
|
||||||
data[j]["description"] = textwrap.fill(
|
data[j]["description"] = textwrap.fill(translatedDescriptionBatch[0], LISTWIDTH)
|
||||||
translatedDescriptionBatch[0], LISTWIDTH
|
|
||||||
)
|
|
||||||
translatedDescriptionBatch.pop(0)
|
translatedDescriptionBatch.pop(0)
|
||||||
|
|
||||||
# If Batch is empty. Move on.
|
# If Batch is empty. Move on.
|
||||||
|
|
@ -872,11 +834,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
nametag = ""
|
nametag = ""
|
||||||
|
|
||||||
## Event Code: 401 Show Text
|
## Event Code: 401 Show Text
|
||||||
if (
|
if "code" in codeList[i] and codeList[i]["code"] in [401, 405, -1] and (CODE401 or CODE405):
|
||||||
"code" in codeList[i]
|
|
||||||
and codeList[i]["code"] in [401, 405, -1]
|
|
||||||
and (CODE401 or CODE405)
|
|
||||||
):
|
|
||||||
# Save Code and starting index (j)
|
# Save Code and starting index (j)
|
||||||
code = codeList[i]["code"]
|
code = codeList[i]["code"]
|
||||||
j = i
|
j = i
|
||||||
|
|
@ -892,10 +850,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Validate Japanese Text
|
# Validate Japanese Text
|
||||||
if (
|
if not re.search(r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString) and IGNORETLTEXT:
|
||||||
not re.search(r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString)
|
|
||||||
and IGNORETLTEXT
|
|
||||||
):
|
|
||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
@ -957,9 +912,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
and len(codeList[i + 1]["parameters"]) > 0
|
and len(codeList[i + 1]["parameters"]) > 0
|
||||||
and len(codeList[i + 1]["parameters"][0]) > 0
|
and len(codeList[i + 1]["parameters"][0]) > 0
|
||||||
):
|
):
|
||||||
if codeList[i + 1]["parameters"] != "" and codeList[i + 1]["parameters"][
|
if codeList[i + 1]["parameters"] != "" and codeList[i + 1]["parameters"][0].strip()[0] in [
|
||||||
0
|
|
||||||
].strip()[0] in [
|
|
||||||
"「",
|
"「",
|
||||||
'"',
|
'"',
|
||||||
"(",
|
"(",
|
||||||
|
|
@ -977,9 +930,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
|
|
||||||
# Set Data
|
# Set Data
|
||||||
codeList[i]["parameters"][0] = nametag + jaString.replace(
|
codeList[i]["parameters"][0] = nametag + jaString.replace(speakerList[0], speaker)
|
||||||
speakerList[0], speaker
|
|
||||||
)
|
|
||||||
nametag = ""
|
nametag = ""
|
||||||
|
|
||||||
# Iterate to next string
|
# Iterate to next string
|
||||||
|
|
@ -1127,15 +1078,11 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
|
|
||||||
# Remove speaker
|
# Remove speaker
|
||||||
if speaker != "":
|
if speaker != "":
|
||||||
matchSpeakerList = re.findall(
|
matchSpeakerList = re.findall(r"^\[?(.+?)\]?\s?[|:]\s?", translatedText)
|
||||||
r"^\[?(.+?)\]?\s?[|:]\s?", translatedText
|
|
||||||
)
|
|
||||||
if len(matchSpeakerList) > 0:
|
if len(matchSpeakerList) > 0:
|
||||||
newSpeaker = matchSpeakerList[0]
|
newSpeaker = matchSpeakerList[0]
|
||||||
nametag = nametag.replace(speaker, newSpeaker)
|
nametag = nametag.replace(speaker, newSpeaker)
|
||||||
translatedText = re.sub(
|
translatedText = re.sub(r"^\[?(.+?)\]?\s?[|:]\s?", "", translatedText)
|
||||||
r"^\[?(.+?)\]?\s?[|:]\s?", "", translatedText
|
|
||||||
)
|
|
||||||
|
|
||||||
# Fix '- '
|
# Fix '- '
|
||||||
translatedText = translatedText.replace("- ", "-")
|
translatedText = translatedText.replace("- ", "-")
|
||||||
|
|
@ -1458,9 +1405,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
|
|
||||||
# Center Text
|
# Center Text
|
||||||
if acExist:
|
if acExist:
|
||||||
translatedText = (
|
translatedText = f'\\ac {translatedText.replace('\n', '\n\\ac ')}'
|
||||||
f'\\ac {translatedText.replace('\n', '\n\\ac ')}'
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check and Set Font
|
# Check and Set Font
|
||||||
if "fontSize" in codeList[i]["parameters"][3]:
|
if "fontSize" in codeList[i]["parameters"][3]:
|
||||||
|
|
@ -1592,11 +1537,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
speaker = ""
|
speaker = ""
|
||||||
|
|
||||||
## Event Code: 355 or 655 Scripts [Optional]
|
## Event Code: 355 or 655 Scripts [Optional]
|
||||||
if (
|
if "code" in codeList[i] and (codeList[i]["code"] == 355 or codeList[i]["code"] == 655) and CODE355655 is True:
|
||||||
"code" in codeList[i]
|
|
||||||
and (codeList[i]["code"] == 355 or codeList[i]["code"] == 655)
|
|
||||||
and CODE355655 is True
|
|
||||||
):
|
|
||||||
jaString = codeList[i]["parameters"][0]
|
jaString = codeList[i]["parameters"][0]
|
||||||
regex = r'.*subject=(.*?)"'
|
regex = r'.*subject=(.*?)"'
|
||||||
|
|
||||||
|
|
@ -1615,9 +1556,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
translatedText = translatedText.replace("'", "\\'")
|
translatedText = translatedText.replace("'", "\\'")
|
||||||
|
|
||||||
# Set
|
# Set
|
||||||
codeList[i]["parameters"][0] = codeList[i]["parameters"][0].replace(
|
codeList[i]["parameters"][0] = codeList[i]["parameters"][0].replace(finalJAString, translatedText)
|
||||||
finalJAString, translatedText
|
|
||||||
)
|
|
||||||
list355655.pop(0)
|
list355655.pop(0)
|
||||||
|
|
||||||
## Event Code: 408 (Script)
|
## Event Code: 408 (Script)
|
||||||
|
|
@ -1791,9 +1730,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
if len(matchList) > 0:
|
if len(matchList) > 0:
|
||||||
# Translate
|
# Translate
|
||||||
text = matchList[0]
|
text = matchList[0]
|
||||||
response = translateGPT(
|
response = translateGPT(text, "Reply with the " + LANGUAGE + " Translation", False)
|
||||||
text, "Reply with the " + LANGUAGE + " Translation", False
|
|
||||||
)
|
|
||||||
translatedText = response[0]
|
translatedText = response[0]
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
|
|
@ -1807,9 +1744,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
if len(matchList) > 0:
|
if len(matchList) > 0:
|
||||||
# Translate
|
# Translate
|
||||||
text = matchList[0]
|
text = matchList[0]
|
||||||
response = translateGPT(
|
response = translateGPT(text, "Reply with the " + LANGUAGE + " Translation", False)
|
||||||
text, "Reply with the " + LANGUAGE + " Translation", False
|
|
||||||
)
|
|
||||||
translatedText = response[0]
|
translatedText = response[0]
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
|
|
@ -1824,9 +1759,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
if len(matchList) > 0:
|
if len(matchList) > 0:
|
||||||
# Translate
|
# Translate
|
||||||
text = matchList[0]
|
text = matchList[0]
|
||||||
response = translateGPT(
|
response = translateGPT(text, "Reply with the " + LANGUAGE + " Translation", False)
|
||||||
text, "Reply with the " + LANGUAGE + " Translation", False
|
|
||||||
)
|
|
||||||
translatedText = response[0]
|
translatedText = response[0]
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
|
|
@ -1914,8 +1847,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
if len(textHistory) > 0:
|
if len(textHistory) > 0:
|
||||||
response = translateGPT(
|
response = translateGPT(
|
||||||
choiceList,
|
choiceList,
|
||||||
"This will be a dialogue option.\nPrevious text for context: "
|
"This will be a dialogue option.\nPrevious text for context: " + str(textHistory),
|
||||||
+ str(textHistory),
|
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
translatedTextList = response[0]
|
translatedTextList = response[0]
|
||||||
|
|
@ -1936,9 +1868,7 @@ def searchCodes(page, pbar, jobList, filename):
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
if translatedText != "":
|
if translatedText != "":
|
||||||
translatedText = (
|
translatedText = varList[choice] + translatedText[0].upper() + translatedText[1:]
|
||||||
varList[choice] + translatedText[0].upper() + translatedText[1:]
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
translatedText = varList[choice] + translatedText
|
translatedText = varList[choice] + translatedText
|
||||||
codeList[i]["parameters"][0][choice] = translatedText
|
codeList[i]["parameters"][0][choice] = translatedText
|
||||||
|
|
@ -2360,9 +2290,7 @@ def searchSystem(data, pbar):
|
||||||
for i in range(len(data["equipTypes"])):
|
for i in range(len(data["equipTypes"])):
|
||||||
response = translateGPT(
|
response = translateGPT(
|
||||||
data["equipTypes"][i],
|
data["equipTypes"][i],
|
||||||
"Reply with only the "
|
"Reply with only the " + LANGUAGE + " translation of the equipment type. No disclaimers.",
|
||||||
+ LANGUAGE
|
|
||||||
+ " translation of the equipment type. No disclaimers.",
|
|
||||||
False,
|
False,
|
||||||
)
|
)
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
|
|
@ -2644,9 +2572,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
translatedText = cleanTranslatedText(translatedText, varResponse)
|
translatedText = cleanTranslatedText(translatedText, varResponse)
|
||||||
if isinstance(tItem, list):
|
if isinstance(tItem, list):
|
||||||
extractedTranslations = extractTranslation(translatedText, True)
|
extractedTranslations = extractTranslation(translatedText, True)
|
||||||
if extractedTranslations == None or len(tItem) != len(
|
if extractedTranslations == None or len(tItem) != len(extractedTranslations):
|
||||||
extractedTranslations
|
|
||||||
):
|
|
||||||
mismatch = True # Just here for breakpoint
|
mismatch = True # Just here for breakpoint
|
||||||
logFile.write(f"Input:\n{subbedT}\n")
|
logFile.write(f"Input:\n{subbedT}\n")
|
||||||
logFile.write(f"Output:\n{translatedText}\n")
|
logFile.write(f"Output:\n{translatedText}\n")
|
||||||
|
|
@ -2654,9 +2580,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
# Set if no mismatch
|
# Set if no mismatch
|
||||||
if mismatch == False:
|
if mismatch == False:
|
||||||
tList[index] = extractedTranslations
|
tList[index] = extractedTranslations
|
||||||
history = extractedTranslations[
|
history = extractedTranslations[-MAXHISTORY:] # Update history if we have a list
|
||||||
-MAXHISTORY:
|
|
||||||
] # Update history if we have a list
|
|
||||||
else:
|
else:
|
||||||
history = text[-MAXHISTORY:]
|
history = text[-MAXHISTORY:]
|
||||||
mismatch = False
|
mismatch = False
|
||||||
|
|
|
||||||
|
|
@ -111,19 +111,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] == None:
|
if translatedData[2] == None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
|
|
@ -132,16 +127,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def openFiles(filename):
|
def openFiles(filename):
|
||||||
|
|
@ -515,9 +501,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
translatedText = cleanTranslatedText(translatedText, varResponse)
|
translatedText = cleanTranslatedText(translatedText, varResponse)
|
||||||
if isinstance(tItem, list):
|
if isinstance(tItem, list):
|
||||||
extractedTranslations = extractTranslation(translatedText, True)
|
extractedTranslations = extractTranslation(translatedText, True)
|
||||||
if extractedTranslations == None or len(tItem) != len(
|
if extractedTranslations == None or len(tItem) != len(extractedTranslations):
|
||||||
extractedTranslations
|
|
||||||
):
|
|
||||||
mismatch = True # Just here for breakpoint
|
mismatch = True # Just here for breakpoint
|
||||||
logFile.write(f"Input:\n{subbedT}\n")
|
logFile.write(f"Input:\n{subbedT}\n")
|
||||||
logFile.write(f"Output:\n{translatedText}\n")
|
logFile.write(f"Output:\n{translatedText}\n")
|
||||||
|
|
@ -525,9 +509,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
# Set if no mismatch
|
# Set if no mismatch
|
||||||
if mismatch == False:
|
if mismatch == False:
|
||||||
tList[index] = extractedTranslations
|
tList[index] = extractedTranslations
|
||||||
history = extractedTranslations[
|
history = extractedTranslations[-MAXHISTORY:] # Update history if we have a list
|
||||||
-MAXHISTORY:
|
|
||||||
] # Update history if we have a list
|
|
||||||
else:
|
else:
|
||||||
history = text[-MAXHISTORY:]
|
history = text[-MAXHISTORY:]
|
||||||
mismatch = False
|
mismatch = False
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,7 @@ LANGUAGE = os.getenv("language").capitalize()
|
||||||
INPUTAPICOST = 0.002 # Depends on the model https://openai.com/pricing
|
INPUTAPICOST = 0.002 # Depends on the model https://openai.com/pricing
|
||||||
OUTPUTAPICOST = 0.002
|
OUTPUTAPICOST = 0.002
|
||||||
PROMPT = Path("prompt.txt").read_text(encoding="utf-8")
|
PROMPT = Path("prompt.txt").read_text(encoding="utf-8")
|
||||||
THREADS = int(
|
THREADS = int(os.getenv("threads")) # Controls how many threads are working on a single file (May have to drop this)
|
||||||
os.getenv("threads")
|
|
||||||
) # Controls how many threads are working on a single file (May have to drop this)
|
|
||||||
LOCK = threading.Lock()
|
LOCK = threading.Lock()
|
||||||
WIDTH = int(os.getenv("width"))
|
WIDTH = int(os.getenv("width"))
|
||||||
LISTWIDTH = int(os.getenv("listWidth"))
|
LISTWIDTH = int(os.getenv("listWidth"))
|
||||||
|
|
@ -97,19 +95,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] is None:
|
if translatedData[2] is None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
|
|
@ -117,16 +110,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
raise translatedData[2]
|
raise translatedData[2]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def openFiles(filename):
|
def openFiles(filename):
|
||||||
|
|
@ -232,9 +216,7 @@ def translateTyrano(data, pbar):
|
||||||
if len(textHistory) > 0:
|
if len(textHistory) > 0:
|
||||||
response = translateGPT(
|
response = translateGPT(
|
||||||
matchList[0],
|
matchList[0],
|
||||||
"Past Translated Text: "
|
"Past Translated Text: " + textHistory[len(textHistory) - 1] + "\n\nReply in the style of a dialogue option.",
|
||||||
+ textHistory[len(textHistory) - 1]
|
|
||||||
+ "\n\nReply in the style of a dialogue option.",
|
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|
@ -253,17 +235,13 @@ def translateTyrano(data, pbar):
|
||||||
translatedText = translatedText.replace("'", "\\'")
|
translatedText = translatedText.replace("'", "\\'")
|
||||||
|
|
||||||
# Set Data
|
# Set Data
|
||||||
translatedText = data[i].replace(
|
translatedText = data[i].replace(matchList[0], translatedText.replace(" ", "\u00a0"))
|
||||||
matchList[0], translatedText.replace(" ", "\u00a0")
|
|
||||||
)
|
|
||||||
data[i] = translatedText
|
data[i] = translatedText
|
||||||
|
|
||||||
# Grab Lines
|
# Grab Lines
|
||||||
matchList = re.findall(r"^([^\n;@*\{\[].+[^;'{}\[]$)", data[i])
|
matchList = re.findall(r"^([^\n;@*\{\[].+[^;'{}\[]$)", data[i])
|
||||||
if len(matchList) > 0 and (
|
if len(matchList) > 0 and (
|
||||||
re.search(r"^\[(.+)\sstorage=.+\],", data[i - 1])
|
re.search(r"^\[(.+)\sstorage=.+\],", data[i - 1]) or re.search(r"^\[(.+)\]$", data[i - 1]) or re.search(r"^《(.+)》", data[i - 1])
|
||||||
or re.search(r"^\[(.+)\]$", data[i - 1])
|
|
||||||
or re.search(r"^《(.+)》", data[i - 1])
|
|
||||||
):
|
):
|
||||||
currentGroup.append(matchList[0])
|
currentGroup.append(matchList[0])
|
||||||
if len(data) > i + 1:
|
if len(data) > i + 1:
|
||||||
|
|
@ -566,13 +544,7 @@ def translateGPT(t, history, fullPromptFlag):
|
||||||
system = PROMPT
|
system = PROMPT
|
||||||
user = "Line to Translate = " + subbedT
|
user = "Line to Translate = " + subbedT
|
||||||
else:
|
else:
|
||||||
system = (
|
system = "Output ONLY the " + LANGUAGE + " translation in the following format: `Translation: <" + LANGUAGE.upper() + "_TRANSLATION>`"
|
||||||
"Output ONLY the "
|
|
||||||
+ LANGUAGE
|
|
||||||
+ " translation in the following format: `Translation: <"
|
|
||||||
+ LANGUAGE.upper()
|
|
||||||
+ "_TRANSLATION>`"
|
|
||||||
)
|
|
||||||
user = "Line to Translate = " + subbedT
|
user = "Line to Translate = " + subbedT
|
||||||
|
|
||||||
# Create Message List
|
# Create Message List
|
||||||
|
|
@ -622,10 +594,7 @@ def translateGPT(t, history, fullPromptFlag):
|
||||||
translatedText = translatedText.replace("!", "!")
|
translatedText = translatedText.replace("!", "!")
|
||||||
|
|
||||||
# Return Translation
|
# Return Translation
|
||||||
if (
|
if len(translatedText) > 15 * len(t) or "I'm sorry, but I'm unable to assist with that translation" in translatedText:
|
||||||
len(translatedText) > 15 * len(t)
|
|
||||||
or "I'm sorry, but I'm unable to assist with that translation" in translatedText
|
|
||||||
):
|
|
||||||
raise Exception
|
raise Exception
|
||||||
else:
|
else:
|
||||||
return [translatedText, totalTokens]
|
return [translatedText, totalTokens]
|
||||||
|
|
|
||||||
|
|
@ -103,19 +103,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] == None:
|
if translatedData[2] == None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
|
|
@ -124,16 +119,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def openFiles(filename):
|
def openFiles(filename):
|
||||||
|
|
@ -253,9 +239,7 @@ def translateTxt(data, translatedList):
|
||||||
|
|
||||||
# Choice List
|
# Choice List
|
||||||
if choiceList:
|
if choiceList:
|
||||||
response = translateGPT(
|
response = translateGPT(choiceList, "Reply with the English TL of the Dialogue Choice", True)
|
||||||
choiceList, "Reply with the English TL of the Dialogue Choice", True
|
|
||||||
)
|
|
||||||
tokens[0] += response[1][0]
|
tokens[0] += response[1][0]
|
||||||
tokens[1] += response[1][1]
|
tokens[1] += response[1][1]
|
||||||
choiceListTL = response[0]
|
choiceListTL = response[0]
|
||||||
|
|
@ -515,9 +499,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
translatedText = cleanTranslatedText(translatedText, varResponse)
|
translatedText = cleanTranslatedText(translatedText, varResponse)
|
||||||
if isinstance(tItem, list):
|
if isinstance(tItem, list):
|
||||||
extractedTranslations = extractTranslation(translatedText, True)
|
extractedTranslations = extractTranslation(translatedText, True)
|
||||||
if extractedTranslations == None or len(tItem) != len(
|
if extractedTranslations == None or len(tItem) != len(extractedTranslations):
|
||||||
extractedTranslations
|
|
||||||
):
|
|
||||||
mismatch = True # Just here for breakpoint
|
mismatch = True # Just here for breakpoint
|
||||||
logFile.write(f"Input:\n{subbedT}\n")
|
logFile.write(f"Input:\n{subbedT}\n")
|
||||||
logFile.write(f"Output:\n{translatedText}\n")
|
logFile.write(f"Output:\n{translatedText}\n")
|
||||||
|
|
@ -525,9 +507,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
# Set if no mismatch
|
# Set if no mismatch
|
||||||
if mismatch == False:
|
if mismatch == False:
|
||||||
tList[index] = extractedTranslations
|
tList[index] = extractedTranslations
|
||||||
history = extractedTranslations[
|
history = extractedTranslations[-MAXHISTORY:] # Update history if we have a list
|
||||||
-MAXHISTORY:
|
|
||||||
] # Update history if we have a list
|
|
||||||
else:
|
else:
|
||||||
history = text[-MAXHISTORY:]
|
history = text[-MAXHISTORY:]
|
||||||
mismatch = False
|
mismatch = False
|
||||||
|
|
|
||||||
|
|
@ -103,19 +103,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] == None:
|
if translatedData[2] == None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
|
|
@ -124,16 +119,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def openFiles(filename):
|
def openFiles(filename):
|
||||||
|
|
@ -186,9 +172,7 @@ def translateTyrano(data, translatedList):
|
||||||
|
|
||||||
while i < len(data):
|
while i < len(data):
|
||||||
voice = False
|
voice = False
|
||||||
lineRegexNoSpeaker = (
|
lineRegexNoSpeaker = r"^([^\[#;*@\n]+)\[l\]\[[rp]\]|^([^\[#;*@\n]+)\[[rpl]\]|^([^\[#;*@_\n]+)\n$"
|
||||||
r"^([^\[#;*@\n]+)\[l\]\[[rp]\]|^([^\[#;*@\n]+)\[[rpl]\]|^([^\[#;*@_\n]+)\n$"
|
|
||||||
)
|
|
||||||
lineRegexSpeaker = r"^#(.*)"
|
lineRegexSpeaker = r"^#(.*)"
|
||||||
furiganaRegex = r"(\[ruby\stext=(.*?)\])"
|
furiganaRegex = r"(\[ruby\stext=(.*?)\])"
|
||||||
choiceRegex = r'\[glink.+?text="(.*?)"'
|
choiceRegex = r'\[glink.+?text="(.*?)"'
|
||||||
|
|
@ -329,9 +313,7 @@ def translateTyrano(data, translatedList):
|
||||||
|
|
||||||
# Choice List
|
# Choice List
|
||||||
if choiceList:
|
if choiceList:
|
||||||
response = translateGPT(
|
response = translateGPT(choiceList, "Reply with the English TL of the Dialogue Choice", True)
|
||||||
choiceList, "Reply with the English TL of the Dialogue Choice", True
|
|
||||||
)
|
|
||||||
tokens[0] += response[1][0]
|
tokens[0] += response[1][0]
|
||||||
tokens[1] += response[1][1]
|
tokens[1] += response[1][1]
|
||||||
choiceListTL = response[0]
|
choiceListTL = response[0]
|
||||||
|
|
@ -591,9 +573,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
translatedText = cleanTranslatedText(translatedText, varResponse)
|
translatedText = cleanTranslatedText(translatedText, varResponse)
|
||||||
if isinstance(tItem, list):
|
if isinstance(tItem, list):
|
||||||
extractedTranslations = extractTranslation(translatedText, True)
|
extractedTranslations = extractTranslation(translatedText, True)
|
||||||
if extractedTranslations == None or len(tItem) != len(
|
if extractedTranslations == None or len(tItem) != len(extractedTranslations):
|
||||||
extractedTranslations
|
|
||||||
):
|
|
||||||
mismatch = True # Just here for breakpoint
|
mismatch = True # Just here for breakpoint
|
||||||
logFile.write(f"Input:\n{subbedT}\n")
|
logFile.write(f"Input:\n{subbedT}\n")
|
||||||
logFile.write(f"Output:\n{translatedText}\n")
|
logFile.write(f"Output:\n{translatedText}\n")
|
||||||
|
|
@ -601,9 +581,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
# Set if no mismatch
|
# Set if no mismatch
|
||||||
if mismatch == False:
|
if mismatch == False:
|
||||||
tList[index] = extractedTranslations
|
tList[index] = extractedTranslations
|
||||||
history = extractedTranslations[
|
history = extractedTranslations[-MAXHISTORY:] # Update history if we have a list
|
||||||
-MAXHISTORY:
|
|
||||||
] # Update history if we have a list
|
|
||||||
else:
|
else:
|
||||||
history = text[-MAXHISTORY:]
|
history = text[-MAXHISTORY:]
|
||||||
mismatch = False
|
mismatch = False
|
||||||
|
|
|
||||||
|
|
@ -119,19 +119,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] == None:
|
if translatedData[2] == None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
|
|
@ -140,16 +135,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def openFiles(filename):
|
def openFiles(filename):
|
||||||
|
|
|
||||||
138
modules/wolf.py
138
modules/wolf.py
|
|
@ -159,19 +159,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] is None:
|
if translatedData[2] is None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
try:
|
try:
|
||||||
|
|
@ -179,16 +174,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def parseOther(data, filename):
|
def parseOther(data, filename):
|
||||||
|
|
@ -248,11 +234,7 @@ def parseMap(data, filename):
|
||||||
with ThreadPoolExecutor(max_workers=THREADS) as executor:
|
with ThreadPoolExecutor(max_workers=THREADS) as executor:
|
||||||
for event in events:
|
for event in events:
|
||||||
if event is not None:
|
if event is not None:
|
||||||
futures = [
|
futures = [executor.submit(searchCodes, page["list"], pbar, None, filename) for page in event["pages"] if page is not None]
|
||||||
executor.submit(searchCodes, page["list"], pbar, None, filename)
|
|
||||||
for page in event["pages"]
|
|
||||||
if page is not None
|
|
||||||
]
|
|
||||||
for future in as_completed(futures):
|
for future in as_completed(futures):
|
||||||
try:
|
try:
|
||||||
totalTokensFuture = future.result()
|
totalTokensFuture = future.result()
|
||||||
|
|
@ -388,11 +370,7 @@ def searchCodes(events, pbar, jobList, filename):
|
||||||
### Event Code: 210 Common Event
|
### Event Code: 210 Common Event
|
||||||
if codeList[i]["code"] == 210 and CODE210 == True:
|
if codeList[i]["code"] == 210 and CODE210 == True:
|
||||||
# Speaker Event
|
# Speaker Event
|
||||||
if (
|
if "stringArgs" in codeList[i] and codeList[i]["intArgs"][0] == None and len(codeList[i]["stringArgs"]) == 2:
|
||||||
"stringArgs" in codeList[i]
|
|
||||||
and codeList[i]["intArgs"][0] == None
|
|
||||||
and len(codeList[i]["stringArgs"]) == 2
|
|
||||||
):
|
|
||||||
response = getSpeaker(codeList[i]["stringArgs"][1])
|
response = getSpeaker(codeList[i]["stringArgs"][1])
|
||||||
totalTokens[1] += response[1][0]
|
totalTokens[1] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
|
|
@ -401,11 +379,7 @@ def searchCodes(events, pbar, jobList, filename):
|
||||||
codeList[i]["stringArgs"][1] = response[0]
|
codeList[i]["stringArgs"][1] = response[0]
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
elif (
|
elif "stringArgs" in codeList[i] and codeList[i]["intArgs"][0] == 500220 and len(codeList[i]["stringArgs"]) == 2:
|
||||||
"stringArgs" in codeList[i]
|
|
||||||
and codeList[i]["intArgs"][0] == 500220
|
|
||||||
and len(codeList[i]["stringArgs"]) == 2
|
|
||||||
):
|
|
||||||
# Grab String
|
# Grab String
|
||||||
jaString = codeList[i]["stringArgs"][1]
|
jaString = codeList[i]["stringArgs"][1]
|
||||||
initialJAString = jaString
|
initialJAString = jaString
|
||||||
|
|
@ -499,9 +473,7 @@ def searchCodes(events, pbar, jobList, filename):
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
|
|
||||||
# Set String
|
# Set String
|
||||||
codeList[i]["stringArgs"][0] = codeList[i]["stringArgs"][0].replace(
|
codeList[i]["stringArgs"][0] = codeList[i]["stringArgs"][0].replace(jaString, translatedText)
|
||||||
jaString, translatedText
|
|
||||||
)
|
|
||||||
|
|
||||||
### Event Code: 122 SetString
|
### Event Code: 122 SetString
|
||||||
if codeList[i]["code"] == 150 and CODE150 == True:
|
if codeList[i]["code"] == 150 and CODE150 == True:
|
||||||
|
|
@ -544,17 +516,9 @@ def searchCodes(events, pbar, jobList, filename):
|
||||||
codeList[i]["stringArgs"][0] = translatedText
|
codeList[i]["stringArgs"][0] = translatedText
|
||||||
|
|
||||||
### Event Code: 300 Common Events
|
### Event Code: 300 Common Events
|
||||||
if (
|
if codeList[i]["code"] == 300 and CODE300 == True and "stringArgs" in codeList[i] and len(codeList[i]["stringArgs"]) > 1:
|
||||||
codeList[i]["code"] == 300
|
|
||||||
and CODE300 == True
|
|
||||||
and "stringArgs" in codeList[i]
|
|
||||||
and len(codeList[i]["stringArgs"]) > 1
|
|
||||||
):
|
|
||||||
# Choices
|
# Choices
|
||||||
if (
|
if codeList[i]["stringArgs"][0] == "[共]汎用ウィンドウ生成" or codeList[i]["stringArgs"][0] == "[共]選択生成":
|
||||||
codeList[i]["stringArgs"][0] == "[共]汎用ウィンドウ生成"
|
|
||||||
or codeList[i]["stringArgs"][0] == "[共]選択生成"
|
|
||||||
):
|
|
||||||
# Grab String
|
# Grab String
|
||||||
choiceList = codeList[i]["stringArgs"][1].split("\r\n")
|
choiceList = codeList[i]["stringArgs"][1].split("\r\n")
|
||||||
|
|
||||||
|
|
@ -610,18 +574,13 @@ def searchCodes(events, pbar, jobList, filename):
|
||||||
|
|
||||||
# Validate size
|
# Validate size
|
||||||
if len(codeList[i]["stringArgs"]) == 4:
|
if len(codeList[i]["stringArgs"]) == 4:
|
||||||
if (
|
if codeList[i]["stringArgs"][1] == "┣所持アイテム個数" and codeList[i]["stringArgs"][2] != "":
|
||||||
codeList[i]["stringArgs"][1] == "┣所持アイテム個数"
|
|
||||||
and codeList[i]["stringArgs"][2] != ""
|
|
||||||
):
|
|
||||||
# Grab String
|
# Grab String
|
||||||
jaString = codeList[i]["stringArgs"][2]
|
jaString = codeList[i]["stringArgs"][2]
|
||||||
|
|
||||||
# Catch Vars that may break the TL
|
# Catch Vars that may break the TL
|
||||||
varString = ""
|
varString = ""
|
||||||
matchList = re.findall(
|
matchList = re.findall(r"^[\\_]+[\w]+\[[a-zA-Z0-9\\\[\]\_,\s-]+\]", jaString)
|
||||||
r"^[\\_]+[\w]+\[[a-zA-Z0-9\\\[\]\_,\s-]+\]", jaString
|
|
||||||
)
|
|
||||||
if len(matchList) != 0:
|
if len(matchList) != 0:
|
||||||
varString = matchList[0]
|
varString = matchList[0]
|
||||||
jaString = jaString.replace(matchList[0], "")
|
jaString = jaString.replace(matchList[0], "")
|
||||||
|
|
@ -733,9 +692,7 @@ def formatDramon(jaString):
|
||||||
jaStringList = re.split(imageRegex, jaString)
|
jaStringList = re.split(imageRegex, jaString)
|
||||||
|
|
||||||
# Clean List
|
# Clean List
|
||||||
cleanedList = [
|
cleanedList = [x for x in jaStringList if x is not None and x != "" and x != "\r\n" and x != "_SS_"]
|
||||||
x for x in jaStringList if x is not None and x != "" and x != "\r\n" and x != "_SS_"
|
|
||||||
]
|
|
||||||
|
|
||||||
# Iterate Through List
|
# Iterate Through List
|
||||||
j = 0
|
j = 0
|
||||||
|
|
@ -748,12 +705,7 @@ def formatDramon(jaString):
|
||||||
and ".ogg" not in cleanedList[j]
|
and ".ogg" not in cleanedList[j]
|
||||||
):
|
):
|
||||||
# Setup @
|
# Setup @
|
||||||
if (
|
if j > 0 and "@" not in cleanedList[j - 1] and "/" not in cleanedList[j - 1] and "_" not in cleanedList[j - 1]:
|
||||||
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]
|
cleanedList[j - 1] = cleanedList[j - 1] + cleanedList[j + 1]
|
||||||
else:
|
else:
|
||||||
cleanedList.insert(j, cleanedList[j + 1])
|
cleanedList.insert(j, cleanedList[j + 1])
|
||||||
|
|
@ -1682,23 +1634,17 @@ def searchDB(events, pbar, jobList, filename):
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
# Desc 1
|
# Desc 1
|
||||||
response = translateGPT(
|
response = translateGPT(npcList[1], "Reply with only the " + LANGUAGE + " translation", True)
|
||||||
npcList[1], "Reply with only the " + LANGUAGE + " translation", True
|
|
||||||
)
|
|
||||||
descListTL1 = response[0]
|
descListTL1 = response[0]
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
# Desc 2
|
# Desc 2
|
||||||
response = translateGPT(
|
response = translateGPT(npcList[2], "Reply with only the " + LANGUAGE + " translation", True)
|
||||||
npcList[2], "Reply with only the " + LANGUAGE + " translation", True
|
|
||||||
)
|
|
||||||
descListTL2 = response[0]
|
descListTL2 = response[0]
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
# Desc 3
|
# Desc 3
|
||||||
response = translateGPT(
|
response = translateGPT(npcList[3], "Reply with only the " + LANGUAGE + " translation", True)
|
||||||
npcList[3], "Reply with only the " + LANGUAGE + " translation", True
|
|
||||||
)
|
|
||||||
descListTL3 = response[0]
|
descListTL3 = response[0]
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
|
|
@ -1755,11 +1701,7 @@ def searchDB(events, pbar, jobList, filename):
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
|
|
||||||
# Check Mismatch
|
# Check Mismatch
|
||||||
if (
|
if len(nameListTL) != len(scenarioList[0]) or len(descListTL1) != len(scenarioList[1]) or len(descListTL2) != len(scenarioList[2]):
|
||||||
len(nameListTL) != len(scenarioList[0])
|
|
||||||
or len(descListTL1) != len(scenarioList[1])
|
|
||||||
or len(descListTL2) != len(scenarioList[2])
|
|
||||||
):
|
|
||||||
with LOCK:
|
with LOCK:
|
||||||
if filename not in MISMATCH:
|
if filename not in MISMATCH:
|
||||||
MISMATCH.append(filename)
|
MISMATCH.append(filename)
|
||||||
|
|
@ -1777,30 +1719,22 @@ def searchDB(events, pbar, jobList, filename):
|
||||||
pbar.refresh()
|
pbar.refresh()
|
||||||
|
|
||||||
# Name
|
# Name
|
||||||
response = translateGPT(
|
response = translateGPT(itemList[0], "Reply with only the " + LANGUAGE + " translation", True)
|
||||||
itemList[0], "Reply with only the " + LANGUAGE + " translation", True
|
|
||||||
)
|
|
||||||
nameListTL = response[0]
|
nameListTL = response[0]
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
# Desc 1
|
# Desc 1
|
||||||
response = translateGPT(
|
response = translateGPT(itemList[1], "Reply with only the " + LANGUAGE + " translation", True)
|
||||||
itemList[1], "Reply with only the " + LANGUAGE + " translation", True
|
|
||||||
)
|
|
||||||
descListTL1 = response[0]
|
descListTL1 = response[0]
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
# Desc 2
|
# Desc 2
|
||||||
response = translateGPT(
|
response = translateGPT(itemList[2], "Reply with only the " + LANGUAGE + " translation", True)
|
||||||
itemList[2], "Reply with only the " + LANGUAGE + " translation", True
|
|
||||||
)
|
|
||||||
descListTL2 = response[0]
|
descListTL2 = response[0]
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
# Desc 3
|
# Desc 3
|
||||||
response = translateGPT(
|
response = translateGPT(itemList[3], "Reply with only the " + LANGUAGE + " translation", True)
|
||||||
itemList[3], "Reply with only the " + LANGUAGE + " translation", True
|
|
||||||
)
|
|
||||||
descListTL3 = response[0]
|
descListTL3 = response[0]
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
|
|
@ -1838,9 +1772,7 @@ def searchDB(events, pbar, jobList, filename):
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
# Desc 1
|
# Desc 1
|
||||||
response = translateGPT(
|
response = translateGPT(armorList[1], "Reply with only the " + LANGUAGE + " translation", True)
|
||||||
armorList[1], "Reply with only the " + LANGUAGE + " translation", True
|
|
||||||
)
|
|
||||||
descListTL1 = response[0]
|
descListTL1 = response[0]
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
|
|
@ -1873,9 +1805,7 @@ def searchDB(events, pbar, jobList, filename):
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
# Desc 1
|
# Desc 1
|
||||||
response = translateGPT(
|
response = translateGPT(enemyList[1], "Reply with only the " + LANGUAGE + " translation", True)
|
||||||
enemyList[1], "Reply with only the " + LANGUAGE + " translation", True
|
|
||||||
)
|
|
||||||
descListTL1 = response[0]
|
descListTL1 = response[0]
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
|
|
@ -1919,11 +1849,7 @@ def searchDB(events, pbar, jobList, filename):
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
|
|
||||||
# Check Mismatch
|
# Check Mismatch
|
||||||
if (
|
if len(nameListTL) != len(weaponsList[0]) or len(descListTL1) != len(weaponsList[1]) or len(descListTL2) != len(weaponsList[2]):
|
||||||
len(nameListTL) != len(weaponsList[0])
|
|
||||||
or len(descListTL1) != len(weaponsList[1])
|
|
||||||
or len(descListTL2) != len(weaponsList[2])
|
|
||||||
):
|
|
||||||
with LOCK:
|
with LOCK:
|
||||||
if filename not in MISMATCH:
|
if filename not in MISMATCH:
|
||||||
MISMATCH.append(filename)
|
MISMATCH.append(filename)
|
||||||
|
|
@ -2143,9 +2069,7 @@ def searchDB(events, pbar, jobList, filename):
|
||||||
pbar.refresh()
|
pbar.refresh()
|
||||||
|
|
||||||
# Name
|
# Name
|
||||||
response = translateGPT(
|
response = translateGPT(itemList[0], "Reply with only the " + LANGUAGE + " translation", True)
|
||||||
itemList[0], "Reply with only the " + LANGUAGE + " translation", True
|
|
||||||
)
|
|
||||||
nameListTL = response[0]
|
nameListTL = response[0]
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
|
|
@ -2169,9 +2093,7 @@ def searchDB(events, pbar, jobList, filename):
|
||||||
pbar.refresh()
|
pbar.refresh()
|
||||||
|
|
||||||
# Name
|
# Name
|
||||||
response = translateGPT(
|
response = translateGPT(dbNameList[0], "Reply with only the " + LANGUAGE + " translation", True)
|
||||||
dbNameList[0], "Reply with only the " + LANGUAGE + " translation", True
|
|
||||||
)
|
|
||||||
nameListTL = response[0]
|
nameListTL = response[0]
|
||||||
totalTokens[0] += response[1][0]
|
totalTokens[0] += response[1][0]
|
||||||
totalTokens[1] += response[1][1]
|
totalTokens[1] += response[1][1]
|
||||||
|
|
@ -2453,9 +2375,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
translatedText = cleanTranslatedText(translatedText, varResponse)
|
translatedText = cleanTranslatedText(translatedText, varResponse)
|
||||||
if isinstance(tItem, list):
|
if isinstance(tItem, list):
|
||||||
extractedTranslations = extractTranslation(translatedText, True)
|
extractedTranslations = extractTranslation(translatedText, True)
|
||||||
if extractedTranslations == None or len(tItem) != len(
|
if extractedTranslations == None or len(tItem) != len(extractedTranslations):
|
||||||
extractedTranslations
|
|
||||||
):
|
|
||||||
mismatch = True # Just here for breakpoint
|
mismatch = True # Just here for breakpoint
|
||||||
logFile.write(f"Input:\n{subbedT}\n")
|
logFile.write(f"Input:\n{subbedT}\n")
|
||||||
logFile.write(f"Output:\n{translatedText}\n")
|
logFile.write(f"Output:\n{translatedText}\n")
|
||||||
|
|
@ -2463,9 +2383,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
# Set if no mismatch
|
# Set if no mismatch
|
||||||
if mismatch == False:
|
if mismatch == False:
|
||||||
tList[index] = extractedTranslations
|
tList[index] = extractedTranslations
|
||||||
history = extractedTranslations[
|
history = extractedTranslations[-MAXHISTORY:] # Update history if we have a list
|
||||||
-MAXHISTORY:
|
|
||||||
] # Update history if we have a list
|
|
||||||
else:
|
else:
|
||||||
history = text[-MAXHISTORY:]
|
history = text[-MAXHISTORY:]
|
||||||
mismatch = False
|
mismatch = False
|
||||||
|
|
|
||||||
|
|
@ -86,9 +86,7 @@ def handleWOLF2(filename, estimate):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
with open(
|
with open("translated/" + filename, "w", encoding="shift_jis", errors="ignore") as outFile:
|
||||||
"translated/" + filename, "w", encoding="shift_jis", errors="ignore"
|
|
||||||
) as outFile:
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
translatedData = openFiles(filename)
|
translatedData = openFiles(filename)
|
||||||
|
|
||||||
|
|
@ -112,19 +110,14 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]"
|
||||||
"[Output: "
|
"[Output: "
|
||||||
+ str(translatedData[1][1])
|
+ str(translatedData[1][1])
|
||||||
+ "]" "[Cost: ${:,.4f}".format(
|
+ "]" "[Cost: ${:,.4f}".format((translatedData[1][0] * 0.001 * INPUTAPICOST) + (translatedData[1][1] * 0.001 * OUTPUTAPICOST))
|
||||||
(translatedData[1][0] * 0.001 * INPUTAPICOST)
|
|
||||||
+ (translatedData[1][1] * 0.001 * OUTPUTAPICOST)
|
|
||||||
)
|
|
||||||
+ "]"
|
+ "]"
|
||||||
)
|
)
|
||||||
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]"
|
||||||
|
|
||||||
if translatedData[2] == None:
|
if translatedData[2] == None:
|
||||||
# Success
|
# Success
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
||||||
filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fail
|
# Fail
|
||||||
|
|
@ -133,16 +126,7 @@ def getResultString(translatedData, translationTime, filename):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
errorString = str(e) + Fore.RED
|
errorString = str(e) + Fore.RED
|
||||||
return (
|
return filename + ": " + totalTokenstring + timeString + Fore.RED + " \u2717 " + errorString + Fore.RESET
|
||||||
filename
|
|
||||||
+ ": "
|
|
||||||
+ totalTokenstring
|
|
||||||
+ timeString
|
|
||||||
+ Fore.RED
|
|
||||||
+ " \u2717 "
|
|
||||||
+ errorString
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def openFiles(filename):
|
def openFiles(filename):
|
||||||
|
|
@ -239,9 +223,7 @@ def translateWOLF(data, translatedList, pbar, filename):
|
||||||
# Grab Consecutive Strings
|
# Grab Consecutive Strings
|
||||||
currentGroup.append(data[i])
|
currentGroup.append(data[i])
|
||||||
i += 1
|
i += 1
|
||||||
while (
|
while i < len(data) and r"/" not in data[i] and "@" not in data[i] and data[i] != "\n":
|
||||||
i < len(data) and r"/" not in data[i] and "@" not in data[i] and data[i] != "\n"
|
|
||||||
):
|
|
||||||
currentGroup.append(data[i])
|
currentGroup.append(data[i])
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
|
@ -264,9 +246,7 @@ def translateWOLF(data, translatedList, pbar, filename):
|
||||||
# Pass 2
|
# Pass 2
|
||||||
else:
|
else:
|
||||||
# Insert Strings
|
# Insert Strings
|
||||||
while (
|
while i < len(data) and r"/" not in data[i] and "@" not in data[i] and data[i] != "\n":
|
||||||
i < len(data) and r"/" not in data[i] and "@" not in data[i] and data[i] != "\n"
|
|
||||||
):
|
|
||||||
data.pop(i)
|
data.pop(i)
|
||||||
|
|
||||||
# Get Text
|
# Get Text
|
||||||
|
|
@ -558,9 +538,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
translatedText = cleanTranslatedText(translatedText, varResponse)
|
translatedText = cleanTranslatedText(translatedText, varResponse)
|
||||||
if isinstance(tItem, list):
|
if isinstance(tItem, list):
|
||||||
extractedTranslations = extractTranslation(translatedText, True)
|
extractedTranslations = extractTranslation(translatedText, True)
|
||||||
if extractedTranslations == None or len(tItem) != len(
|
if extractedTranslations == None or len(tItem) != len(extractedTranslations):
|
||||||
extractedTranslations
|
|
||||||
):
|
|
||||||
mismatch = True # Just here for breakpoint
|
mismatch = True # Just here for breakpoint
|
||||||
logFile.write(f"Input:\n{subbedT}\n")
|
logFile.write(f"Input:\n{subbedT}\n")
|
||||||
logFile.write(f"Output:\n{translatedText}\n")
|
logFile.write(f"Output:\n{translatedText}\n")
|
||||||
|
|
@ -568,9 +546,7 @@ def translateGPT(text, history, fullPromptFlag):
|
||||||
# Set if no mismatch
|
# Set if no mismatch
|
||||||
if mismatch == False:
|
if mismatch == False:
|
||||||
tList[index] = extractedTranslations
|
tList[index] = extractedTranslations
|
||||||
history = extractedTranslations[
|
history = extractedTranslations[-MAXHISTORY:] # Update history if we have a list
|
||||||
-MAXHISTORY:
|
|
||||||
] # Update history if we have a list
|
|
||||||
else:
|
else:
|
||||||
history = text[-MAXHISTORY:]
|
history = text[-MAXHISTORY:]
|
||||||
mismatch = False
|
mismatch = False
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
line-length = 100
|
line-length = 150
|
||||||
Loading…
Reference in a new issue