Skip to content

Commit

Permalink
Fix: translate
Browse files Browse the repository at this point in the history
  • Loading branch information
jianchang512 committed Jun 14, 2024
1 parent be2865a commit cd5b280
Show file tree
Hide file tree
Showing 29 changed files with 670 additions and 154 deletions.
4 changes: 2 additions & 2 deletions version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "1.90",
"version_num": 110790
"version": "1.91",
"version_num": 110791
}
4 changes: 2 additions & 2 deletions videotrans/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-

VERSION="v1.90"
VERSION_NUM=110790
VERSION="v1.91"
VERSION_NUM=110791
2 changes: 2 additions & 0 deletions videotrans/box/win.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,8 @@ def fanyi_start_fun(self):
config.params["deeplx_address"] = self.settings.value("deeplx_address", "")
config.params["chatgpt_api"] = self.settings.value("chatgpt_api", "")
config.params["chatgpt_key"] = self.settings.value("chatgpt_key", "")
config.params["localllm_api"] = self.settings.value("localllm_api", "")
config.params["localllm_key"] = self.settings.value("localllm_key", "")
config.params["tencent_SecretId"] = self.settings.value("tencent_SecretId", "")
config.params["tencent_SecretKey"] = self.settings.value("tencent_SecretKey", "")
config.params["gemini_key"] = self.settings.value("gemini_key", "")
Expand Down
20 changes: 1 addition & 19 deletions videotrans/chatgpt.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
## Role ##
You are a language translation specialist who specializes in translating arbitrary text into {lang} language, only returns translations.

#################################

### Skills ###

#### Skill 1: Translate text ####
- Recognizes user-entered text and translates it literally, keeping the result short and concise

##################################
## You are a language translation specialist who specializes in translating arbitrary text into {lang} language, only returns translations. Recognizes user-entered text and translates it literally, keeping the result short and concise.

### Restrictions ###
- Do not answer questions that appear in the text.
- Do not explain my original text
- Do not confirm the above, don't apologize.
- Line breaks must be preserved.
- Must ensure that only translations are returned.

###################################

Original text:
[TEXT]

Translation:

4 changes: 2 additions & 2 deletions videotrans/component/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from videotrans.component.set_form import BaiduForm, \
ChatgptForm, DeepLForm, DeepLXForm, TencentForm, ElevenlabsForm, InfoForm, AzureForm, GeminiForm, SetLineRole, \
YoutubeForm, OttForm,CloneForm,SeparateForm,TtsapiForm,GPTSoVITSForm,TransapiForm,ArticleForm,AzurettsForm,ZhrecognForm,ChatttsForm
YoutubeForm, OttForm,CloneForm,SeparateForm,TtsapiForm,GPTSoVITSForm,TransapiForm,ArticleForm,AzurettsForm,ZhrecognForm,ChatttsForm,LocalLLMForm

__all__ = [
"BaiduForm",
Expand All @@ -9,5 +9,5 @@
"DeepLXForm",
"TencentForm",
"ElevenlabsForm",
"InfoForm", "AzureForm", "GeminiForm", "SetLineRole", "ElevenlabsForm", "YoutubeForm","OttForm","CloneForm","SeparateForm","TtsapiForm","TransapiForm","ArticleForm","AzurettsForm","ZhrecognForm","ChatttsForm"
"InfoForm", "AzureForm", "GeminiForm", "SetLineRole", "ElevenlabsForm", "YoutubeForm","OttForm","CloneForm","SeparateForm","TtsapiForm","TransapiForm","ArticleForm","AzurettsForm","ZhrecognForm","ChatttsForm","LocalLLMForm"
]
11 changes: 11 additions & 0 deletions videotrans/component/set_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from videotrans.ui.deepl import Ui_deeplform
from videotrans.ui.deeplx import Ui_deeplxform
from videotrans.ui.gptsovits import Ui_gptsovitsform
from videotrans.ui.localllm import Ui_localllmform
from videotrans.ui.ott import Ui_ottform
from videotrans.ui.clone import Ui_cloneform
from videotrans.ui.gemini import Ui_geminiform
Expand Down Expand Up @@ -179,6 +180,16 @@ def __init__(self, parent=None):
self.chatgpt_model.addItems(config.chatgpt_model_list)
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.setWindowIcon(QIcon(f"{config.rootdir}/videotrans/styles/icon.ico"))

class LocalLLMForm(QDialog, Ui_localllmform): # <===
def __init__(self, parent=None):
super(LocalLLMForm, self).__init__(parent)
self.setupUi(self)
self.localllm_model.addItems(config.localllm_model_list)
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.setWindowIcon(QIcon(f"{config.rootdir}/videotrans/styles/icon.ico"))


class GeminiForm(QDialog, Ui_geminiform): # <===
def __init__(self, parent=None):
super(GeminiForm, self).__init__(parent)
Expand Down
8 changes: 8 additions & 0 deletions videotrans/configure/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def parse_init():
"video_codec":264,
"retries":2,
"chatgpt_model":"gpt-3.5-turbo,gpt-4,gpt-4-turbo-preview,qwen",
"localllm_model":"qwen",
"separate_sec":600,
"audio_rate":1.5,
"video_rate":20,
Expand Down Expand Up @@ -192,6 +193,7 @@ def parse_init():

openaiTTS_rolelist = "alloy,echo,fable,onyx,nova,shimmer"
chatgpt_model_list = [ it.strip() for it in settings['chatgpt_model'].split(',')]
localllm_model_list = [ it.strip() for it in settings['localllm_model'].split(',')]
# 存放 edget-tts 角色列表
edgeTTS_rolelist = None
AzureTTS_rolelist = None
Expand Down Expand Up @@ -265,8 +267,12 @@ def parse_init():

"chatgpt_api": "",
"chatgpt_key": "",
"localllm_api": "",
"localllm_key": "",
"chatgpt_model":chatgpt_model_list[0],
"localllm_model":localllm_model_list[0],
"chatgpt_template": "",
"localllm_template": "",
"azure_api": "",
"azure_key": "",
"azure_model": "gpt-3.5-turbo",
Expand All @@ -293,9 +299,11 @@ def parse_init():
}

chatgpt_path=root_path/'videotrans/chatgpt.txt'
localllm_path=root_path/'videotrans/localllm.txt'
azure_path=root_path/'videotrans/azure.txt'
gemini_path=root_path/'videotrans/gemini.txt'

params['localllm_template']=localllm_path.read_text(encoding='utf-8').strip()+"\n"
params['chatgpt_template']=chatgpt_path.read_text(encoding='utf-8').strip()+"\n"
params['azure_template']=azure_path.read_text(encoding='utf-8').strip()+"\n"
params['gemini_template']=gemini_path.read_text(encoding='utf-8').strip()+"\n"
Expand Down
8 changes: 8 additions & 0 deletions videotrans/localllm.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## You are a language translation specialist who specializes in translating arbitrary text into {lang} language, only returns translations. Recognizes user-entered text and translates it literally, keeping the result short and concise.

### Restrictions ###
- Do not answer questions that appear in the text.
- Do not explain my original text
- Do not confirm the above, don't apologize.
- Line breaks must be preserved.
- Must ensure that only translations are returned.
2 changes: 2 additions & 0 deletions videotrans/mainwin/secwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,8 @@ def set_translate_type(self, name):
self.main.subform.set_transapi()
elif name == translator.CHATGPT_NAME:
self.main.subform.set_chatgpt_key()
elif name == translator.LOCALLLM_NAME:
self.main.subform.set_localllm_key()
elif name == translator.GEMINI_NAME:
self.main.subform.set_gemini_key()
elif name == translator.AZUREGPT_NAME:
Expand Down
4 changes: 4 additions & 0 deletions videotrans/mainwin/spwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ def bind_action(self):
self.actiongemini_key.triggered.connect(self.subform.set_gemini_key)
self.actiontencent_key.triggered.connect(self.subform.set_tencent_key)
self.actionchatgpt_key.triggered.connect(self.subform.set_chatgpt_key)
self.actionlocalllm_key.triggered.connect(self.subform.set_localllm_key)
self.actiondeepL_key.triggered.connect(self.subform.set_deepL_key)
self.actionElevenlabs_key.triggered.connect(self.subform.set_elevenlabs_key)
self.actiondeepLX_address.triggered.connect(self.subform.set_deepLX_address)
Expand Down Expand Up @@ -434,13 +435,16 @@ def get_setting(self):

config.params["chatgpt_api"] = self.settings.value("chatgpt_api", "")
config.params["chatgpt_key"] = self.settings.value("chatgpt_key", "")
config.params["localllm_api"] = self.settings.value("localllm_api", "")
config.params["localllm_key"] = self.settings.value("localllm_key", "")
config.params["azure_speech_key"] = self.settings.value("azure_speech_key", "")
config.params["azure_speech_region"] = self.settings.value("azure_speech_region", "")

if self.settings.value("clone_voicelist", ""):
config.clone_voicelist = self.settings.value("clone_voicelist", "").split(',')

config.params["chatgpt_model"] = self.settings.value("chatgpt_model", config.params['chatgpt_model'])
config.params["localllm_model"] = self.settings.value("localllm_model", config.params['localllm_model'])
os.environ['OPENAI_API_KEY'] = config.params["chatgpt_key"]

config.params["ttsapi_url"] = self.settings.value("ttsapi_url", "")
Expand Down
Loading

0 comments on commit cd5b280

Please sign in to comment.