ClueAI commited on
Commit
f6b8bcf
1 Parent(s): 95d2f97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -10
app.py CHANGED
@@ -56,7 +56,27 @@ def chatyuan_bot(input, history):
56
  history.append((input, output_text))
57
  #print(history)
58
  return history, history
 
 
 
 
 
 
 
 
 
 
 
59
 
 
 
 
 
 
 
 
 
 
60
  block = gr.Blocks()
61
 
62
  with block as demo:
@@ -72,7 +92,10 @@ with block as demo:
72
  clear_history = gr.Button("👋 清除历史对话 | Clear")
73
  clear = gr.Button('🧹 清除发送框 | Clear Input')
74
  send = gr.Button("🚀 发送 | Send")
75
-
 
 
 
76
  send.click(chatyuan_bot, inputs=[message, state], outputs=[chatbot, state])
77
  clear.click(lambda: None, None, message, queue=False)
78
  clear_history.click(fn=clear_session , inputs=[], outputs=[chatbot, state], queue=False)
@@ -112,6 +135,8 @@ def chatyuan_bot_api(api_key, input, history):
112
  #print(history)
113
  return history, history
114
 
 
 
115
  block = gr.Blocks()
116
 
117
  with block as demo_1:
@@ -157,23 +182,14 @@ ChatYuan-large-v2是ChatYuan系列中以轻量化实现高质量效果的模型
157
  - 增强了模拟情景能力。.<br>
158
  <br>
159
  Based on the original functions of Chatyuan-large-v1, we optimized the model as follows:
160
-
161
  -Added the ability to speak in both Chinese and English.
162
-
163
  -Added the ability to refuse to answer. Learn to refuse to answer some dangerous and harmful questions.
164
-
165
  -Added code generation functionality. Basic code generation has been optimized to a certain extent.
166
-
167
  -Enhanced basic capabilities. The original contextual Q&A and creative writing skills have significantly improved.
168
-
169
  -Added a table generation function. Make the generated table content and format more appropriate.
170
-
171
  -Enhanced basic mathematical computing capabilities.
172
-
173
  -The maximum number of length tokens has been expanded to 4096.
174
-
175
  -Enhanced ability to simulate scenarios< br>
176
-
177
  <br>
178
  👀<a href='https://www.cluebenchmarks.com/clueai.html'>PromptCLUE-large</a>在1000亿token中文语料上预训练, 累计学习1.5万亿中文token, 并且在数百种任务上进行Prompt任务式训练. 针对理解类任务, 如分类、情感分析、抽取等, 可以自定义标签体系; 针对多种生成任务, 可以进行采样自由生成. <br>
179
  <br>
 
56
  history.append((input, output_text))
57
  #print(history)
58
  return history, history
59
+ def chatyuan_bot_regenerate(input, history):
60
+
61
+ history = history or []
62
+
63
+ if history:
64
+ input=history[-1][0]
65
+ history=history[:-1]
66
+
67
+
68
+ if len(history) > 5:
69
+ history = history[-5:]
70
 
71
+ context = "\n".join([f"用户:{input_text}\n小元:{answer_text}" for input_text, answer_text in history])
72
+ print(context)
73
+
74
+ input_text = context + "\n用户:" + input + "\n小元:"
75
+ output_text = answer(input_text)
76
+ history.append((input, output_text))
77
+ print(history)
78
+ return history, history
79
+
80
  block = gr.Blocks()
81
 
82
  with block as demo:
 
92
  clear_history = gr.Button("👋 清除历史对话 | Clear")
93
  clear = gr.Button('🧹 清除发送框 | Clear Input')
94
  send = gr.Button("🚀 发送 | Send")
95
+ regenerate = gr.Button("🚀 重新生成本次结果 | regenerate")
96
+
97
+
98
+ regenerate.click(chatyuan_bot_regenerate, inputs=[message, state], outputs=[chatbot, state])
99
  send.click(chatyuan_bot, inputs=[message, state], outputs=[chatbot, state])
100
  clear.click(lambda: None, None, message, queue=False)
101
  clear_history.click(fn=clear_session , inputs=[], outputs=[chatbot, state], queue=False)
 
135
  #print(history)
136
  return history, history
137
 
138
+
139
+
140
  block = gr.Blocks()
141
 
142
  with block as demo_1:
 
182
  - 增强了模拟情景能力。.<br>
183
  <br>
184
  Based on the original functions of Chatyuan-large-v1, we optimized the model as follows:
 
185
  -Added the ability to speak in both Chinese and English.
 
186
  -Added the ability to refuse to answer. Learn to refuse to answer some dangerous and harmful questions.
 
187
  -Added code generation functionality. Basic code generation has been optimized to a certain extent.
 
188
  -Enhanced basic capabilities. The original contextual Q&A and creative writing skills have significantly improved.
 
189
  -Added a table generation function. Make the generated table content and format more appropriate.
 
190
  -Enhanced basic mathematical computing capabilities.
 
191
  -The maximum number of length tokens has been expanded to 4096.
 
192
  -Enhanced ability to simulate scenarios< br>
 
193
  <br>
194
  👀<a href='https://www.cluebenchmarks.com/clueai.html'>PromptCLUE-large</a>在1000亿token中文语料上预训练, 累计学习1.5万亿中文token, 并且在数百种任务上进行Prompt任务式训练. 针对理解类任务, 如分类、情感分析、抽取等, 可以自定义标签体系; 针对多种生成任务, 可以进行采样自由生成. <br>
195
  <br>