diff --git a/check_proxy.py b/check_proxy.py index a6919dd..abc75d0 100644 --- a/check_proxy.py +++ b/check_proxy.py @@ -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 diff --git a/main.py b/main.py index 973d16f..48ea670 100644 --- a/main.py +++ b/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()