first 'working' version
This commit is contained in:
+50
-20
@@ -4,7 +4,8 @@ import streamlit as st
|
||||
from streamlit_autorefresh import st_autorefresh
|
||||
|
||||
|
||||
from transcription.job_utils import get_existing_jobs
|
||||
from transcription.job_utils import get_existing_jobs, remove_job
|
||||
|
||||
|
||||
def show_results(job_data: dict):
|
||||
"""
|
||||
@@ -15,9 +16,12 @@ def show_results(job_data: dict):
|
||||
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']}")
|
||||
# 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):
|
||||
"""
|
||||
@@ -25,7 +29,7 @@ def hide_results(job_data: dict):
|
||||
:param job_data: job data
|
||||
:return: None
|
||||
"""
|
||||
st.session_state[f"results_button_{job_data['name']}"] = False
|
||||
st.session_state[f"shown_result"] = None
|
||||
|
||||
def results_button(job_data: dict, app_config: dict):
|
||||
"""
|
||||
@@ -34,16 +38,33 @@ def results_button(job_data: dict, app_config: dict):
|
||||
: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)])
|
||||
# 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()
|
||||
|
||||
|
||||
|
||||
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):
|
||||
@@ -54,15 +75,11 @@ def render_task_list(container, app_config: dict):
|
||||
:return: None
|
||||
"""
|
||||
|
||||
# disable all results
|
||||
for job in get_existing_jobs(app_config):
|
||||
st.session_state[f"results_button_{job['name']}"] = False
|
||||
existing_jobs = get_existing_jobs(app_config)
|
||||
|
||||
with container.container():
|
||||
st.subheader('Task List')
|
||||
|
||||
existing_jobs = get_existing_jobs(app_config)
|
||||
|
||||
column_config = [
|
||||
{
|
||||
"name": "Name",
|
||||
@@ -79,19 +96,32 @@ def render_task_list(container, app_config: dict):
|
||||
{
|
||||
"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):
|
||||
cols[j].write(col["name"])
|
||||
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)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user