cmz1024 commited on
Commit
6dd7bb1
·
verified ·
1 Parent(s): 7faa428

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +107 -1
app.py CHANGED
@@ -249,4 +249,110 @@ body {
249
 
250
  # 创建Gradio界面
251
  with gr.Blocks(css=custom_css) as demo:
252
- with gr.Column(elem
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
 
250
  # 创建Gradio界面
251
  with gr.Blocks(css=custom_css) as demo:
252
+ with gr.Column(elem_classes="container"):
253
+ with gr.Column(elem_classes="header-container"):
254
+ gr.HTML("""
255
+ <div>
256
+ <span class="logo-pulse">🧠</span>
257
+ <h1>MiniMind AI</h1>
258
+ <p>强大的自然语言处理模型,为您提供智能对话体验</p>
259
+ </div>
260
+ """)
261
+
262
+ with gr.Column(elem_classes="main-card"):
263
+ with gr.Row():
264
+ with gr.Column(scale=1, elem_classes="input-area"):
265
+ input_text = gr.Textbox(
266
+ label="您的问题",
267
+ placeholder="请在此输入您的问题或指令...",
268
+ lines=5,
269
+ elem_id="input-box"
270
+ )
271
+
272
+ with gr.Row():
273
+ submit_btn = gr.Button("🚀 生成回答", elem_classes="button-primary")
274
+ clear_btn = gr.Button("🗑️ 清除历史", elem_classes="button-secondary")
275
+
276
+ with gr.Accordion("⚙️ 高级参数设置", open=False, elem_classes="accordion"):
277
+ max_length = gr.Slider(
278
+ minimum=10, maximum=2048, value=512, step=1,
279
+ label="最大生成长度",
280
+ info="控制生成文本的最大长度",
281
+ elem_classes="slider-container"
282
+ )
283
+ temperature = gr.Slider(
284
+ minimum=0.1, maximum=1.5, value=0.85, step=0.01,
285
+ label="温度系数",
286
+ info="较高的值会使输出更加随机,较低的值使输出更加确定",
287
+ elem_classes="slider-container"
288
+ )
289
+ top_p = gr.Slider(
290
+ minimum=0.1, maximum=1.0, value=0.85, step=0.01,
291
+ label="Top-p 采样",
292
+ info="控制词汇选择的多样性",
293
+ elem_classes="slider-container"
294
+ )
295
+ history_cnt = gr.Slider(
296
+ minimum=0, maximum=10, value=0, step=2,
297
+ label="历史对话轮数",
298
+ info="考虑多少轮历史对话作为上下文",
299
+ elem_classes="slider-container"
300
+ )
301
+
302
+ with gr.Column(scale=1, elem_classes="output-area"):
303
+ output_text = gr.Textbox(
304
+ label="AI 回答",
305
+ lines=25,
306
+ elem_id="output-box"
307
+ )
308
+ clear_output = gr.Textbox(
309
+ label="状态",
310
+ value="系统就绪,等待您的输入...",
311
+ elem_classes="status-box"
312
+ )
313
+
314
+ with gr.Column(elem_classes="footer"):
315
+ gr.HTML("""
316
+ <div>
317
+ <p>MiniMind 模型演示 | 基于先进的自然语言处理技术</p>
318
+ <p>运行环境:<span id="device-info"></span></p>
319
+ </div>
320
+ <script>
321
+ document.getElementById('device-info').innerText =
322
+ navigator.userAgent.includes('Mobile') ? '移动设备' : '桌面设备';
323
+
324
+ // 添加输入动画效果
325
+ document.addEventListener('DOMContentLoaded', function() {
326
+ const inputBox = document.getElementById('input-box');
327
+ const outputBox = document.getElementById('output-box');
328
+
329
+ if(inputBox) {
330
+ inputBox.addEventListener('focus', function() {
331
+ this.style.transform = 'translateY(-2px)';
332
+ this.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.1)';
333
+ });
334
+
335
+ inputBox.addEventListener('blur', function() {
336
+ this.style.transform = 'translateY(0)';
337
+ this.style.boxShadow = '0 1px 3px rgba(0, 0, 0, 0.1)';
338
+ });
339
+ }
340
+ });
341
+ </script>
342
+ """)
343
+
344
+ # 设置事件
345
+ submit_btn.click(
346
+ fn=generate_text,
347
+ inputs=[input_text, max_length, temperature, top_p, history_cnt],
348
+ outputs=output_text
349
+ )
350
+
351
+ clear_btn.click(
352
+ fn=clear_history,
353
+ inputs=[],
354
+ outputs=clear_output
355
+ )
356
+
357
+ # 启动应用
358
+ demo.launch()