feat: add case demo module and streamline Model assets
This commit is contained in:
@@ -10,6 +10,8 @@ from analysis_functions import (
|
||||
frequency_domain_analysis,
|
||||
root_locus_analysis
|
||||
)
|
||||
# ===== 新增:算例演示模块函数导入 =====
|
||||
from case_demo_functions import run_case_demo
|
||||
from chatbot import chat_with_ai
|
||||
from user_stats import get_online_status_html, update_user_activity
|
||||
from ui_components import (
|
||||
@@ -17,6 +19,7 @@ from ui_components import (
|
||||
create_time_domain_tab,
|
||||
create_frequency_domain_tab,
|
||||
create_root_locus_tab,
|
||||
create_case_demo_tab,
|
||||
create_chatbot_tab
|
||||
)
|
||||
|
||||
@@ -59,7 +62,10 @@ with gr.Blocks(title="自动控制理论学习网站 - AI+数智平台", css=cus
|
||||
freq_domain_ui = create_frequency_domain_tab()
|
||||
with gr.TabItem("🎯 根轨迹 (Root Locus)", id=2):
|
||||
root_locus_ui = create_root_locus_tab()
|
||||
with gr.TabItem("🤖 智能问答 (Q&A)", id=3):
|
||||
# ===== 新增:算例演示 Tab(位于根轨迹与智能问答之间) =====
|
||||
with gr.TabItem("🧪 算例演示 (Case Demo)", id=3):
|
||||
case_demo_ui = create_case_demo_tab()
|
||||
with gr.TabItem("🤖 智能问答 (Q&A)", id=4):
|
||||
chatbot_ui = create_chatbot_tab()
|
||||
|
||||
# 2. 绑定事件逻辑
|
||||
@@ -144,6 +150,41 @@ with gr.Blocks(title="自动控制理论学习网站 - AI+数智平台", css=cus
|
||||
num_input.change(fn=update_all_on_tf_change, inputs=tf_change_inputs, outputs=tf_change_outputs)
|
||||
den_input.change(fn=update_all_on_tf_change, inputs=tf_change_inputs, outputs=tf_change_outputs)
|
||||
|
||||
# ===== 新增:算例演示事件包装器 =====
|
||||
def run_case_demo_wrapper(sim_time, dt, initial_soc, initial_engine_power, profile, rpm_scale, load_scale, sid):
|
||||
update_user_activity(sid)
|
||||
fig, summary, table_data = run_case_demo(
|
||||
sim_time_s=sim_time,
|
||||
dt=dt,
|
||||
initial_soc_pct=initial_soc,
|
||||
initial_engine_power_kw=initial_engine_power,
|
||||
profile_name=profile,
|
||||
rpm_scale=rpm_scale,
|
||||
load_scale=load_scale
|
||||
)
|
||||
return fig, summary, table_data, get_online_status_html()
|
||||
|
||||
# ===== 新增:算例演示按钮事件绑定 =====
|
||||
case_demo_ui["run_button"].click(
|
||||
fn=run_case_demo_wrapper,
|
||||
inputs=[
|
||||
case_demo_ui["sim_time"],
|
||||
case_demo_ui["dt"],
|
||||
case_demo_ui["initial_soc"],
|
||||
case_demo_ui["initial_engine_power"],
|
||||
case_demo_ui["profile"],
|
||||
case_demo_ui["rpm_scale"],
|
||||
case_demo_ui["load_scale"],
|
||||
session_id
|
||||
],
|
||||
outputs=[
|
||||
case_demo_ui["plot"],
|
||||
case_demo_ui["summary"],
|
||||
case_demo_ui["table"],
|
||||
online_counter
|
||||
]
|
||||
)
|
||||
|
||||
# --- 聊天机器人事件 ---
|
||||
async def chat_wrapper(message, history, sid):
|
||||
update_user_activity(sid)
|
||||
|
||||
Reference in New Issue
Block a user