Skip to content

Commit

Permalink
fix: bugs and update
Browse files Browse the repository at this point in the history
  • Loading branch information
jianchang512 committed May 18, 2024
1 parent 1a23daf commit 615f488
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 19 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.77",
"version_num": 11077
"version": "1.78",
"version_num": 11078
}
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.77"
VERSION_NUM=110707
VERSION="v1.78"
VERSION_NUM=110708
3 changes: 3 additions & 0 deletions videotrans/mainwin/secwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,'免责声明',"""
免责声明:
Expand Down
1 change: 1 addition & 0 deletions videotrans/mainwin/spwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions videotrans/mainwin/subform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
19 changes: 12 additions & 7 deletions videotrans/translator/chatgpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions videotrans/translator/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion videotrans/translator/ott.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
16 changes: 10 additions & 6 deletions videotrans/tts/openaitts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion videotrans/ui/ttsapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 615f488

Please sign in to comment.