check_new_version
This commit is contained in:
parent
effa1421b4
commit
b87bfeaddb
@ -19,6 +19,30 @@ def check_proxy(proxies):
|
||||
return result
|
||||
|
||||
|
||||
def auto_update():
|
||||
from toolbox import get_conf
|
||||
import requests, time, json
|
||||
proxies, = get_conf('proxies')
|
||||
response = requests.get("https://raw.githubusercontent.com/binary-husky/chatgpt_academic/master/version",
|
||||
proxies=proxies, timeout=1)
|
||||
remote_json_data = json.loads(response.text)
|
||||
remote_version = remote_json_data['version']
|
||||
if remote_json_data["show_feature"]:
|
||||
new_feature = "新功能:" + remote_json_data["new_feature"]
|
||||
else:
|
||||
new_feature = ""
|
||||
with open('./version', 'r', encoding='utf8') as f:
|
||||
current_version = f.read()
|
||||
current_version = json.loads(current_version)['version']
|
||||
if (remote_version - current_version) >= 0.05:
|
||||
print(f'\n新版本可用。新版本:{remote_version},当前版本:{current_version}。{new_feature}')
|
||||
print('Github更新地址:\nhttps://github.com/binary-husky/chatgpt_academic\n')
|
||||
time.sleep(3)
|
||||
return
|
||||
else:
|
||||
return
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染
|
||||
from toolbox import get_conf
|
||||
|
10
main.py
10
main.py
@ -37,6 +37,11 @@ gr.Chatbot.postprocess = format_io
|
||||
from theme import adjust_theme, advanced_css
|
||||
set_theme = adjust_theme()
|
||||
|
||||
# 代理与自动更新
|
||||
from check_proxy import check_proxy, auto_update
|
||||
proxy_info = check_proxy(proxies)
|
||||
|
||||
|
||||
cancel_handles = []
|
||||
with gr.Blocks(theme=set_theme, analytics_enabled=False, css=advanced_css) as demo:
|
||||
gr.HTML(title_html)
|
||||
@ -54,8 +59,7 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False, css=advanced_css) as de
|
||||
resetBtn = gr.Button("重置", variant="secondary"); resetBtn.style(size="sm")
|
||||
stopBtn = gr.Button("停止", variant="secondary"); stopBtn.style(size="sm")
|
||||
with gr.Row():
|
||||
from check_proxy import check_proxy
|
||||
status = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行。当前模型: {LLM_MODEL} \n {check_proxy(proxies)}")
|
||||
status = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行。当前模型: {LLM_MODEL} \n {proxy_info}")
|
||||
with gr.Accordion("基础功能区", open=True) as area_basic_fn:
|
||||
with gr.Row():
|
||||
for k in functional:
|
||||
@ -139,6 +143,8 @@ def auto_opentab_delay():
|
||||
print(f"\t(暗色主体): http://localhost:{PORT}/?__dark-theme=true")
|
||||
def open():
|
||||
time.sleep(2)
|
||||
try: auto_update() # 检查新版本
|
||||
except: pass
|
||||
webbrowser.open_new_tab(f"http://localhost:{PORT}/?__dark-theme=true")
|
||||
threading.Thread(target=open, name="open-browser", daemon=True).start()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user