feat: 新增模块化Streamlit本地工具箱
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
from datetime import datetime
|
||||
import streamlit as st
|
||||
from toolbox.tasks import ACTIVE, KINDS, LABELS, list_tasks, stop_task, tail_log
|
||||
|
||||
|
||||
@st.fragment(run_every="2s")
|
||||
def task_panel(task_id=None, recent=False):
|
||||
tasks = list_tasks()
|
||||
if task_id:
|
||||
tasks = [task for task in tasks if task["id"] == task_id]
|
||||
elif recent:
|
||||
tasks = tasks[:1]
|
||||
if not tasks:
|
||||
st.info("暂无任务。启动工具后可在这里查看进度和成果。")
|
||||
return
|
||||
for task in tasks:
|
||||
with st.container(border=True):
|
||||
st.markdown(f"**{KINDS[task['kind']]} · {LABELS[task['status']]}**")
|
||||
st.caption(f"{task['id']} · {datetime.fromtimestamp(task['created']):%Y-%m-%d %H:%M:%S}")
|
||||
st.write(task["message"])
|
||||
if task.get("total"):
|
||||
ratio = min(task.get("done", 0) / task["total"], 1.0)
|
||||
st.progress(ratio, text=f"{task.get('done', 0)} / {task['total']}")
|
||||
elif task.get("done"):
|
||||
st.write(f"已处理 {task['done']} 个坐标")
|
||||
if task.get("counts"):
|
||||
st.write(task["counts"])
|
||||
if task["status"] in ACTIVE:
|
||||
if task["stop_requested"]:
|
||||
st.info("已请求停止,等待当前批次或正在进行的请求完成写入。")
|
||||
elif st.button("停止任务", key=f"stop_{task['id']}"):
|
||||
stop_task(task["id"])
|
||||
st.rerun(scope="fragment")
|
||||
st.caption(f"成果目录:{task['output']}")
|
||||
with st.expander("运行日志", expanded=bool(task_id)):
|
||||
st.code(tail_log(task["directory"]), language="text")
|
||||
|
||||
|
||||
def show_started(task_id):
|
||||
st.session_state["last_task"] = task_id
|
||||
st.success("任务已启动。可以切换页面,进度和结果保存在任务中心。")
|
||||
Reference in New Issue
Block a user