File size: 1,639 Bytes
ad1357a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# ui_components.py
# Gradio界面相关和辅助函数
import gradio as gr
from config import SCENE_CONFIGS
from logging_utils import read_logs, format_logs_for_display

def update_history_display(history: list) -> list:
    updates = []
    for i in range(10):
        if i < len(history):
            entry = history[i]
            label_text = f"Simulation {i+1}  scene: {entry['scene']}, model: {entry.get('model','')}, mode: {entry.get('mode','')}, prompt: {entry['prompt']}"
            updates.extend([
                gr.update(visible=True),
                gr.update(visible=True, label=label_text, open=False),
                gr.update(value=entry['video_path'], visible=True),
                gr.update(value=f"{entry['timestamp']}")
            ])
        else:
            updates.extend([
                gr.update(visible=False),
                gr.update(visible=False),
                gr.update(value=None, visible=False),
                gr.update(value="")
            ])
    return updates

def update_scene_display(scene: str):
    config = SCENE_CONFIGS.get(scene, {})
    desc = config.get("description", "No Description")
    objects = "、".join(config.get("objects", []))
    image = config.get("preview_image", None)
    markdown = f"**{desc}**  \nPlaces Included: {objects}"
    return markdown, image

def get_scene_instruction(scene: str):
    """根据场景获取默认指令"""
    config = SCENE_CONFIGS.get(scene, {})
    return config.get("default_instruction", "")

def update_log_display():
    logs = read_logs()
    return format_logs_for_display(logs)