summary / ui_summary.py
Roland Ding
10.9.26.75 updated ui, data, features, and backend
004db8a
import gradio as gr
from utility import *
from application import *
from features import init_app_data, create_md_tables, generate_summary # , add_device, remove_device, get_device
def refresh():
init_app_data()
'''
refresh the literature report.
'''
return create_md_tables(app_data["articles"])
def articles_page():
with gr.Blocks() as tab_page:
gr.Markdown("## Article Lists")
btn_refresh = gr.Button(value="Refresh",variant="primary")
gr.HTML("<hr>")
article_list = gr.Markdown("")
btn_refresh.click(
fn=refresh,
outputs=[article_list]
)
return tab_page
def preference_page():
with gr.Blocks() as tab_page:
render_custom_performance()
render_custom_safety()
return tab_page
def summary_page():
# create a selection box for the user to select the articles
# that they want to include in the summary
with gr.Blocks() as tab_page:
gr.Markdown("## Summary")
gr.HTML("<hr>")
with gr.Row(equal_height=False):
with gr.Column():
article_selection = gr.Dropdown(
label="Select Articles",
choices=list(app_data["articles"].keys()),
info="Select the articles that you want to include in the summary.",
multiselect=True
)
with gr.Column():
gen_button = gr.Button(
label="Generate Summary",
variant="primary",
info="Click to generate the summary."
)
gr.HTML("<hr>")
summary = gr.Markdown("")
gen_button.click(
fn=generate_summary,
inputs=[article_selection],
outputs=[summary]
)
article_selection.change(
fn=lambda value: update_user_preference(value,"articles","summary"),
inputs=[article_selection]
)
return tab_page
def render_custom_performance():
with gr.Blocks():
render_performance_row("Performance Outcome #1",show_header=True)
render_performance_row("Performance Outcome #2")
def render_performance_row(row_name, show_header=False):
with gr.Row():
with gr.Column():
if show_header:
gr.Markdown("### User-Identified Performance Outcomes")
gr.Markdown("<hr>")
with gr.Row():
assessment_step = gr.Radio(
label="Assessment Step",
choices = ["Clinical","Radiologic","Other"],
value = "Clinical")
name = gr.Dropdown(
label=row_name,
choices=defaults[assessment_step.value.lower()],
value=defaults[assessment_step.value.lower()][0],
interactive=True
)
with gr.Column():
if show_header:
gr.Markdown("### Acceptability Criteria")
gr.Markdown("<hr>")
with gr.Row():
replationship = gr.Dropdown(
label="Relationship",
choices = ["Greater than","Less than"])
numeric_value= gr.Textbox(
label="Numeric Value",
placeholder="e.g. 10.0"
)
unit = gr.Dropdown(
label="Units",
choices = defaults["units"])
assessment_step.change(fn=lambda value: update_user_preference(value,"assessment_step",row_name),inputs=[assessment_step],outputs=[name])
name.change(fn=lambda value: update_user_preference(value,"name",row_name),inputs=[name])
replationship.change(fn=lambda value: update_user_preference(value,"relationship",row_name),inputs=[replationship])
numeric_value.change(fn=lambda value: update_user_preference(value,"numeric value",row_name),inputs=[numeric_value])
unit.change(fn=lambda value: update_user_preference(value,"unit",row_name),inputs=[unit])
def render_custom_safety():
with gr.Blocks():
render_safety_row("Safety Outcome #1",show_header=True)
render_safety_row("Safety Outcome #2")
def render_safety_row(row_name, show_header=False):
with gr.Row():
with gr.Column():
if show_header:
gr.Markdown("### User-Identified Safety Outcomes")
gr.Markdown("<hr>")
with gr.Row():
name = gr.Dropdown(
label=row_name,
choices=defaults["safety"],
value=defaults["safety"][0],
interactive=True
)
with gr.Column():
if show_header:
gr.Markdown("### Acceptability Criteria")
gr.Markdown("<hr>")
with gr.Row():
numeric_value = gr.Textbox(
label="Numeric Value",
placeholder="e.g. 10.0"
)
gr.Label(
value="%",
label="Units")
name.change(fn=lambda value: update_user_preference(value,"name",row_name),inputs=[name])
numeric_value.change(fn=lambda value: update_user_preference(value,"numeric value",row_name),inputs=[numeric_value])
def update_user_preference(value,element,setting):
app_data["user"][setting.lower()][element] = value
print(app_data["user"])
if element == "assessment_step":
return gr.update(
choices=defaults[value.lower()],
value=defaults[value.lower()][0]
)