Spaces:
Runtime error
Runtime error
JohnSmith9982
commited on
Commit
•
e1bbc1f
1
Parent(s):
43a8575
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
|
|
3 |
import os
|
4 |
import sys
|
5 |
from utils import *
|
|
|
6 |
|
7 |
my_api_key = "" # 在这里输入你的 API 密钥
|
8 |
HIDE_MY_KEY = False # 如果你想在UI中隐藏你的 API 密钥,将此值设置为 True
|
@@ -39,43 +40,6 @@ else:
|
|
39 |
if username != "" and password != "":
|
40 |
authflag = True
|
41 |
|
42 |
-
title = """<h1 align="center">川虎ChatGPT 🚀</h1>"""
|
43 |
-
description = """<div align=center>
|
44 |
-
|
45 |
-
由Bilibili [土川虎虎虎](https://space.bilibili.com/29125536) 和 [明昭MZhao](https://space.bilibili.com/24807452)开发
|
46 |
-
|
47 |
-
访问川虎ChatGPT的 [GitHub项目](https://github.com/GaiZhenbiao/ChuanhuChatGPT) 下载最新版脚本
|
48 |
-
|
49 |
-
此App使用 `gpt-3.5-turbo` 大语言模型
|
50 |
-
</div>
|
51 |
-
"""
|
52 |
-
customCSS = """
|
53 |
-
code {
|
54 |
-
display: inline;
|
55 |
-
white-space: break-spaces;
|
56 |
-
border-radius: 6px;
|
57 |
-
margin: 0 2px 0 2px;
|
58 |
-
padding: .2em .4em .1em .4em;
|
59 |
-
background-color: rgba(175,184,193,0.2);
|
60 |
-
}
|
61 |
-
pre {
|
62 |
-
display: block;
|
63 |
-
white-space: pre;
|
64 |
-
background-color: hsla(0, 0%, 0%, 72%);
|
65 |
-
border: solid 5px var(--color-border-primary) !important;
|
66 |
-
border-radius: 8px;
|
67 |
-
padding: 0 1.2rem 1.2rem;
|
68 |
-
margin-top: 1em !important;
|
69 |
-
color: #FFF;
|
70 |
-
box-shadow: inset 0px 8px 16px hsla(0, 0%, 0%, .2)
|
71 |
-
}
|
72 |
-
pre code, pre code code {
|
73 |
-
background-color: transparent !important;
|
74 |
-
margin: 0;
|
75 |
-
padding: 0;
|
76 |
-
}
|
77 |
-
"""
|
78 |
-
|
79 |
with gr.Blocks(css=customCSS) as demo:
|
80 |
gr.HTML(title)
|
81 |
gr.HTML('''<center><a href="https://huggingface.co/spaces/JohnSmith9982/ChuanhuChatGPT?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="复制 Space"></a>强烈建议点击上面的按钮复制一份这个Space,在你自己的Space里运行,响应更迅速、也更安全👆</center>''')
|
@@ -106,26 +70,26 @@ with gr.Blocks(css=customCSS) as demo:
|
|
106 |
with gr.Column():
|
107 |
with gr.Row():
|
108 |
with gr.Column(scale=6):
|
109 |
-
templateFileSelectDropdown = gr.Dropdown(label="选择Prompt模板集合文件(.csv)", choices=get_template_names(plain=True), multiselect=False)
|
110 |
with gr.Column(scale=1):
|
111 |
templateRefreshBtn = gr.Button("🔄 刷新")
|
112 |
templaeFileReadBtn = gr.Button("📂 读入模板")
|
113 |
with gr.Row():
|
114 |
with gr.Column(scale=6):
|
115 |
-
templateSelectDropdown = gr.Dropdown(label="从Prompt模板中加载", choices=load_template(get_template_names(plain=True)[0], mode=1), multiselect=False)
|
116 |
with gr.Column(scale=1):
|
117 |
templateApplyBtn = gr.Button("⬇️ 应用")
|
118 |
-
with gr.Accordion(label="保存/加载对话历史记录
|
119 |
with gr.Column():
|
120 |
with gr.Row():
|
121 |
with gr.Column(scale=6):
|
122 |
saveFileName = gr.Textbox(
|
123 |
show_label=True, placeholder=f"在这里输入保存的文件名...", label="设置保存文件名", value="对话历史记录").style(container=True)
|
124 |
with gr.Column(scale=1):
|
125 |
-
|
126 |
with gr.Row():
|
127 |
with gr.Column(scale=6):
|
128 |
-
historyFileSelectDropdown = gr.Dropdown(label="从列表中加载对话", choices=get_history_names(plain=True), multiselect=False)
|
129 |
with gr.Column(scale=1):
|
130 |
historyRefreshBtn = gr.Button("🔄 刷新")
|
131 |
historyReadBtn = gr.Button("📂 读入对话")
|
@@ -153,14 +117,14 @@ with gr.Blocks(css=customCSS) as demo:
|
|
153 |
chatbot, history], show_progress=True)
|
154 |
reduceTokenBtn.click(predict, [txt, top_p, temperature, keyTxt, chatbot, history,
|
155 |
systemPromptTxt, FALSECONSTANT, TRUECOMSTANT], [chatbot, history, statusDisplay], show_progress=True)
|
156 |
-
|
157 |
saveFileName, systemPromptTxt, history, chatbot], None, show_progress=True)
|
158 |
-
|
159 |
historyRefreshBtn.click(get_history_names, None, [historyFileSelectDropdown])
|
160 |
-
historyReadBtn.click(load_chat_history, [historyFileSelectDropdown], [saveFileName, systemPromptTxt, history, chatbot], show_progress=True)
|
161 |
templateRefreshBtn.click(get_template_names, None, [templateFileSelectDropdown])
|
162 |
templaeFileReadBtn.click(load_template, [templateFileSelectDropdown], [promptTemplates, templateSelectDropdown], show_progress=True)
|
163 |
-
templateApplyBtn.click(
|
164 |
|
165 |
print("川虎的温馨提示:访问 http://localhost:7860 查看界面")
|
166 |
# 默认开启本地服务器,默认可以直接从IP访问,默认不创建公开分享链接
|
|
|
3 |
import os
|
4 |
import sys
|
5 |
from utils import *
|
6 |
+
from presets import *
|
7 |
|
8 |
my_api_key = "" # 在这里输入你的 API 密钥
|
9 |
HIDE_MY_KEY = False # 如果你想在UI中隐藏你的 API 密钥,将此值设置为 True
|
|
|
40 |
if username != "" and password != "":
|
41 |
authflag = True
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
with gr.Blocks(css=customCSS) as demo:
|
44 |
gr.HTML(title)
|
45 |
gr.HTML('''<center><a href="https://huggingface.co/spaces/JohnSmith9982/ChuanhuChatGPT?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="复制 Space"></a>强烈建议点击上面的按钮复制一份这个Space,在你自己的Space里运行,响应更迅速、也更安全👆</center>''')
|
|
|
70 |
with gr.Column():
|
71 |
with gr.Row():
|
72 |
with gr.Column(scale=6):
|
73 |
+
templateFileSelectDropdown = gr.Dropdown(label="选择Prompt模板集合文件(.csv)", choices=get_template_names(plain=True), multiselect=False, value=get_template_names(plain=True)[0])
|
74 |
with gr.Column(scale=1):
|
75 |
templateRefreshBtn = gr.Button("🔄 刷新")
|
76 |
templaeFileReadBtn = gr.Button("📂 读入模板")
|
77 |
with gr.Row():
|
78 |
with gr.Column(scale=6):
|
79 |
+
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])
|
80 |
with gr.Column(scale=1):
|
81 |
templateApplyBtn = gr.Button("⬇️ 应用")
|
82 |
+
with gr.Accordion(label="保存/加载对话历史记录", open=False):
|
83 |
with gr.Column():
|
84 |
with gr.Row():
|
85 |
with gr.Column(scale=6):
|
86 |
saveFileName = gr.Textbox(
|
87 |
show_label=True, placeholder=f"在这里输入保存的文件名...", label="设置保存文件名", value="对话历史记录").style(container=True)
|
88 |
with gr.Column(scale=1):
|
89 |
+
saveHistoryBtn = gr.Button("💾 保存对话")
|
90 |
with gr.Row():
|
91 |
with gr.Column(scale=6):
|
92 |
+
historyFileSelectDropdown = gr.Dropdown(label="从列表中加载对话", choices=get_history_names(plain=True), multiselect=False, value=get_history_names(plain=True)[0])
|
93 |
with gr.Column(scale=1):
|
94 |
historyRefreshBtn = gr.Button("🔄 刷新")
|
95 |
historyReadBtn = gr.Button("📂 读入对话")
|
|
|
117 |
chatbot, history], show_progress=True)
|
118 |
reduceTokenBtn.click(predict, [txt, top_p, temperature, keyTxt, chatbot, history,
|
119 |
systemPromptTxt, FALSECONSTANT, TRUECOMSTANT], [chatbot, history, statusDisplay], show_progress=True)
|
120 |
+
saveHistoryBtn.click(save_chat_history, [
|
121 |
saveFileName, systemPromptTxt, history, chatbot], None, show_progress=True)
|
122 |
+
saveHistoryBtn.click(get_history_names, None, [historyFileSelectDropdown])
|
123 |
historyRefreshBtn.click(get_history_names, None, [historyFileSelectDropdown])
|
124 |
+
historyReadBtn.click(load_chat_history, [historyFileSelectDropdown, systemPromptTxt, history, chatbot], [saveFileName, systemPromptTxt, history, chatbot], show_progress=True)
|
125 |
templateRefreshBtn.click(get_template_names, None, [templateFileSelectDropdown])
|
126 |
templaeFileReadBtn.click(load_template, [templateFileSelectDropdown], [promptTemplates, templateSelectDropdown], show_progress=True)
|
127 |
+
templateApplyBtn.click(get_template_content, [promptTemplates, templateSelectDropdown, systemPromptTxt], [systemPromptTxt], show_progress=True)
|
128 |
|
129 |
print("川虎的温馨提示:访问 http://localhost:7860 查看界面")
|
130 |
# 默认开启本地服务器,默认可以直接从IP访问,默认不创建公开分享链接
|