decula commited on
Commit
4f26428
·
1 Parent(s): 48f4118

Added stop button

Browse files
Files changed (1) hide show
  1. 7b_rag.py +28 -12
7b_rag.py CHANGED
@@ -211,23 +211,39 @@ install_Frpc('7860',frpconfigfile,use_frpc)
211
  # Gradio blocks
212
  with gr.Blocks(title=title) as demo:
213
  gr.HTML(f"<div style=\"text-align: center;\">\n<h1>RWKV-5 World v2 with RAG - {title}</h1>\n</div>")
214
- with gr.Tab("RAG-Enhanced Generation"):
215
- gr.Markdown(f"This is RWKV-5 World v2 with 3B params and RAG (Retrieval Augmented Generation) - a 100% attention-free RNN [RWKV-LM](https://github.com/BlinkDL/RWKV-LM) enhanced with web search. Supports all 100+ world languages and code. *** Please try examples first (bottom of page) *** (edit them to use your question). Demo limited to ctxlen {ctx_limit}.")
216
  with gr.Row():
217
  with gr.Column():
218
- prompt = gr.Textbox(lines=2, label="Prompt", value="")
219
- token_count = gr.Slider(0, 20000, label="Max Tokens", step=200, value=100)
220
- temperature = gr.Slider(0.2, 2.0, label="Temperature", step=0.1, value=1.0)
221
  top_p = gr.Slider(0.0, 1.0, label="Top P", step=0.05, value=0.3)
222
- presence_penalty = gr.Slider(0.0, 1.0, label="Presence Penalty", step=0.1, value=1)
223
- count_penalty = gr.Slider(0.0, 1.0, label="Count Penalty", step=0.1, value=1)
224
  with gr.Column():
225
  with gr.Row():
226
- submit = gr.Button("Submit", variant="primary")
227
- clear = gr.Button("Clear", variant="secondary")
228
- output = gr.Textbox(label="Output", lines=5)
229
- data = gr.Dataset(components=[prompt, token_count, temperature, top_p, presence_penalty, count_penalty], label="Example Instructions", headers=["Prompt", "Max Tokens", "Temperature", "Top P", "Presence Penalty", "Count Penalty"])
230
- submit.click(evaluate, [prompt, token_count, temperature, top_p, presence_penalty, count_penalty], [output])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  clear.click(lambda: None, [], [output])
232
  data.click(lambda x: x, [data], [prompt, token_count, temperature, top_p, presence_penalty, count_penalty])
233
 
 
211
  # Gradio blocks
212
  with gr.Blocks(title=title) as demo:
213
  gr.HTML(f"<div style=\"text-align: center;\">\n<h1>RWKV-5 World v2 with RAG - {title}</h1>\n</div>")
214
+ with gr.Tab("Raw Generation"):
215
+ gr.Markdown(f"这是带有RAG功能的RWKV-5 World v2模型。支持100多种世界语言和代码。演示限制上下文长度为{ctx_limit}")
216
  with gr.Row():
217
  with gr.Column():
218
+ prompt = gr.Textbox(lines=2, label="提示词", value="")
219
+ token_count = gr.Slider(0, 20000, label="最大Token数", step=200, value=100)
220
+ temperature = gr.Slider(0.2, 2.0, label="温度", step=0.1, value=1.0)
221
  top_p = gr.Slider(0.0, 1.0, label="Top P", step=0.05, value=0.3)
222
+ presence_penalty = gr.Slider(0.0, 1.0, label="存在惩罚", step=0.1, value=1)
223
+ count_penalty = gr.Slider(0.0, 1.0, label="计数惩罚", step=0.1, value=1)
224
  with gr.Column():
225
  with gr.Row():
226
+ submit = gr.Button("提交", variant="primary")
227
+ stop_btn = gr.Button("中断", variant="stop")
228
+ clear = gr.Button("清除", variant="secondary")
229
+ output = gr.Textbox(label="输出", lines=5)
230
+ data = gr.Dataset(components=[prompt, token_count, temperature, top_p, presence_penalty, count_penalty], label="示例指令", headers=["提示词", "最大Token数", "温度", "Top P", "存在惩罚", "计数惩罚"])
231
+
232
+ # 设置提交按钮事件
233
+ submit_event = submit.click(
234
+ evaluate,
235
+ [prompt, token_count, temperature, top_p, presence_penalty, count_penalty],
236
+ [output]
237
+ )
238
+
239
+ # 设置中断按钮事件
240
+ stop_btn.click(
241
+ fn=None,
242
+ inputs=None,
243
+ outputs=None,
244
+ cancels=[submit_event] # 取消正在进行的生成过程
245
+ )
246
+
247
  clear.click(lambda: None, [], [output])
248
  data.click(lambda x: x, [data], [prompt, token_count, temperature, top_p, presence_penalty, count_penalty])
249