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