Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,6 +30,10 @@ print(f'MiniMind模型参数量: {sum(p.numel() for p in model.parameters() if p
|
|
| 30 |
|
| 31 |
# 生成文本函数
|
| 32 |
def generate_text(prompt, max_length=512, temperature=0.85, top_p=0.85, history_cnt=0):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
# 设置随机种子
|
| 34 |
setup_seed(random.randint(0, 2048))
|
| 35 |
|
|
@@ -255,7 +259,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 255 |
<div>
|
| 256 |
<span class="logo-pulse">🧠</span>
|
| 257 |
<h1>MiniMind AI</h1>
|
| 258 |
-
<p
|
| 259 |
</div>
|
| 260 |
""")
|
| 261 |
|
|
@@ -348,6 +352,13 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 348 |
outputs=output_text
|
| 349 |
)
|
| 350 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
clear_btn.click(
|
| 352 |
fn=clear_history,
|
| 353 |
inputs=[],
|
|
|
|
| 30 |
|
| 31 |
# 生成文本函数
|
| 32 |
def generate_text(prompt, max_length=512, temperature=0.85, top_p=0.85, history_cnt=0):
|
| 33 |
+
# 如果输入为空,则返回提示信息
|
| 34 |
+
if not prompt.strip():
|
| 35 |
+
return "请输入您的问题或指令..."
|
| 36 |
+
|
| 37 |
# 设置随机种子
|
| 38 |
setup_seed(random.randint(0, 2048))
|
| 39 |
|
|
|
|
| 259 |
<div>
|
| 260 |
<span class="logo-pulse">🧠</span>
|
| 261 |
<h1>MiniMind AI</h1>
|
| 262 |
+
<p>基于开源项目minimind训练的模型,为您提供智能对话体验</p>
|
| 263 |
</div>
|
| 264 |
""")
|
| 265 |
|
|
|
|
| 352 |
outputs=output_text
|
| 353 |
)
|
| 354 |
|
| 355 |
+
# 添加回车键触发生成回答的功能
|
| 356 |
+
input_text.submit(
|
| 357 |
+
fn=generate_text,
|
| 358 |
+
inputs=[input_text, max_length, temperature, top_p, history_cnt],
|
| 359 |
+
outputs=output_text
|
| 360 |
+
)
|
| 361 |
+
|
| 362 |
clear_btn.click(
|
| 363 |
fn=clear_history,
|
| 364 |
inputs=[],
|