Update app.py
Browse files
app.py
CHANGED
|
@@ -393,14 +393,18 @@ def create_demo():
|
|
| 393 |
interactive=False
|
| 394 |
)
|
| 395 |
|
|
|
|
| 396 |
score_chart = gr.LinePlot(
|
| 397 |
label="分数演进",
|
| 398 |
x="iteration",
|
| 399 |
y="score",
|
| 400 |
-
|
| 401 |
-
|
| 402 |
)
|
| 403 |
|
|
|
|
|
|
|
|
|
|
| 404 |
gr.Markdown("### 迭代详情")
|
| 405 |
|
| 406 |
# 使用 Tab 展示四个阶段
|
|
@@ -416,7 +420,7 @@ def create_demo():
|
|
| 416 |
|
| 417 |
def run_task(task: str, max_iter: int, target: float):
|
| 418 |
if not task or not task.strip():
|
| 419 |
-
yield "错误: 请输入任务描述", pd.DataFrame(columns=["iteration", "score"]), "", "", "", ""
|
| 420 |
return
|
| 421 |
|
| 422 |
chart_data = []
|
|
@@ -424,7 +428,7 @@ def create_demo():
|
|
| 424 |
|
| 425 |
empty_md = "*等待开始...*"
|
| 426 |
# 初始状态:显示"准备中"
|
| 427 |
-
yield "状态: 准备执行任务...", pd.DataFrame(columns=["iteration", "score"]), empty_md, empty_md, empty_md, empty_md
|
| 428 |
|
| 429 |
# 存储所有迭代的完整历史
|
| 430 |
all_history = []
|
|
@@ -494,11 +498,11 @@ def create_demo():
|
|
| 494 |
"""
|
| 495 |
|
| 496 |
# 更新图表数据
|
| 497 |
-
chart_data.append({"iteration": i, "score": current_score})
|
| 498 |
|
| 499 |
# 每次迭代完成后才更新 UI
|
| 500 |
status = f"状态: 第 {i}/{int(max_iter)} 次迭代完成 (分数: {current_score:.2f})"
|
| 501 |
-
yield status, pd.DataFrame(chart_data), plan_md, exec1_md, exec2_md, summary_md
|
| 502 |
|
| 503 |
# 检查是否达到目标
|
| 504 |
if current_score >= target:
|
|
@@ -507,12 +511,12 @@ def create_demo():
|
|
| 507 |
time.sleep(0.3)
|
| 508 |
|
| 509 |
final_status = f"状态: 任务完成\n最终分数: {current_score:.2f}\n总迭代次数: {len(chart_data)}"
|
| 510 |
-
yield final_status, pd.DataFrame(chart_data), plan_md, exec1_md, exec2_md, summary_md
|
| 511 |
|
| 512 |
run_btn.click(
|
| 513 |
fn=run_task,
|
| 514 |
inputs=[task_input, max_iterations, target_score],
|
| 515 |
-
outputs=[status_output, score_chart, plan_output, execute1_output, execute2_output, summary_output]
|
| 516 |
)
|
| 517 |
|
| 518 |
gr.Markdown("""
|
|
|
|
| 393 |
interactive=False
|
| 394 |
)
|
| 395 |
|
| 396 |
+
# 分数演进图表
|
| 397 |
score_chart = gr.LinePlot(
|
| 398 |
label="分数演进",
|
| 399 |
x="iteration",
|
| 400 |
y="score",
|
| 401 |
+
height=250,
|
| 402 |
+
title="Score Evolution"
|
| 403 |
)
|
| 404 |
|
| 405 |
+
# 额外显示分数列表
|
| 406 |
+
score_list = gr.JSON(label="分数详情")
|
| 407 |
+
|
| 408 |
gr.Markdown("### 迭代详情")
|
| 409 |
|
| 410 |
# 使用 Tab 展示四个阶段
|
|
|
|
| 420 |
|
| 421 |
def run_task(task: str, max_iter: int, target: float):
|
| 422 |
if not task or not task.strip():
|
| 423 |
+
yield "错误: 请输入任务描述", pd.DataFrame(columns=["iteration", "score"]), {}, "", "", "", ""
|
| 424 |
return
|
| 425 |
|
| 426 |
chart_data = []
|
|
|
|
| 428 |
|
| 429 |
empty_md = "*等待开始...*"
|
| 430 |
# 初始状态:显示"准备中"
|
| 431 |
+
yield "状态: 准备执行任务...", pd.DataFrame(columns=["iteration", "score"]), [], empty_md, empty_md, empty_md, empty_md
|
| 432 |
|
| 433 |
# 存储所有迭代的完整历史
|
| 434 |
all_history = []
|
|
|
|
| 498 |
"""
|
| 499 |
|
| 500 |
# 更新图表数据
|
| 501 |
+
chart_data.append({"iteration": i, "score": round(current_score, 2)})
|
| 502 |
|
| 503 |
# 每次迭代完成后才更新 UI
|
| 504 |
status = f"状态: 第 {i}/{int(max_iter)} 次迭代完成 (分数: {current_score:.2f})"
|
| 505 |
+
yield status, pd.DataFrame(chart_data), chart_data, plan_md, exec1_md, exec2_md, summary_md
|
| 506 |
|
| 507 |
# 检查是否达到目标
|
| 508 |
if current_score >= target:
|
|
|
|
| 511 |
time.sleep(0.3)
|
| 512 |
|
| 513 |
final_status = f"状态: 任务完成\n最终分数: {current_score:.2f}\n总迭代次数: {len(chart_data)}"
|
| 514 |
+
yield final_status, pd.DataFrame(chart_data), chart_data, plan_md, exec1_md, exec2_md, summary_md
|
| 515 |
|
| 516 |
run_btn.click(
|
| 517 |
fn=run_task,
|
| 518 |
inputs=[task_input, max_iterations, target_score],
|
| 519 |
+
outputs=[status_output, score_chart, score_list, plan_output, execute1_output, execute2_output, summary_output]
|
| 520 |
)
|
| 521 |
|
| 522 |
gr.Markdown("""
|