Keldos commited on
Commit
6b4e8ea
1 Parent(s): 80b54e5

[WIP] feat: 自动更新

Browse files
ChuanhuChatbot.py CHANGED
@@ -282,6 +282,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
282
  )
283
  changeProxyBtn = gr.Button(i18n("🔄 设置代理地址"))
284
  default_btn = gr.Button(i18n("🔙 恢复默认设置"))
 
285
 
286
  gr.Markdown(CHUANHU_DESCRIPTION, elem_id="description")
287
  gr.HTML(get_html("footer.html").format(versions=versions_html()), elem_id="footer")
@@ -483,6 +484,14 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
483
  )
484
  checkUpdateBtn.click(fn=None, _js='()=>{manualCheckUpdate();}')
485
 
 
 
 
 
 
 
 
 
486
  logging.info(
487
  colorama.Back.GREEN
488
  + "\n川虎的温馨提示:访问 http://localhost:7860 查看界面"
 
282
  )
283
  changeProxyBtn = gr.Button(i18n("🔄 设置代理地址"))
284
  default_btn = gr.Button(i18n("🔙 恢复默认设置"))
285
+ updateChuanhuBtn = gr.Button(visible=False, elem_classes="invisible_btn", elem_id="update_chuanhu_btn")
286
 
287
  gr.Markdown(CHUANHU_DESCRIPTION, elem_id="description")
288
  gr.HTML(get_html("footer.html").format(versions=versions_html()), elem_id="footer")
 
484
  )
485
  checkUpdateBtn.click(fn=None, _js='()=>{manualCheckUpdate();}')
486
 
487
+ # Invisible elements
488
+ updateChuanhuBtn.click(
489
+ update_chuanhu,
490
+ [],
491
+ [status_display],
492
+ show_progress=True,
493
+ )
494
+
495
  logging.info(
496
  colorama.Back.GREEN
497
  + "\n川虎的温馨提示:访问 http://localhost:7860 查看界面"
assets/custom.js CHANGED
@@ -22,6 +22,7 @@ var updateToast = null;
22
  var sendBtn = null;
23
  var cancelBtn = null;
24
  var sliders = null;
 
25
 
26
  var userLogged = false;
27
  var usernameGotten = false;
@@ -87,6 +88,7 @@ function gradioLoaded(mutations) {
87
  sendBtn = document.getElementById("submit_btn");
88
  cancelBtn = document.getElementById("cancel_btn");
89
  sliders = document.querySelectorAll('input[type="range"]');
 
90
 
91
  if (loginUserForm) {
92
  localStorage.setItem("userLogged", true);
 
22
  var sendBtn = null;
23
  var cancelBtn = null;
24
  var sliders = null;
25
+ var updateChuanhuBtn = null;
26
 
27
  var userLogged = false;
28
  var usernameGotten = false;
 
88
  sendBtn = document.getElementById("submit_btn");
89
  cancelBtn = document.getElementById("cancel_btn");
90
  sliders = document.querySelectorAll('input[type="range"]');
91
+ updateChuanhuBtn = document.getElementById("update_chuanhu_btn");
92
 
93
  if (loginUserForm) {
94
  localStorage.setItem("userLogged", true);
assets/html/update.html CHANGED
@@ -15,7 +15,7 @@
15
  </div>
16
  <div id="goto-update-btn" class="btn-update-group">
17
  <button class="btn-update lg secondary svelte-1ipelgc" id="cancel-button" onclick="cancelUpdate()">{cancel_btn}</button>
18
- <button class="btn-update lg primary svelte-1ipelgc" id="update-button" onclick="getUpdate()">{update_btn}</button>
19
  </div>
20
  <div id="close-update-btn" class="btn-update-group hideK">
21
  <button class="btn-update lg secondary svelte-1jrzxu" id="update-button" onclick="getUpdate()">{seenew_btn}</button>
 
15
  </div>
16
  <div id="goto-update-btn" class="btn-update-group">
17
  <button class="btn-update lg secondary svelte-1ipelgc" id="cancel-button" onclick="cancelUpdate()">{cancel_btn}</button>
18
+ <button class="btn-update lg primary svelte-1ipelgc" id="update-button" onclick="getUpdate(); updateChuanhuBtn.click();">{update_btn}</button>
19
  </div>
20
  <div id="close-update-btn" class="btn-update-group hideK">
21
  <button class="btn-update lg secondary svelte-1jrzxu" id="update-button" onclick="getUpdate()">{seenew_btn}</button>
modules/utils.py CHANGED
@@ -590,6 +590,16 @@ def version_time():
590
  commit_time = "unknown"
591
  return commit_time
592
 
 
 
 
 
 
 
 
 
 
 
593
  def get_html(filename):
594
  path = os.path.join(shared.chuanhu_path, "assets", "html", filename)
595
  if os.path.exists(path):
 
590
  commit_time = "unknown"
591
  return commit_time
592
 
593
+ def update_chuanhu():
594
+ git = os.environ.get('GIT', "git")
595
+ try:
596
+ run(f"{git} fetch --all && {git} stash && {git} pull https://github.com/GaiZhenbiao/ChuanhuChatGPT.git main -f && {git} stash pop")
597
+ logging.info("更新成功,重启中……")
598
+ return gr.Markdown.update(value="更新成功,重启中……")
599
+ except Exception:
600
+ logging.info("更新失败")
601
+ return gr.Markdown.update(value="更新失败")
602
+
603
  def get_html(filename):
604
  path = os.path.join(shared.chuanhu_path, "assets", "html", filename)
605
  if os.path.exists(path):