sjdnjn commited on
Commit
f1c51ab
·
verified ·
1 Parent(s): 108a050

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -1
app.py CHANGED
@@ -56,4 +56,36 @@ def get_model_outputs(question_or_prompt, context, max_length=100):
56
  elif qa_model and not context:
57
  output_qa = "问答模型需要提供上下文才能回答问题。"
58
 
59
- return output_text_gen, output_qa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  elif qa_model and not context:
57
  output_qa = "问答模型需要提供上下文才能回答问题。"
58
 
59
+ return output_text_gen, output_qa
60
+
61
+
62
+ # Arena 选项卡内容创建函数 (40分)
63
+ def create_arena_tab():
64
+ with gr.Blocks() as arena_block:
65
+ gr.Markdown("## ⚔️ Arena: 模型实时对比")
66
+ gr.Markdown("在这里,您可以输入一个问题或提示词,并提供一段上下文。文本生成模型将根据问题和上下文生成文本,问答模型将从上下文中抽取答案。")
67
+
68
+ with gr.Row():
69
+ # 统一输入框 1: 问题/提示词
70
+ question_input = gr.Textbox(label="问题/提示词:", placeholder="请输入您的问题或想让模型生成的提示词...", lines=3)
71
+ # 统一输入框 2: 上下文 (主要用于问答模型)
72
+ context_input = gr.Textbox(label="上下文 (Context):", placeholder="请输入问答模型需要从中抽取答案的上下文...", lines=5)
73
+
74
+ with gr.Row():
75
+ # 增加生成长度控制(主要针对文本生成模型)
76
+ gen_length_slider = gr.Slider(minimum=20, maximum=300, value=100, step=10, label="文本生成最大长度")
77
+ generate_btn = gr.Button("🚀 生成并对比")
78
+
79
+ with gr.Row():
80
+ # 模型 1 输出 (文本生成)
81
+ output_text_gen = gr.Textbox(label=f"模型 1 (文本生成: {model1_name}) 输出:", interactive=False, lines=10)
82
+ # 模型 2 输出 (问答)
83
+ output_qa = gr.Textbox(label=f"模型 2 (问答: {model2_name}) 输出:", interactive=False, lines=10)
84
+
85
+ # 绑定按钮点击事件到推理函数
86
+ generate_btn.click(
87
+ fn=get_model_outputs,
88
+ inputs=[question_input, context_input, gen_length_slider],
89
+ outputs=[output_text_gen, output_qa]
90
+ )
91
+ return arena_block