Keldos commited on
Commit
9f551dd
1 Parent(s): 5817e2c

feat: 在页脚加入环境版本信息 (#439)

Browse files

* feat: 在页脚加入环境版本信息

- 去掉了build with gradio信息(/ω\)
- 借鉴了stable-diffusion-webui

* chore: 当没有git信息时显示unkown

Files changed (4) hide show
  1. ChuanhuChatbot.py +1 -1
  2. assets/custom.css +15 -0
  3. modules/presets.py +4 -0
  4. modules/utils.py +44 -0
ChuanhuChatbot.py CHANGED
@@ -227,7 +227,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
227
  changeProxyBtn = gr.Button("🔄 设置代理地址")
228
 
229
  gr.Markdown(description)
230
-
231
  chatgpt_predict_args = dict(
232
  fn=predict,
233
  inputs=[
 
227
  changeProxyBtn = gr.Button("🔄 设置代理地址")
228
 
229
  gr.Markdown(description)
230
+ gr.HTML(footer.format(versions=versions_html()), elem_id="footer")
231
  chatgpt_predict_args = dict(
232
  fn=predict,
233
  inputs=[
assets/custom.css CHANGED
@@ -3,6 +3,21 @@
3
  --chatbot-color-dark: #121111;
4
  }
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  /* status_display */
7
  #status_display {
8
  display: flex;
 
3
  --chatbot-color-dark: #121111;
4
  }
5
 
6
+ /* 覆盖gradio的页脚信息QAQ */
7
+ footer {
8
+ display: none !important;
9
+ }
10
+ #footer{
11
+ text-align: center;
12
+ }
13
+ #footer div{
14
+ display: inline-block;
15
+ }
16
+ #footer .versions{
17
+ font-size: 85%;
18
+ opacity: 0.85;
19
+ }
20
+
21
  /* status_display */
22
  #status_display {
23
  display: flex;
modules/presets.py CHANGED
@@ -41,6 +41,10 @@ description = """\
41
  </div>
42
  """
43
 
 
 
 
 
44
  summarize_prompt = "你是谁?我们刚才聊了什么?" # 总结对话时的 prompt
45
 
46
  MODELS = [
 
41
  </div>
42
  """
43
 
44
+ footer = """\
45
+ <div class="versions">{versions}</div>
46
+ """
47
+
48
  summarize_prompt = "你是谁?我们刚才聊了什么?" # 总结对话时的 prompt
49
 
50
  MODELS = [
modules/utils.py CHANGED
@@ -10,6 +10,8 @@ import csv
10
  import requests
11
  import re
12
  import html
 
 
13
 
14
  import gradio as gr
15
  from pypinyin import lazy_pinyin
@@ -457,3 +459,45 @@ def get_proxies():
457
  proxies = None
458
 
459
  return proxies
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  import requests
11
  import re
12
  import html
13
+ import sys
14
+ import subprocess
15
 
16
  import gradio as gr
17
  from pypinyin import lazy_pinyin
 
459
  proxies = None
460
 
461
  return proxies
462
+
463
+ def run(command, desc=None, errdesc=None, custom_env=None, live=False):
464
+ if desc is not None:
465
+ print(desc)
466
+ if live:
467
+ result = subprocess.run(command, shell=True, env=os.environ if custom_env is None else custom_env)
468
+ if result.returncode != 0:
469
+ raise RuntimeError(f"""{errdesc or 'Error running command'}.
470
+ Command: {command}
471
+ Error code: {result.returncode}""")
472
+
473
+ return ""
474
+ result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=os.environ if custom_env is None else custom_env)
475
+ if result.returncode != 0:
476
+ message = f"""{errdesc or 'Error running command'}.
477
+ Command: {command}
478
+ Error code: {result.returncode}
479
+ stdout: {result.stdout.decode(encoding="utf8", errors="ignore") if len(result.stdout)>0 else '<empty>'}
480
+ stderr: {result.stderr.decode(encoding="utf8", errors="ignore") if len(result.stderr)>0 else '<empty>'}
481
+ """
482
+ raise RuntimeError(message)
483
+ return result.stdout.decode(encoding="utf8", errors="ignore")
484
+
485
+ def versions_html():
486
+ git = os.environ.get('GIT', "git")
487
+ python_version = ".".join([str(x) for x in sys.version_info[0:3]])
488
+ try:
489
+ commit_hash = run(f"{git} rev-parse HEAD").strip()
490
+ except Exception:
491
+ commit_hash = "<none>"
492
+ if commit_hash != "<none>":
493
+ short_commit = commit_hash[0:7]
494
+ commit_info = f"<a style=\"text-decoration:none\" href=\"https://github.com/GaiZhenbiao/ChuanhuChatGPT/commit/{short_commit}\">{short_commit}</a>"
495
+ else:
496
+ commit_info = "unknown \U0001F615"
497
+ return f"""
498
+ Python: <span title="{sys.version}">{python_version}</span>
499
+  • 
500
+ Gradio: {gr.__version__}
501
+  • 
502
+ Commit: {commit_info}
503
+ """