Keldos commited on
Commit
1a5edd8
1 Parent(s): d4ac5ad

refactor: 将html内容从presets移除

Browse files
ChuanhuChatbot.py CHANGED
@@ -161,7 +161,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
161
 
162
  with gr.Tab(label=i18n("高级")):
163
  gr.Markdown(i18n("# ⚠️ 务必谨慎更改 ⚠️\n\n如果无法使用请恢复默认设置"))
164
- gr.HTML(APPEARANCE_SWITCHER, elem_classes="insert_block")
165
  use_streaming_checkbox = gr.Checkbox(
166
  label=i18n("实时传输回答"), value=True, visible=ENABLE_STREAMING_OPTION
167
  )
@@ -265,7 +265,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
265
  default_btn = gr.Button(i18n("🔙 恢复默认设置"))
266
 
267
  gr.Markdown(CHUANHU_DESCRIPTION, elem_id="description")
268
- gr.HTML(FOOTER.format(versions=versions_html()), elem_id="footer")
269
 
270
  # https://github.com/gradio-app/gradio/pull/3296
271
  def create_greeting(request: gr.Request):
 
161
 
162
  with gr.Tab(label=i18n("高级")):
163
  gr.Markdown(i18n("# ⚠️ 务必谨慎更改 ⚠️\n\n如果无法使用请恢复默认设置"))
164
+ gr.HTML(get_html("appearance_switcher.html").format(label=i18n("切换亮暗色主题")), elem_classes="insert_block")
165
  use_streaming_checkbox = gr.Checkbox(
166
  label=i18n("实时传输回答"), value=True, visible=ENABLE_STREAMING_OPTION
167
  )
 
265
  default_btn = gr.Button(i18n("🔙 恢复默认设置"))
266
 
267
  gr.Markdown(CHUANHU_DESCRIPTION, elem_id="description")
268
+ gr.HTML(get_html("footer.html").format(versions=versions_html()), elem_id="footer")
269
 
270
  # https://github.com/gradio-app/gradio/pull/3296
271
  def create_greeting(request: gr.Request):
assets/html/appearance_switcher.html ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div style="display: flex; justify-content: space-between;">
2
+ <span style="margin-top: 4px !important;">
3
+ {label}
4
+ </span>
5
+ <span>
6
+ <label class="apSwitch" for="checkbox">
7
+ <input type="checkbox" id="checkbox">
8
+ <div class="apSlider"></div>
9
+ </label>
10
+ </span>
11
+ </div>
assets/html/footer.html ADDED
@@ -0,0 +1 @@
 
 
1
+ <div class="versions">{versions}</div>
modules/presets.py CHANGED
@@ -46,17 +46,6 @@ CHUANHU_TITLE = i18n("川虎Chat 🚀")
46
 
47
  CHUANHU_DESCRIPTION = i18n("由Bilibili [土川虎虎虎](https://space.bilibili.com/29125536)、[明昭MZhao](https://space.bilibili.com/24807452) 和 [Keldos](https://github.com/Keldos-Li) 开发<br />访问川虎Chat的 [GitHub项目](https://github.com/GaiZhenbiao/ChuanhuChatGPT) 下载最新版脚本")
48
 
49
- FOOTER = """<div class="versions">{versions}</div>"""
50
-
51
- APPEARANCE_SWITCHER = """
52
- <div style="display: flex; justify-content: space-between;">
53
- <span style="margin-top: 4px !important;">"""+ i18n("切换亮暗色主题") + """</span>
54
- <span><label class="apSwitch" for="checkbox">
55
- <input type="checkbox" id="checkbox">
56
- <div class="apSlider"></div>
57
- </label></span>
58
- </div>
59
- """
60
 
61
  ONLINE_MODELS = [
62
  "gpt-3.5-turbo",
 
46
 
47
  CHUANHU_DESCRIPTION = i18n("由Bilibili [土川虎虎虎](https://space.bilibili.com/29125536)、[明昭MZhao](https://space.bilibili.com/24807452) 和 [Keldos](https://github.com/Keldos-Li) 开发<br />访问川虎Chat的 [GitHub项目](https://github.com/GaiZhenbiao/ChuanhuChatGPT) 下载最新版脚本")
48
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  ONLINE_MODELS = [
51
  "gpt-3.5-turbo",
modules/shared.py CHANGED
@@ -59,3 +59,6 @@ class State:
59
 
60
 
61
  state = State()
 
 
 
 
59
 
60
 
61
  state = State()
62
+
63
+ modules_path = os.path.dirname(os.path.realpath(__file__))
64
+ chuanhu_path = os.path.dirname(modules_path)
modules/utils.py CHANGED
@@ -551,6 +551,13 @@ def versions_html():
551
  <a style="text-decoration:none;color:inherit" href="https://github.com/GaiZhenbiao/ChuanhuChatGPT">ChuanhuChat</a>: {commit_info}
552
  """
553
 
 
 
 
 
 
 
 
554
  def add_source_numbers(lst, source_name = "Source", use_source = True):
555
  if use_source:
556
  return [f'[{idx+1}]\t "{item[0]}"\n{source_name}: {item[1]}' for idx, item in enumerate(lst)]
 
551
  <a style="text-decoration:none;color:inherit" href="https://github.com/GaiZhenbiao/ChuanhuChatGPT">ChuanhuChat</a>: {commit_info}
552
  """
553
 
554
+ def get_html(filename):
555
+ path = os.path.join(shared.chuanhu_path, "assets", "html", filename)
556
+ if os.path.exists(path):
557
+ with open(path, encoding="utf8") as file:
558
+ return file.read()
559
+ return ""
560
+
561
  def add_source_numbers(lst, source_name = "Source", use_source = True):
562
  if use_source:
563
  return [f'[{idx+1}]\t "{item[0]}"\n{source_name}: {item[1]}' for idx, item in enumerate(lst)]