qingxu99 commited on
Commit
b87bfea
1 Parent(s): effa142

check_new_version

Browse files
Files changed (2) hide show
  1. check_proxy.py +24 -0
  2. main.py +8 -2
check_proxy.py CHANGED
@@ -19,6 +19,30 @@ def check_proxy(proxies):
19
  return result
20
 
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  if __name__ == '__main__':
23
  import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染
24
  from toolbox import get_conf
 
19
  return result
20
 
21
 
22
+ def auto_update():
23
+ from toolbox import get_conf
24
+ import requests, time, json
25
+ proxies, = get_conf('proxies')
26
+ response = requests.get("https://raw.githubusercontent.com/binary-husky/chatgpt_academic/master/version",
27
+ proxies=proxies, timeout=1)
28
+ remote_json_data = json.loads(response.text)
29
+ remote_version = remote_json_data['version']
30
+ if remote_json_data["show_feature"]:
31
+ new_feature = "新功能:" + remote_json_data["new_feature"]
32
+ else:
33
+ new_feature = ""
34
+ with open('./version', 'r', encoding='utf8') as f:
35
+ current_version = f.read()
36
+ current_version = json.loads(current_version)['version']
37
+ if (remote_version - current_version) >= 0.05:
38
+ print(f'\n新版本可用。新版本:{remote_version},当前版本:{current_version}。{new_feature}')
39
+ print('Github更新地址:\nhttps://github.com/binary-husky/chatgpt_academic\n')
40
+ time.sleep(3)
41
+ return
42
+ else:
43
+ return
44
+
45
+
46
  if __name__ == '__main__':
47
  import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染
48
  from toolbox import get_conf
main.py CHANGED
@@ -37,6 +37,11 @@ gr.Chatbot.postprocess = format_io
37
  from theme import adjust_theme, advanced_css
38
  set_theme = adjust_theme()
39
 
 
 
 
 
 
40
  cancel_handles = []
41
  with gr.Blocks(theme=set_theme, analytics_enabled=False, css=advanced_css) as demo:
42
  gr.HTML(title_html)
@@ -54,8 +59,7 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False, css=advanced_css) as de
54
  resetBtn = gr.Button("重置", variant="secondary"); resetBtn.style(size="sm")
55
  stopBtn = gr.Button("停止", variant="secondary"); stopBtn.style(size="sm")
56
  with gr.Row():
57
- from check_proxy import check_proxy
58
- status = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行。当前模型: {LLM_MODEL} \n {check_proxy(proxies)}")
59
  with gr.Accordion("基础功能区", open=True) as area_basic_fn:
60
  with gr.Row():
61
  for k in functional:
@@ -139,6 +143,8 @@ def auto_opentab_delay():
139
  print(f"\t(暗色主体): http://localhost:{PORT}/?__dark-theme=true")
140
  def open():
141
  time.sleep(2)
 
 
142
  webbrowser.open_new_tab(f"http://localhost:{PORT}/?__dark-theme=true")
143
  threading.Thread(target=open, name="open-browser", daemon=True).start()
144
 
 
37
  from theme import adjust_theme, advanced_css
38
  set_theme = adjust_theme()
39
 
40
+ # 代理与自动更新
41
+ from check_proxy import check_proxy, auto_update
42
+ proxy_info = check_proxy(proxies)
43
+
44
+
45
  cancel_handles = []
46
  with gr.Blocks(theme=set_theme, analytics_enabled=False, css=advanced_css) as demo:
47
  gr.HTML(title_html)
 
59
  resetBtn = gr.Button("重置", variant="secondary"); resetBtn.style(size="sm")
60
  stopBtn = gr.Button("停止", variant="secondary"); stopBtn.style(size="sm")
61
  with gr.Row():
62
+ status = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行。当前模型: {LLM_MODEL} \n {proxy_info}")
 
63
  with gr.Accordion("基础功能区", open=True) as area_basic_fn:
64
  with gr.Row():
65
  for k in functional:
 
143
  print(f"\t(暗色主体): http://localhost:{PORT}/?__dark-theme=true")
144
  def open():
145
  time.sleep(2)
146
+ try: auto_update() # 检查新版本
147
+ except: pass
148
  webbrowser.open_new_tab(f"http://localhost:{PORT}/?__dark-theme=true")
149
  threading.Thread(target=open, name="open-browser", daemon=True).start()
150