from functools import partial import streamlit as st from streamlit_autorefresh import st_autorefresh from transcription.job_utils import get_existing_jobs 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: st.session_state[f"results_button_{job_data['name']}"] = True st.write(f"Transcription 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"results_button_{job_data['name']}"] = False 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"results_button_{job_data['name']}") other_toggled = any([st.session_state.get(f"results_button_{job['name']}") for job in get_existing_jobs(app_config)]) if other_toggled: for job in get_existing_jobs(app_config): st.session_state[f"results_button_{job['name']}"] = False if is_toggled: return st.button("Show Results", on_click=partial(show_results, job_data)) else: return st.button("Hide Results", on_click=partial(hide_results, job_data)) 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 """ # disable all results for job in get_existing_jobs(app_config): st.session_state[f"results_button_{job['name']}"] = False with container.container(): st.subheader('Task List') existing_jobs = get_existing_jobs(app_config) 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) } ] if len(existing_jobs) == 0: st.write("No tasks available.") else: for i, job in enumerate(existing_jobs): cols = st.columns(len(column_config)) for j, col in enumerate(column_config): cols[j].write(col["name"]) with cols[j]: col["render_func"](job)