From 615f4885f30e86cc67f5f552e3a7f30c0ec29396 Mon Sep 17 00:00:00 2001 From: jameson512 <2867557054@qq.com> Date: Sat, 18 May 2024 17:47:07 +0800 Subject: [PATCH] fix: bugs and update --- version.json | 4 ++-- videotrans/__init__.py | 4 ++-- videotrans/mainwin/secwin.py | 3 +++ videotrans/mainwin/spwin.py | 1 + videotrans/mainwin/subform.py | 2 ++ videotrans/translator/chatgpt.py | 19 ++++++++++++------- videotrans/translator/gemini.py | 1 + videotrans/translator/ott.py | 2 +- videotrans/tts/openaitts.py | 16 ++++++++++------ videotrans/ui/ttsapi.py | 3 ++- 10 files changed, 36 insertions(+), 19 deletions(-) diff --git a/version.json b/version.json index 1684b1f5..eaf4a043 100644 --- a/version.json +++ b/version.json @@ -1,4 +1,4 @@ { - "version": "1.77", - "version_num": 11077 + "version": "1.78", + "version_num": 11078 } diff --git a/videotrans/__init__.py b/videotrans/__init__.py index 63614ded..b1549f78 100644 --- a/videotrans/__init__.py +++ b/videotrans/__init__.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- -VERSION="v1.77" -VERSION_NUM=110707 \ No newline at end of file +VERSION="v1.78" +VERSION_NUM=110708 \ No newline at end of file diff --git a/videotrans/mainwin/secwin.py b/videotrans/mainwin/secwin.py index ee5806d6..a3541069 100644 --- a/videotrans/mainwin/secwin.py +++ b/videotrans/mainwin/secwin.py @@ -572,6 +572,9 @@ def open_url(self, title): webbrowser.open_new_tab("https://github.com/jianchang512/pyvideotrans/blob/main/about.md") elif title == 'download': webbrowser.open_new_tab("https://github.com/jianchang512/pyvideotrans/releases") + elif title=='openvoice': + webbrowser.open_new_tab("https://github.com/kungful/openvoice-api") + elif title == 'online': QMessageBox.information(self.main,'免责声明',""" 免责声明: diff --git a/videotrans/mainwin/spwin.py b/videotrans/mainwin/spwin.py index a50ff0a9..66ceac41 100644 --- a/videotrans/mainwin/spwin.py +++ b/videotrans/mainwin/spwin.py @@ -307,6 +307,7 @@ def bind_action(self): self.action_blog.triggered.connect(lambda: self.util.open_url('blog')) self.statusLabel.clicked.connect(lambda: self.util.open_url('help')) self.action_issue.triggered.connect(lambda: self.util.open_url('issue')) + self.action_tool.triggered.connect(lambda: self.util.open_toolbox(0, False)) self.actionyoutube.triggered.connect(self.subform.open_youtube) self.actionsepar.triggered.connect(self.subform.open_separate) diff --git a/videotrans/mainwin/subform.py b/videotrans/mainwin/subform.py index a2178a9e..50266d96 100644 --- a/videotrans/mainwin/subform.py +++ b/videotrans/mainwin/subform.py @@ -516,6 +516,8 @@ def save(): self.main.ttsapiw.save.clicked.connect(save) self.main.ttsapiw.test.clicked.connect(test) + self.main.ttsapiw.otherlink.clicked.connect(lambda: self.main.util.open_url('openvoice')) + self.main.ttsapiw.otherlink.setCursor(Qt.PointingHandCursor) self.main.ttsapiw.show() def set_transapi(self): diff --git a/videotrans/translator/chatgpt.py b/videotrans/translator/chatgpt.py index 3db17d42..241e8f4d 100644 --- a/videotrans/translator/chatgpt.py +++ b/videotrans/translator/chatgpt.py @@ -9,14 +9,18 @@ from videotrans.util import tools def get_url(url=""): + + if not url.startswith('http'): + url='http://'+url + # 删除末尾 / + url=url.rstrip('/').lower() if not url or url.find(".openai.com")>-1: return "https://api.openai.com/v1" - url=url.rstrip('/').lower() - if not url.startswith('http'): - url='http://'+url - if re.match(r'.*/v1/(chat/)?completions/?$',url): - return re.sub(r'/v1/.*$','/v1',url) - if re.match(r'^https?://[^/]+?$',url): + # 存在 /v1/xx的,改为 /v1 + if re.match(r'.*/v1/(chat)?(/?completions)?$',url): + return re.sub(r'/v1.*$','/v1',url) + # 不是/v1结尾的改为 /v1 + if url.find('/v1')==-1: return url+"/v1" return url @@ -42,7 +46,8 @@ def create_openai_client(): api_url = get_url(config.params['chatgpt_api']) openai.base_url = api_url config.logger.info(f'当前chatGPT:{api_url=}') - update_proxy(type='set') + if not re.search('localhost',api_url) and not re.match(r'^https?://(\d+\.){3}\d+(:\d+)?',api_url): + update_proxy(type='set') try: client = OpenAI(base_url=api_url,http_client=httpx.Client()) except Exception as e: diff --git a/videotrans/translator/gemini.py b/videotrans/translator/gemini.py index be3b2a4f..3b431c81 100644 --- a/videotrans/translator/gemini.py +++ b/videotrans/translator/gemini.py @@ -73,6 +73,7 @@ def get_error(num=5, type='error'): def get_content(d,*,model=None,prompt=None): update_proxy(type='set') + response=None try: message=prompt.replace('{text}',"\n".join(d)) response = model.generate_content( diff --git a/videotrans/translator/ott.py b/videotrans/translator/ott.py index cc9ceb66..d70d07f7 100644 --- a/videotrans/translator/ott.py +++ b/videotrans/translator/ott.py @@ -36,7 +36,7 @@ def trans(text_list, target_language="en", *, set_p=True,inst=None,stop=0,source url=url.replace('//translate','/translate') if not url.startswith('http'): url=f"http://{url}" - if re.search(r'localhost',url) or re.match(r'https?://(\d+\.){3}\d+',url): + if not re.search(r'localhost',url) and not re.match(r'https?://(\d+\.){3}\d+',url): update_proxy(type='set') # 翻译后的文本 target_text = [] diff --git a/videotrans/tts/openaitts.py b/videotrans/tts/openaitts.py index 1a09d337..bba573ae 100644 --- a/videotrans/tts/openaitts.py +++ b/videotrans/tts/openaitts.py @@ -29,14 +29,18 @@ def update_proxy(type='set'): def get_url(url=""): + + if not url.startswith('http'): + url='http://'+url + # 删除末尾 / + url=url.rstrip('/').lower() if not url or url.find(".openai.com")>-1: return "https://api.openai.com/v1" - url=url.rstrip('/').lower() - if not url.startswith('http'): - url='http://'+url - if re.match(r'.*/v1/(chat/)?completions/?$',url): - return re.sub(r'/v1/.*$','/v1',url) - if re.match(r'^https?://[^/]+?$',url): + # 存在 /v1/xx的,改为 /v1 + if re.match(r'.*/v1/(chat)?(/?completions)?$',url): + return re.sub(r'/v1.*$','/v1',url) + # 不是/v1结尾的改为 /v1 + if url.find('/v1')==-1: return url+"/v1" return url diff --git a/videotrans/ui/ttsapi.py b/videotrans/ui/ttsapi.py index 89667572..51678200 100644 --- a/videotrans/ui/ttsapi.py +++ b/videotrans/ui/ttsapi.py @@ -61,7 +61,8 @@ def setupUi(self, ttsapiform): self.test.setGeometry(QRect(490, 350, 93, 35)) self.test.setMinimumSize(QSize(0, 35)) - self.otherlink=QLabel() + self.otherlink=QPushButton(ttsapiform) + self.otherlink.setStyleSheet("""background-color:transparent;border:0;""") self.otherlink.setText("第三方实现OpenVoice接口 https://github.com/kungful/openvoice-api") self.otherlink.setGeometry(QRect(10,400,400,35))