128 lines
3.8 KiB
Python
128 lines
3.8 KiB
Python
from functools import partial
|
|
|
|
import streamlit as st
|
|
from streamlit_autorefresh import st_autorefresh
|
|
|
|
|
|
from transcription.job_utils import get_existing_jobs, remove_job
|
|
|
|
|
|
def show_results(job_data: dict):
|
|
"""
|
|
Show the results of a job
|
|
:param job_data: job data
|
|
:return: None
|
|
"""
|
|
if job_data is None:
|
|
return
|
|
else:
|
|
# print("showing results")
|
|
# st.session_state[f"shown_result"] = job_data['name']
|
|
# st.write(f"Transcription Results for job {job_data['name']}")
|
|
# st.write(f"Output: {job_data['output']}")
|
|
with st.popover("Transcription Results", f"Results for job {job_data['name']}"):
|
|
st.write(f"Output: {job_data['output']}")
|
|
|
|
def hide_results(job_data: dict):
|
|
"""
|
|
Hide the results of a job
|
|
:param job_data: job data
|
|
:return: None
|
|
"""
|
|
st.session_state[f"shown_result"] = None
|
|
|
|
def results_button(job_data: dict, app_config: dict):
|
|
"""
|
|
Show the results of a job
|
|
:param job_data: job data
|
|
:param app_config: app configuration
|
|
:return: None
|
|
"""
|
|
# is_toggled = st.session_state.get(f"shown_result") == job_data['name']
|
|
#
|
|
# if is_toggled:
|
|
# return st.button("Hide Results", on_click=partial(hide_results, job_data), key=f"hide_{job_data['name']}")
|
|
# else:
|
|
# return st.button("Show Results", on_click=partial(show_results, job_data), key=f"show_{job_data['name']}")
|
|
|
|
with st.popover("Show Results"):
|
|
st.markdown("Results")
|
|
st.write(job_data['output'])
|
|
|
|
@st.dialog("Are you sure?")
|
|
def delete_task(job_data: dict, app_config: dict):
|
|
"""
|
|
Delete a task
|
|
:param job_data: job data
|
|
:param app_config: app configuration
|
|
:return: None
|
|
"""
|
|
st.write(f"Are you sure you want to delete task {job_data['name']}?")
|
|
if st.button("Yes"):
|
|
remove_job(job_data['name'], app_config)
|
|
st.success(f"Task {job_data['name']} deleted.")
|
|
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
def render_task_list(container, app_config: dict):
|
|
"""
|
|
Render the task list page
|
|
:param container: container object to place the content in
|
|
:param app_config: app configuration
|
|
:return: None
|
|
"""
|
|
|
|
existing_jobs = get_existing_jobs(app_config)
|
|
|
|
with container.container():
|
|
st.subheader('Task List')
|
|
|
|
column_config = [
|
|
{
|
|
"name": "Name",
|
|
"render_func": lambda x: st.markdown(f"**{x['name']}**")
|
|
},
|
|
{
|
|
"name": "Progress",
|
|
"render_func": lambda x: st.progress(x["progress"]) if x["progress"] < 100 else st.markdown(" -- ")
|
|
},
|
|
{
|
|
"name": "Status",
|
|
"render_func": lambda x: st.markdown("Completed") if x["completed"] else st.markdown("Processing" if x["processing"] else "Pending")
|
|
},
|
|
{
|
|
"name": "Output",
|
|
"render_func": lambda x: results_button(x, app_config)
|
|
},
|
|
{
|
|
"name": "Actions",
|
|
"render_func": lambda x: st.button("Delete", on_click=partial(delete_task, x, app_config), key=f"delete_{x['name']}")
|
|
}
|
|
]
|
|
|
|
if len(existing_jobs) == 0:
|
|
st.write("No tasks available.")
|
|
else:
|
|
# display header
|
|
cols = st.columns(len(column_config))
|
|
for i, col in enumerate(column_config):
|
|
with cols[i]:
|
|
st.write(col["name"])
|
|
for i, job in enumerate(existing_jobs):
|
|
cols = st.columns(len(column_config))
|
|
for j, col in enumerate(column_config):
|
|
with cols[j]:
|
|
col["render_func"](job)
|
|
|
|
def update_job_list():
|
|
nonlocal existing_jobs
|
|
existing_jobs = get_existing_jobs(app_config)
|
|
|
|
st.button("Refresh", on_click=update_job_list)
|
|
|
|
|
|
|