Upload folder using huggingface_hub
Browse files- home.py +54 -37
- plot_helper.py +24 -1
- ui.py +5 -1
home.py
CHANGED
|
@@ -21,7 +21,9 @@ from plot_helper import (
|
|
| 21 |
NUM_COLS,
|
| 22 |
build_trend_figure,
|
| 23 |
render_vitals_plot_layout,
|
|
|
|
| 24 |
reset_trends,
|
|
|
|
| 25 |
update_trends,
|
| 26 |
)
|
| 27 |
from ui import (
|
|
@@ -40,6 +42,7 @@ from ui import (
|
|
| 40 |
render_logo_small,
|
| 41 |
save_vitals_readings,
|
| 42 |
show_component,
|
|
|
|
| 43 |
show_no_data_found_if_none,
|
| 44 |
)
|
| 45 |
|
|
@@ -615,41 +618,48 @@ def build_home_page(
|
|
| 615 |
"Save Readings", variant="huggingface", scale=0
|
| 616 |
)
|
| 617 |
save_vitals_status = gr.Markdown()
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 653 |
with gr.Tab("🧪 Tests", id=2):
|
| 654 |
reports_df = gr.DataFrame(
|
| 655 |
headers=[
|
|
@@ -858,6 +868,8 @@ def build_home_page(
|
|
| 858 |
)
|
| 859 |
else:
|
| 860 |
(*trends, page, page_info, prev_btn, next_btn) = await reset_trends()
|
|
|
|
|
|
|
| 861 |
return (
|
| 862 |
None,
|
| 863 |
"⚠ No patient selected",
|
|
@@ -875,8 +887,8 @@ def build_home_page(
|
|
| 875 |
headers=["patient_id"],
|
| 876 |
value=[],
|
| 877 |
),
|
| 878 |
-
|
| 879 |
-
|
| 880 |
*trends,
|
| 881 |
page,
|
| 882 |
page_info,
|
|
@@ -960,6 +972,11 @@ def build_home_page(
|
|
| 960 |
inputs=[test_names_state],
|
| 961 |
outputs=[no_trends_message, trends_pagination_container],
|
| 962 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 963 |
|
| 964 |
add_patient_btn.click(close_side_bar, outputs=[sheami_sidebar]).then(
|
| 965 |
clear_component, outputs=[add_out]
|
|
|
|
| 21 |
NUM_COLS,
|
| 22 |
build_trend_figure,
|
| 23 |
render_vitals_plot_layout,
|
| 24 |
+
reset_latest_vitals_labels,
|
| 25 |
reset_trends,
|
| 26 |
+
reset_vitals_plots,
|
| 27 |
update_trends,
|
| 28 |
)
|
| 29 |
from ui import (
|
|
|
|
| 42 |
render_logo_small,
|
| 43 |
save_vitals_readings,
|
| 44 |
show_component,
|
| 45 |
+
show_no_data_found_if_dataframe_empty,
|
| 46 |
show_no_data_found_if_none,
|
| 47 |
)
|
| 48 |
|
|
|
|
| 618 |
"Save Readings", variant="huggingface", scale=0
|
| 619 |
)
|
| 620 |
save_vitals_status = gr.Markdown()
|
| 621 |
+
no_vitals_message = empty_state_component(
|
| 622 |
+
message="📊 No vitals recorded yet. Please add your first entry to begin tracking."
|
| 623 |
+
)
|
| 624 |
+
|
| 625 |
+
with gr.Column(visible=False) as vitals_container:
|
| 626 |
+
# Latest Vitals
|
| 627 |
+
gr.Markdown("## Vitals - Latest")
|
| 628 |
+
gr.Markdown("---")
|
| 629 |
+
with gr.Row():
|
| 630 |
+
latest_vitals_cards = [
|
| 631 |
+
gr.Label(visible=False) for _ in range(20)
|
| 632 |
+
]
|
| 633 |
+
with gr.Row():
|
| 634 |
+
# Historical Vitals
|
| 635 |
+
with gr.Column(scale=1):
|
| 636 |
+
gr.Markdown("## Vitals - History")
|
| 637 |
+
gr.Markdown("---")
|
| 638 |
+
vitals_df = gr.DataFrame(
|
| 639 |
+
headers=[
|
| 640 |
+
"Date",
|
| 641 |
+
"Name",
|
| 642 |
+
"Value",
|
| 643 |
+
"Unit",
|
| 644 |
+
"AI Status",
|
| 645 |
+
],
|
| 646 |
+
interactive=False,
|
| 647 |
+
)
|
| 648 |
+
with gr.Column(scale=2):
|
| 649 |
+
gr.Markdown("## Vitals - Trends")
|
| 650 |
+
gr.Markdown("---")
|
| 651 |
+
vitals_plots = []
|
| 652 |
+
rows = math.ceil(
|
| 653 |
+
20 / 2
|
| 654 |
+
) # default num_cols_per_row columns per row
|
| 655 |
+
for r in range(rows):
|
| 656 |
+
with gr.Row():
|
| 657 |
+
for c in range(
|
| 658 |
+
2
|
| 659 |
+
): # num_cols_per_row cols per row
|
| 660 |
+
vitals_plots.append(
|
| 661 |
+
gr.Plot(visible=True)
|
| 662 |
+
)
|
| 663 |
with gr.Tab("🧪 Tests", id=2):
|
| 664 |
reports_df = gr.DataFrame(
|
| 665 |
headers=[
|
|
|
|
| 868 |
)
|
| 869 |
else:
|
| 870 |
(*trends, page, page_info, prev_btn, next_btn) = await reset_trends()
|
| 871 |
+
(*vitals_plots,) = reset_vitals_plots()
|
| 872 |
+
(*vitals_labels,) = reset_latest_vitals_labels()
|
| 873 |
return (
|
| 874 |
None,
|
| 875 |
"⚠ No patient selected",
|
|
|
|
| 887 |
headers=["patient_id"],
|
| 888 |
value=[],
|
| 889 |
),
|
| 890 |
+
*vitals_labels,
|
| 891 |
+
*vitals_plots,
|
| 892 |
*trends,
|
| 893 |
page,
|
| 894 |
page_info,
|
|
|
|
| 972 |
inputs=[test_names_state],
|
| 973 |
outputs=[no_trends_message, trends_pagination_container],
|
| 974 |
)
|
| 975 |
+
vitals_df.change(
|
| 976 |
+
show_no_data_found_if_dataframe_empty,
|
| 977 |
+
inputs=[vitals_df],
|
| 978 |
+
outputs=[no_vitals_message, vitals_container],
|
| 979 |
+
)
|
| 980 |
|
| 981 |
add_patient_btn.click(close_side_bar, outputs=[sheami_sidebar]).then(
|
| 982 |
clear_component, outputs=[add_out]
|
plot_helper.py
CHANGED
|
@@ -178,6 +178,29 @@ async def reset_trends():
|
|
| 178 |
)
|
| 179 |
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
def _to_jsonable_dt(x):
|
| 182 |
if isinstance(x, pd.Timestamp):
|
| 183 |
return x.to_pydatetime() # or x.isoformat()
|
|
@@ -242,7 +265,7 @@ async def render_vitals_plot_layout(patient_id):
|
|
| 242 |
margin=dict(l=30, r=20, t=40, b=30),
|
| 243 |
)
|
| 244 |
figures.append(empty_fig)
|
| 245 |
-
|
| 246 |
plots = []
|
| 247 |
for fig in figures:
|
| 248 |
plots.append(gr.Plot(value=fig, label=fig.layout.title.text))
|
|
|
|
| 178 |
)
|
| 179 |
|
| 180 |
|
| 181 |
+
def reset_vitals_plots():
|
| 182 |
+
"""
|
| 183 |
+
Clears all vitals plots and resets page info.
|
| 184 |
+
Returns a list of gr.update(...) objects matching the outputs of update_trends.
|
| 185 |
+
"""
|
| 186 |
+
outputs = []
|
| 187 |
+
for _ in range(20):
|
| 188 |
+
outputs.append(gr.update(visible=False, value=None, label=""))
|
| 189 |
+
|
| 190 |
+
return (*outputs,)
|
| 191 |
+
|
| 192 |
+
def reset_latest_vitals_labels():
|
| 193 |
+
"""
|
| 194 |
+
Clears all latest vitals labels and resets page info.
|
| 195 |
+
Returns a list of gr.update(...) objects matching the outputs of update_trends.
|
| 196 |
+
"""
|
| 197 |
+
outputs = []
|
| 198 |
+
for _ in range(20):
|
| 199 |
+
outputs.append(gr.update(visible=False, value=None, label=""))
|
| 200 |
+
|
| 201 |
+
return (*outputs,)
|
| 202 |
+
|
| 203 |
+
|
| 204 |
def _to_jsonable_dt(x):
|
| 205 |
if isinstance(x, pd.Timestamp):
|
| 206 |
return x.to_pydatetime() # or x.isoformat()
|
|
|
|
| 265 |
margin=dict(l=30, r=20, t=40, b=30),
|
| 266 |
)
|
| 267 |
figures.append(empty_fig)
|
| 268 |
+
|
| 269 |
plots = []
|
| 270 |
for fig in figures:
|
| 271 |
plots.append(gr.Plot(value=fig, label=fig.layout.title.text))
|
ui.py
CHANGED
|
@@ -956,9 +956,13 @@ def hide_tabs_if_no_patient_selected(patient_id):
|
|
| 956 |
|
| 957 |
|
| 958 |
def show_no_data_found_if_none(data):
|
| 959 |
-
print("show_no_data_found_if_none = data = ", data)
|
| 960 |
if not data:
|
| 961 |
return show_component(), hide_component() # no data found # actual component
|
| 962 |
else:
|
| 963 |
return hide_component(), show_component() # no data found # actual component
|
| 964 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 956 |
|
| 957 |
|
| 958 |
def show_no_data_found_if_none(data):
|
|
|
|
| 959 |
if not data:
|
| 960 |
return show_component(), hide_component() # no data found # actual component
|
| 961 |
else:
|
| 962 |
return hide_component(), show_component() # no data found # actual component
|
| 963 |
|
| 964 |
+
def show_no_data_found_if_dataframe_empty(data : pd.DataFrame):
|
| 965 |
+
if data.empty:
|
| 966 |
+
return show_component(), hide_component() # no data found # actual component
|
| 967 |
+
else:
|
| 968 |
+
return hide_component(), show_component() # no data found # actual component
|