Fix CSV T++ Estimate
This commit is contained in:
parent
0c772c51e6
commit
6499be8d8b
2 changed files with 27 additions and 27 deletions
|
|
@ -40,21 +40,11 @@ LEAVE=False
|
||||||
def handleCSV(filename, estimate):
|
def handleCSV(filename, estimate):
|
||||||
global ESTIMATE, TOKENS, TOTALTOKENS, TOTALCOST
|
global ESTIMATE, TOKENS, TOTALTOKENS, TOTALCOST
|
||||||
ESTIMATE = estimate
|
ESTIMATE = estimate
|
||||||
|
|
||||||
with open('translated/' + filename, 'w+t', newline='', encoding='utf-8') as writeFile:
|
with open('translated/' + filename, 'w+t', newline='', encoding='utf-8') as writeFile:
|
||||||
start = time.time()
|
start = time.time()
|
||||||
translatedData = openFiles(filename, writeFile)
|
translatedData = openFiles(filename, writeFile)
|
||||||
|
|
||||||
if estimate:
|
|
||||||
# Print Result
|
|
||||||
end = time.time()
|
|
||||||
tqdm.write(getResultString(['', TOKENS, None], end - start, filename))
|
|
||||||
TOTALCOST += TOKENS * .001 * APICOST
|
|
||||||
TOTALTOKENS += TOKENS
|
|
||||||
TOKENS = 0
|
|
||||||
os.remove('translated/' + filename)
|
|
||||||
|
|
||||||
else:
|
|
||||||
# Print Result
|
# Print Result
|
||||||
end = time.time()
|
end = time.time()
|
||||||
tqdm.write(getResultString(translatedData, end - start, filename))
|
tqdm.write(getResultString(translatedData, end - start, filename))
|
||||||
|
|
@ -220,6 +210,7 @@ def translateCSV(row, pbar, writer, textHistory, format):
|
||||||
pbar.update(1)
|
pbar.update(1)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
traceback.print_exc()
|
||||||
tracebackLineNo = str(traceback.extract_tb(sys.exc_info()[2])[-1].lineno)
|
tracebackLineNo = str(traceback.extract_tb(sys.exc_info()[2])[-1].lineno)
|
||||||
raise Exception(str(e) + '|Line:' + tracebackLineNo + '| Failed to translate: ' + text)
|
raise Exception(str(e) + '|Line:' + tracebackLineNo + '| Failed to translate: ' + text)
|
||||||
|
|
||||||
|
|
@ -321,13 +312,15 @@ def resubVars(translatedText, allList):
|
||||||
translatedText = translatedText.replace('<F' + str(count) + '>', var)
|
translatedText = translatedText.replace('<F' + str(count) + '>', var)
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
|
return translatedText
|
||||||
|
|
||||||
@retry(exceptions=Exception, tries=5, delay=5)
|
@retry(exceptions=Exception, tries=5, delay=5)
|
||||||
def translateGPT(t, history, fullPromptFlag):
|
def translateGPT(t, history, fullPromptFlag):
|
||||||
# If ESTIMATE is True just count this as an execution and return.
|
# If ESTIMATE is True just count this as an execution and return.
|
||||||
if ESTIMATE:
|
if ESTIMATE:
|
||||||
enc = tiktoken.encoding_for_model("gpt-3.5-turbo-0613")
|
enc = tiktoken.encoding_for_model("gpt-3.5-turbo")
|
||||||
TOKENS = len(enc.encode(t)) * 2 + len(enc.encode(history)) + len(enc.encode(PROMPT))
|
tokens = len(enc.encode(t)) * 2 + len(enc.encode(history)) + len(enc.encode(PROMPT))
|
||||||
return (t, 0)
|
return (t, tokens)
|
||||||
|
|
||||||
# Sub Vars
|
# Sub Vars
|
||||||
varResponse = subVars(t)
|
varResponse = subVars(t)
|
||||||
|
|
|
||||||
|
|
@ -675,6 +675,13 @@ def searchCodes(page, pbar):
|
||||||
# codeList[j]['parameters'][0] = nametag + finalJAString
|
# codeList[j]['parameters'][0] = nametag + finalJAString
|
||||||
# codeList[j]['code'] = code
|
# codeList[j]['code'] = code
|
||||||
|
|
||||||
|
# Special Effects
|
||||||
|
soundEffectString = ''
|
||||||
|
matchList = re.findall(r'(.+\\SE\[.+?\])', finalJAString)
|
||||||
|
if len(matchList) != 0:
|
||||||
|
soundEffectString = matchList[0]
|
||||||
|
finalJAString = finalJAString.replace(matchList[0], '')
|
||||||
|
|
||||||
# Remove any textwrap
|
# Remove any textwrap
|
||||||
if FIXTEXTWRAP == True:
|
if FIXTEXTWRAP == True:
|
||||||
finalJAString = re.sub(r'\n', ' ', finalJAString)
|
finalJAString = re.sub(r'\n', ' ', finalJAString)
|
||||||
|
|
@ -752,6 +759,7 @@ def searchCodes(page, pbar):
|
||||||
CLFlag = False
|
CLFlag = False
|
||||||
translatedText = nametag + translatedText
|
translatedText = nametag + translatedText
|
||||||
nametag = ''
|
nametag = ''
|
||||||
|
translatedText = soundEffectString + translatedText
|
||||||
|
|
||||||
# Set Data
|
# Set Data
|
||||||
translatedText = translatedText.replace('\"', '')
|
translatedText = translatedText.replace('\"', '')
|
||||||
|
|
@ -1598,7 +1606,7 @@ def subVars(jaString):
|
||||||
nameList = set(nameList)
|
nameList = set(nameList)
|
||||||
if len(nameList) != 0:
|
if len(nameList) != 0:
|
||||||
for name in nameList:
|
for name in nameList:
|
||||||
jaString = jaString.replace(name, '[Char_' + str(count) + ']')
|
jaString = jaString.replace(name, '[N_' + str(count) + ']')
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
|
|
@ -1651,7 +1659,7 @@ def resubVars(translatedText, allList):
|
||||||
count = 0
|
count = 0
|
||||||
if len(allList[2]) != 0:
|
if len(allList[2]) != 0:
|
||||||
for var in allList[2]:
|
for var in allList[2]:
|
||||||
translatedText = translatedText.replace('[Char_' + str(count) + ']', var)
|
translatedText = translatedText.replace('[N_' + str(count) + ']', var)
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
# Vars
|
# Vars
|
||||||
|
|
@ -1692,16 +1700,15 @@ def translateGPT(t, history, fullPromptFlag):
|
||||||
|
|
||||||
"""Translate text using GPT"""
|
"""Translate text using GPT"""
|
||||||
context = '```\
|
context = '```\
|
||||||
Character Names Context:\
|
Game Characters:\
|
||||||
Character: クノ == Kuno - Gender: Female\
|
Character: 如月亜里愛 == Kisaragi Aria - Nickname: Aria - Gender: Female\
|
||||||
Character: ノンナ == Nonna - Gender: Female\
|
Character: 愛洲美彌子 == Aisu Miyako - Gender: Female\
|
||||||
Character: フロス == Fross - Gender: Female\
|
Character: 喜遊名心 == Cocoa Kiyuna - Gender: Female\
|
||||||
Character: シア == Shia - Gender: Female\
|
Character: 柵瀬愛色 == Ai Sakurai - Gender: Female\
|
||||||
Character: ウカ == Uka - Gender: Female\
|
Character: 陰平小鞠 == Komari Kagehira - Gender: Female\
|
||||||
Character: プラエ == Prae - Gender: Female\
|
Character: 訓覇一縷 == Ichiru Kurube - Gender: Female\
|
||||||
Character: サナ == Sana - Gender: Female\
|
Character: 緋皇月 == Luna Hisube - Gender: Female\
|
||||||
Character: サリア == Saria - Gender: Female\
|
Character: 刑事 == Detective - Gender: Male\
|
||||||
Character: 太郎 == Taro - Gender: Male\
|
|
||||||
```'
|
```'
|
||||||
|
|
||||||
if fullPromptFlag:
|
if fullPromptFlag:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue