Spaces:
Sleeping
Sleeping
Chen Zirui
commited on
大幅美化布局 🗓️ TODO: status_display高度固定 (#172)
Browse files- ChuanhuChatbot.py +70 -56
- presets.py +8 -1
ChuanhuChatbot.py
CHANGED
|
@@ -43,7 +43,7 @@ else:
|
|
| 43 |
|
| 44 |
gr.Chatbot.postprocess = postprocess
|
| 45 |
|
| 46 |
-
with gr.Blocks(css=customCSS) as demo:
|
| 47 |
history = gr.State([])
|
| 48 |
token_count = gr.State([])
|
| 49 |
promptTemplates = gr.State(load_template(get_template_names(plain=True)[0], mode=2))
|
|
@@ -51,64 +51,78 @@ with gr.Blocks(css=customCSS) as demo:
|
|
| 51 |
FALSECONSTANT = gr.State(False)
|
| 52 |
topic = gr.State("未命名对话历史记录")
|
| 53 |
|
| 54 |
-
gr.HTML(
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
| 58 |
with gr.Column():
|
| 59 |
-
with gr.Row():
|
|
|
|
|
|
|
|
|
|
| 60 |
model_select_dropdown = gr.Dropdown(label="选择模型", choices=MODELS, multiselect=False, value=MODELS[0])
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
saveHistoryBtn = gr.Button("💾 保存对话")
|
| 99 |
-
with gr.Row():
|
| 100 |
-
with gr.Column(scale=6):
|
| 101 |
-
historyFileSelectDropdown = gr.Dropdown(label="从列表中加载对话", choices=get_history_names(plain=True), multiselect=False, value=get_history_names(plain=True)[0])
|
| 102 |
-
with gr.Column(scale=1):
|
| 103 |
-
historyRefreshBtn = gr.Button("🔄 刷新")
|
| 104 |
-
historyReadBtn = gr.Button("📂 读入对话")
|
| 105 |
-
#inputs, top_p, temperature, top_k, repetition_penalty
|
| 106 |
-
with gr.Accordion("参数", open=False):
|
| 107 |
-
top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.05,
|
| 108 |
-
interactive=True, label="Top-p (nucleus sampling)",)
|
| 109 |
-
temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0,
|
| 110 |
-
step=0.1, interactive=True, label="Temperature",)
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
gr.Markdown(description)
|
| 113 |
|
| 114 |
|
|
|
|
| 43 |
|
| 44 |
gr.Chatbot.postprocess = postprocess
|
| 45 |
|
| 46 |
+
with gr.Blocks(css=customCSS,) as demo:
|
| 47 |
history = gr.State([])
|
| 48 |
token_count = gr.State([])
|
| 49 |
promptTemplates = gr.State(load_template(get_template_names(plain=True)[0], mode=2))
|
|
|
|
| 51 |
FALSECONSTANT = gr.State(False)
|
| 52 |
topic = gr.State("未命名对话历史记录")
|
| 53 |
|
| 54 |
+
gr.HTML("""
|
| 55 |
+
<div style="text-align: center; margin-top: 20px;">
|
| 56 |
+
""")
|
| 57 |
+
|
| 58 |
+
with gr.Row(scale=1).style(equal_height=True):
|
| 59 |
with gr.Column():
|
| 60 |
+
with gr.Row(min_width=50,scale=1):
|
| 61 |
+
gr.HTML(title)
|
| 62 |
+
status_display = gr.Markdown("status: ready")
|
| 63 |
+
keyTxt = gr.Textbox(show_label=True, placeholder=f"OpenAI API-key...",value=my_api_key, type="password", visible=not HIDE_MY_KEY, label="API-Key")
|
| 64 |
model_select_dropdown = gr.Dropdown(label="选择模型", choices=MODELS, multiselect=False, value=MODELS[0])
|
| 65 |
+
systemPromptTxt = gr.Textbox(show_label=True, placeholder=f"在这里输入System Prompt...", label="System prompt", value=initial_prompt).style(container=True)
|
| 66 |
+
|
| 67 |
+
#inputs, top_p, temperature, top_k, repetition_penalty
|
| 68 |
+
with gr.Accordion("参数", open=True):
|
| 69 |
+
top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.05,
|
| 70 |
+
interactive=True, label="Top-p (nucleus sampling)",)
|
| 71 |
+
temperature = gr.Slider(minimum=-0, maximum=5.0, value=1.0,
|
| 72 |
+
step=0.1, interactive=True, label="Temperature",)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
with gr.Accordion(label="加载Prompt模板", open=False):
|
| 76 |
+
with gr.Column():
|
| 77 |
+
with gr.Row():
|
| 78 |
+
with gr.Column(scale=6):
|
| 79 |
+
templateFileSelectDropdown = gr.Dropdown(label="选择Prompt模板集合文件", choices=get_template_names(plain=True), multiselect=False, value=get_template_names(plain=True)[0])
|
| 80 |
+
with gr.Column(scale=1):
|
| 81 |
+
templateRefreshBtn = gr.Button("🔄 刷新")
|
| 82 |
+
templaeFileReadBtn = gr.Button("📂 读入模板")
|
| 83 |
+
with gr.Row():
|
| 84 |
+
with gr.Column(scale=6):
|
| 85 |
+
templateSelectDropdown = gr.Dropdown(label="从Prompt模板中加载", choices=load_template(get_template_names(plain=True)[0], mode=1), multiselect=False, value=load_template(get_template_names(plain=True)[0], mode=1)[0])
|
| 86 |
+
with gr.Column(scale=1):
|
| 87 |
+
templateApplyBtn = gr.Button("⬇️ 应用")
|
| 88 |
+
with gr.Accordion(label="保存/加载对话历史记录", open=False):
|
| 89 |
+
with gr.Column():
|
| 90 |
+
with gr.Row():
|
| 91 |
+
with gr.Column(scale=6):
|
| 92 |
+
saveFileName = gr.Textbox(
|
| 93 |
+
show_label=True, placeholder=f"在这里输入保存的文件名...", label="设置保存文件名", value="对话历史记录").style(container=True)
|
| 94 |
+
with gr.Column(scale=1):
|
| 95 |
+
saveHistoryBtn = gr.Button("💾 保存对话")
|
| 96 |
+
with gr.Row():
|
| 97 |
+
with gr.Column(scale=6):
|
| 98 |
+
historyFileSelectDropdown = gr.Dropdown(label="从列表中加载对话", choices=get_history_names(plain=True), multiselect=False, value=get_history_names(plain=True)[0])
|
| 99 |
+
with gr.Column(scale=1):
|
| 100 |
+
historyRefreshBtn = gr.Button("🔄 刷新")
|
| 101 |
+
historyReadBtn = gr.Button("📂 读入对话")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
+
use_streaming_checkbox = gr.Checkbox(label="实时传输回答", value=True, visible=enable_streaming_option)
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
with gr.Column(scale=5):
|
| 108 |
+
with gr.Row(scale=1):
|
| 109 |
+
chatbot = gr.Chatbot().style(height=700) # .style(color_map=("#1D51EE", "#585A5B"))
|
| 110 |
+
with gr.Row(scale=1):
|
| 111 |
+
with gr.Column(scale=12):
|
| 112 |
+
user_input = gr.Textbox(show_label=False, placeholder="在这里输入").style(
|
| 113 |
+
container=False)
|
| 114 |
+
with gr.Column(min_width=50, scale=1):
|
| 115 |
+
submitBtn = gr.Button("🚀", variant="primary")
|
| 116 |
+
with gr.Row(scale=1):
|
| 117 |
+
emptyBtn = gr.Button("🧹 新的对话",)
|
| 118 |
+
retryBtn = gr.Button("🔄 重新生成")
|
| 119 |
+
delLastBtn = gr.Button("🗑️ 删除最近一条对话")
|
| 120 |
+
reduceTokenBtn = gr.Button("♻️ 总结对话")
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
gr.HTML("""
|
| 124 |
+
<div style="text-align: center; margin-top: 20px; margin-bottom: 20px;">
|
| 125 |
+
""")
|
| 126 |
gr.Markdown(description)
|
| 127 |
|
| 128 |
|
presets.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# -*- coding:utf-8 -*-
|
| 2 |
-
title = """<h1 align="
|
| 3 |
description = """<div align=center>
|
| 4 |
|
| 5 |
由Bilibili [土川虎虎虎](https://space.bilibili.com/29125536) 和 [明昭MZhao](https://space.bilibili.com/24807452)开发
|
|
@@ -29,6 +29,13 @@ pre code {
|
|
| 29 |
color: #FFF;
|
| 30 |
box-shadow: inset 0px 8px 16px hsla(0, 0%, 0%, .2)
|
| 31 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
"""
|
| 33 |
|
| 34 |
summarize_prompt = "你是谁?我们刚才聊了什么?" # 总结对话时的 prompt
|
|
|
|
| 1 |
# -*- coding:utf-8 -*-
|
| 2 |
+
title = """<h1 align="left">川虎ChatGPT 🚀</h1>"""
|
| 3 |
description = """<div align=center>
|
| 4 |
|
| 5 |
由Bilibili [土川虎虎虎](https://space.bilibili.com/29125536) 和 [明昭MZhao](https://space.bilibili.com/24807452)开发
|
|
|
|
| 29 |
color: #FFF;
|
| 30 |
box-shadow: inset 0px 8px 16px hsla(0, 0%, 0%, .2)
|
| 31 |
}
|
| 32 |
+
|
| 33 |
+
*{
|
| 34 |
+
border-radius: 3px !important;
|
| 35 |
+
transition: all 0.6s;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
|
| 39 |
"""
|
| 40 |
|
| 41 |
summarize_prompt = "你是谁?我们刚才聊了什么?" # 总结对话时的 prompt
|