Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -1030,7 +1030,7 @@ def chapterExtension(
|
|
1030 |
user_input, chatbot, max_length, top_p, temperature, history, past_key_values
|
1031 |
):
|
1032 |
|
1033 |
-
|
1034 |
user_input = chapterExtensionins+ user_input
|
1035 |
|
1036 |
yield from predict(
|
@@ -1042,9 +1042,123 @@ def chapterExtension(
|
|
1042 |
temperature,
|
1043 |
history,
|
1044 |
past_key_values,
|
1045 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1046 |
|
1047 |
-
|
1048 |
|
1049 |
with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) as demo:
|
1050 |
# gr.HTML("""<h1 align="center">ChatGLM2-6B-int4</h1>""")
|
@@ -1090,6 +1204,9 @@ with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) a
|
|
1090 |
with gr.Column(min_width=32, scale=1):
|
1091 |
with gr.Row():
|
1092 |
submitBtn = gr.Button("发送Submit", variant="primary")
|
|
|
|
|
|
|
1093 |
deleteBtn = gr.Button("删除最后一条对话", variant="secondary")
|
1094 |
retryBtn = gr.Button("重新生成Regenerate", variant="secondary")
|
1095 |
with gr.Row():
|
@@ -1112,7 +1229,7 @@ with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) a
|
|
1112 |
with gr.Row():
|
1113 |
fitnessAskBtn = gr.Button("🥼健康咨询", variant="primary")
|
1114 |
mindAskBtn = gr.Button("😶🌫️心理咨询", variant="primary")
|
1115 |
-
|
1116 |
with gr.Column(scale=1):
|
1117 |
gr.HTML("""<h3 align="center">🍀您好,除健康咨询和心理咨询外,其它功能使用前,请先清空历史,并输入问题。🍀</h3>""")
|
1118 |
emptyBtn = gr.Button("清空对话Clear History")
|
@@ -1524,7 +1641,7 @@ with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) a
|
|
1524 |
|
1525 |
mxOutlineBtn.click(
|
1526 |
reset_state, outputs=[chatbot, history, past_key_values], show_progress="full"
|
1527 |
-
|
1528 |
mxOutlineBtn.click(
|
1529 |
mxOutline,
|
1530 |
inputs=[
|
@@ -1553,9 +1670,23 @@ with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) a
|
|
1553 |
],
|
1554 |
# outputs = [chatbot, history, last_user_message, user_message]
|
1555 |
outputs=[chatbot, history, past_key_values],
|
1556 |
-
|
1557 |
-
|
1558 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1559 |
|
1560 |
with gr.Accordion("Example inputs", open=False):
|
1561 |
etext0 = """ "act": "作为基于文本的冒险游戏",\n "prompt": "我想让你扮演一个基于文本的冒险游戏。我在这个基于文本的冒险游戏中扮演一个角色。请尽可能具体地描述角色所看到的内容和环境,并在游戏输出1、2、3让用户选择进行回复,而不是其它方式。我将输入命令来告诉角色该做什么,而你需要回复角色的行动结果以推动游戏的进行。我的第一个命令是'醒来',请从这里开始故事 “ """
|
|
|
1030 |
user_input, chatbot, max_length, top_p, temperature, history, past_key_values
|
1031 |
):
|
1032 |
|
1033 |
+
|
1034 |
user_input = chapterExtensionins+ user_input
|
1035 |
|
1036 |
yield from predict(
|
|
|
1042 |
temperature,
|
1043 |
history,
|
1044 |
past_key_values,
|
1045 |
+
)
|
1046 |
+
def noNet(
|
1047 |
+
user_input, chatbot, max_length, top_p, temperature, history, past_key_values
|
1048 |
+
):
|
1049 |
+
yield from predict(
|
1050 |
+
RETRY_FLAG, # type: ignore
|
1051 |
+
user_input,
|
1052 |
+
chatbot=[],
|
1053 |
+
max_length=4000,
|
1054 |
+
top_p=0.6,
|
1055 |
+
temperature=0.85,
|
1056 |
+
history=[],
|
1057 |
+
past_key_values=None,
|
1058 |
+
)
|
1059 |
+
|
1060 |
+
def predictex(
|
1061 |
+
predict_function,
|
1062 |
+
inputs,
|
1063 |
+
outputs
|
1064 |
+
):
|
1065 |
+
predict_function(user_input, chatbot, max_length, top_p, temperature, history, past_key_values)
|
1066 |
+
outputs=[chatbot, history, past_key_values]
|
1067 |
+
|
1068 |
+
def execute(
|
1069 |
+
user_input, chatbot, max_length, top_p, temperature, history, past_key_values
|
1070 |
+
):
|
1071 |
+
response = chatbot[-1][1]
|
1072 |
+
print("Response:", response) # 添加打印语句以输出 response 的值
|
1073 |
+
if "不需要" in response:
|
1074 |
+
print("Executing 不连网...")
|
1075 |
+
predictex(
|
1076 |
+
noNet,
|
1077 |
+
inputs=[
|
1078 |
+
user_input,
|
1079 |
+
chatbot,
|
1080 |
+
max_length,
|
1081 |
+
top_p,
|
1082 |
+
temperature,
|
1083 |
+
history,
|
1084 |
+
past_key_values,
|
1085 |
+
],
|
1086 |
+
# outputs = [chatbot, history, last_user_message, user_message]
|
1087 |
+
outputs=[chatbot, history, past_key_values],
|
1088 |
+
)
|
1089 |
+
print("chatbot", chatbot)
|
1090 |
+
else:
|
1091 |
+
print("Executing 连网...")
|
1092 |
+
predictex(
|
1093 |
+
GGSearch,
|
1094 |
+
inputs=[
|
1095 |
+
user_input,
|
1096 |
+
chatbot,
|
1097 |
+
max_length,
|
1098 |
+
top_p,
|
1099 |
+
temperature,
|
1100 |
+
history,
|
1101 |
+
past_key_values,
|
1102 |
+
],
|
1103 |
+
# outputs = [chatbot, history, last_user_message, user_message]
|
1104 |
+
outputs=[chatbot, history, past_key_values],
|
1105 |
+
)
|
1106 |
+
|
1107 |
+
# 是否联网搜索函数
|
1108 |
+
def netOrNotnet(
|
1109 |
+
user_input, chatbot, max_length, top_p, temperature, history, past_key_values
|
1110 |
+
):
|
1111 |
+
user_input_original = user_input
|
1112 |
+
user_input_prompt = '请判断这个指令:“' + user_input + '”是否需要通过网络搜索才能准确完成,你只需要回答"是"或者"否",不要其它多余的内容'
|
1113 |
+
|
1114 |
+
response, history = model.chat(tokenizer, user_input_prompt, history=[])
|
1115 |
+
if '否' in response or '不需要' in response:
|
1116 |
+
NET = True
|
1117 |
+
else:
|
1118 |
+
NET = False
|
1119 |
+
print(user_input_original)
|
1120 |
+
print(response)
|
1121 |
+
print(NET)
|
1122 |
+
if NET:
|
1123 |
+
yield from predict(
|
1124 |
+
RETRY_FLAG,# type: ignore
|
1125 |
+
user_input_original,
|
1126 |
+
chatbot,
|
1127 |
+
max_length,
|
1128 |
+
top_p,
|
1129 |
+
temperature,
|
1130 |
+
history=[],
|
1131 |
+
past_key_values=None,
|
1132 |
+
|
1133 |
+
)
|
1134 |
+
|
1135 |
+
else:
|
1136 |
+
yield from GGSearch(
|
1137 |
+
user_input_original,
|
1138 |
+
chatbot,
|
1139 |
+
max_length,
|
1140 |
+
top_p,
|
1141 |
+
temperature,
|
1142 |
+
history=[],
|
1143 |
+
past_key_values=None,
|
1144 |
+
)
|
1145 |
+
|
1146 |
+
|
1147 |
+
# Update the chatbot and history variables after each execution
|
1148 |
+
chatbot = chatbot[:-1] + [chatbot[-1]]
|
1149 |
+
return chatbot, history, past_key_values
|
1150 |
+
|
1151 |
+
# 调用 execute 并传递 response
|
1152 |
+
execute(
|
1153 |
+
user_input_original,
|
1154 |
+
chatbot,
|
1155 |
+
max_length,
|
1156 |
+
top_p,
|
1157 |
+
temperature,
|
1158 |
+
history,
|
1159 |
+
past_key_values
|
1160 |
+
)
|
1161 |
|
|
|
1162 |
|
1163 |
with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) as demo:
|
1164 |
# gr.HTML("""<h1 align="center">ChatGLM2-6B-int4</h1>""")
|
|
|
1204 |
with gr.Column(min_width=32, scale=1):
|
1205 |
with gr.Row():
|
1206 |
submitBtn = gr.Button("发送Submit", variant="primary")
|
1207 |
+
GGSearchBtn = gr.Button("🐞联网搜索", variant="secondary")
|
1208 |
+
netOrNotnetBtn = gr.Button("联网意图识别🙏韩帅DEBUG🙏", variant="secondary")
|
1209 |
+
with gr.Row():
|
1210 |
deleteBtn = gr.Button("删除最后一条对话", variant="secondary")
|
1211 |
retryBtn = gr.Button("重新生成Regenerate", variant="secondary")
|
1212 |
with gr.Row():
|
|
|
1229 |
with gr.Row():
|
1230 |
fitnessAskBtn = gr.Button("🥼健康咨询", variant="primary")
|
1231 |
mindAskBtn = gr.Button("😶🌫️心理咨询", variant="primary")
|
1232 |
+
|
1233 |
with gr.Column(scale=1):
|
1234 |
gr.HTML("""<h3 align="center">🍀您好,除健康咨询和心理咨询外,其它功能使用前,请先清空历史,并输入问题。🍀</h3>""")
|
1235 |
emptyBtn = gr.Button("清空对话Clear History")
|
|
|
1641 |
|
1642 |
mxOutlineBtn.click(
|
1643 |
reset_state, outputs=[chatbot, history, past_key_values], show_progress="full"
|
1644 |
+
)
|
1645 |
mxOutlineBtn.click(
|
1646 |
mxOutline,
|
1647 |
inputs=[
|
|
|
1670 |
],
|
1671 |
# outputs = [chatbot, history, last_user_message, user_message]
|
1672 |
outputs=[chatbot, history, past_key_values],
|
1673 |
+
)
|
1674 |
+
|
1675 |
+
|
1676 |
+
netOrNotnetBtn.click(
|
1677 |
+
netOrNotnet,
|
1678 |
+
inputs=[
|
1679 |
+
user_input,
|
1680 |
+
chatbot,
|
1681 |
+
max_length,
|
1682 |
+
top_p,
|
1683 |
+
temperature,
|
1684 |
+
history,
|
1685 |
+
past_key_values,
|
1686 |
+
],
|
1687 |
+
# outputs = [chatbot, history, last_user_message, user_message]
|
1688 |
+
outputs=[chatbot, history, past_key_values],
|
1689 |
+
)
|
1690 |
|
1691 |
with gr.Accordion("Example inputs", open=False):
|
1692 |
etext0 = """ "act": "作为基于文本的冒险游戏",\n "prompt": "我想让你扮演一个基于文本的冒险游戏。我在这个基于文本的冒险游戏中扮演一个角色。请尽可能具体地描述角色所看到的内容和环境,并在游戏输出1、2、3让用户选择进行回复,而不是其它方式。我将输入命令来告诉角色该做什么,而你需要回复角色的行动结果以推动游戏的进行。我的第一个命令是'醒来',请从这里开始故事 “ """
|