Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
# ui_components.py | |
# Gradio界面相关和辅助函数 | |
import gradio as gr | |
import os | |
from config import SCENE_CONFIGS, EPISODE_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", [])) | |
glb_path = config.get("glb_path", "") | |
markdown = f"**{desc}** \nPlaces Included: {objects}" | |
# Validate if file path exists | |
if not os.path.exists(glb_path): | |
return markdown, None | |
return markdown, glb_path | |
def update_episode_display(scene: str, episode: str): | |
config = SCENE_CONFIGS.get(scene, {}) | |
scene_name = config.get("scene_name", scene) # 使用配置中的scene_name | |
episode_id = int(episode[-1]) | |
image_path = os.path.join("scene_assets", f"{scene_name}_{episode_id-1}.jpg") | |
# Validate if file path exists | |
if os.path.exists(image_path): | |
return image_path | |
else: | |
# Fallback to preview_image if episode image doesn't exist | |
fallback_path = config.get("preview_image", None) | |
return fallback_path | |
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) | |