Spaces:
Sleeping
Sleeping
Merge pull request #5 from ginidok/huggingface-deploy-action
Browse files
cdss.py
CHANGED
|
@@ -277,7 +277,8 @@ def process_and_update(
|
|
| 277 |
return (
|
| 278 |
asdict(ps),
|
| 279 |
*state_to_panels(ps),
|
| 280 |
-
str(ps.labs),
|
|
|
|
| 281 |
interpretation,
|
| 282 |
history_df,
|
| 283 |
df_for_table,
|
|
@@ -293,11 +294,26 @@ def process_and_update(
|
|
| 293 |
|
| 294 |
def state_to_panels(state: PatientState) -> Tuple:
|
| 295 |
v = state.vitals
|
| 296 |
-
return (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
|
| 298 |
|
| 299 |
-
def inject_scenario(tag: str, cdss_on: bool):
|
| 300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
|
| 302 |
|
| 303 |
def manual_edit(
|
|
@@ -310,6 +326,7 @@ def manual_edit(
|
|
| 310 |
notes,
|
| 311 |
labs_text,
|
| 312 |
cdss_on,
|
|
|
|
| 313 |
current_state,
|
| 314 |
history_df,
|
| 315 |
historic_text,
|
|
@@ -320,7 +337,7 @@ def manual_edit(
|
|
| 320 |
labs = {"raw": labs_text}
|
| 321 |
ps = PatientState(
|
| 322 |
current_state.get("scenario", "Manual"),
|
| 323 |
-
|
| 324 |
notes,
|
| 325 |
labs,
|
| 326 |
Vitals(int(sbp), int(dbp), int(hr), int(rr), float(temp_c), int(spo2)),
|
|
@@ -411,6 +428,9 @@ with gr.Blocks(
|
|
| 411 |
labs_show = gr.Textbox(label="Labs (Parsed)", interactive=False)
|
| 412 |
with gr.Column(scale=1):
|
| 413 |
with gr.Group():
|
|
|
|
|
|
|
|
|
|
| 414 |
sbp = gr.Number(label="SBP")
|
| 415 |
dbp = gr.Number(label="DBP")
|
| 416 |
hr = gr.Number(label="HR")
|
|
@@ -431,6 +451,7 @@ with gr.Blocks(
|
|
| 431 |
ui_outputs = [
|
| 432 |
state,
|
| 433 |
scenario_lbl,
|
|
|
|
| 434 |
notes,
|
| 435 |
sbp,
|
| 436 |
dbp,
|
|
@@ -438,6 +459,7 @@ with gr.Blocks(
|
|
| 438 |
rr,
|
| 439 |
temp_c,
|
| 440 |
spo2,
|
|
|
|
| 441 |
labs_show,
|
| 442 |
interpretation,
|
| 443 |
history_df,
|
|
@@ -461,6 +483,7 @@ with gr.Blocks(
|
|
| 461 |
notes,
|
| 462 |
labs_text,
|
| 463 |
cdss_toggle,
|
|
|
|
| 464 |
state,
|
| 465 |
history_df,
|
| 466 |
historic_text,
|
|
@@ -482,7 +505,7 @@ with gr.Blocks(
|
|
| 482 |
btn_C3,
|
| 483 |
],
|
| 484 |
):
|
| 485 |
-
btn.click(inject_scenario, [gr.State(tag), cdss_toggle], ui_outputs)
|
| 486 |
|
| 487 |
csv_outputs = [history_df, df_view, bp_plot, hr_plot, rr_plot, temp_plot, spo2_plot]
|
| 488 |
csv_file.change(load_csv, [csv_file, history_df], csv_outputs)
|
|
|
|
| 277 |
return (
|
| 278 |
asdict(ps),
|
| 279 |
*state_to_panels(ps),
|
| 280 |
+
str(ps.labs), # For labs_text
|
| 281 |
+
str(ps.labs), # For labs_show
|
| 282 |
interpretation,
|
| 283 |
history_df,
|
| 284 |
df_for_table,
|
|
|
|
| 294 |
|
| 295 |
def state_to_panels(state: PatientState) -> Tuple:
|
| 296 |
v = state.vitals
|
| 297 |
+
return (
|
| 298 |
+
state.scenario,
|
| 299 |
+
state.patient_type,
|
| 300 |
+
state.notes,
|
| 301 |
+
v.sbp,
|
| 302 |
+
v.dbp,
|
| 303 |
+
v.hr,
|
| 304 |
+
v.rr,
|
| 305 |
+
v.temp_c,
|
| 306 |
+
v.spo2,
|
| 307 |
+
)
|
| 308 |
|
| 309 |
|
| 310 |
+
def inject_scenario(tag: str, cdss_on: bool, history_df: pd.DataFrame, historic_text: str):
|
| 311 |
+
ps = SCENARIOS[tag]()
|
| 312 |
+
if historic_text: # Add a newline if text already exists
|
| 313 |
+
historic_text += f"\n[{datetime.now().strftime('%H:%M:%S')}] Scenario Injected: {ps.scenario}"
|
| 314 |
+
else:
|
| 315 |
+
historic_text = f"[{datetime.now().strftime('%H:%M:%S')}] Scenario Injected: {ps.scenario}"
|
| 316 |
+
return process_and_update(ps, history_df, historic_text, cdss_on)
|
| 317 |
|
| 318 |
|
| 319 |
def manual_edit(
|
|
|
|
| 326 |
notes,
|
| 327 |
labs_text,
|
| 328 |
cdss_on,
|
| 329 |
+
patient_type,
|
| 330 |
current_state,
|
| 331 |
history_df,
|
| 332 |
historic_text,
|
|
|
|
| 337 |
labs = {"raw": labs_text}
|
| 338 |
ps = PatientState(
|
| 339 |
current_state.get("scenario", "Manual"),
|
| 340 |
+
patient_type,
|
| 341 |
notes,
|
| 342 |
labs,
|
| 343 |
Vitals(int(sbp), int(dbp), int(hr), int(rr), float(temp_c), int(spo2)),
|
|
|
|
| 428 |
labs_show = gr.Textbox(label="Labs (Parsed)", interactive=False)
|
| 429 |
with gr.Column(scale=1):
|
| 430 |
with gr.Group():
|
| 431 |
+
patient_type_radio = gr.Radio(
|
| 432 |
+
["Mother", "Neonate", "Gyn"], label="Patient Type", value="Mother"
|
| 433 |
+
)
|
| 434 |
sbp = gr.Number(label="SBP")
|
| 435 |
dbp = gr.Number(label="DBP")
|
| 436 |
hr = gr.Number(label="HR")
|
|
|
|
| 451 |
ui_outputs = [
|
| 452 |
state,
|
| 453 |
scenario_lbl,
|
| 454 |
+
patient_type_radio,
|
| 455 |
notes,
|
| 456 |
sbp,
|
| 457 |
dbp,
|
|
|
|
| 459 |
rr,
|
| 460 |
temp_c,
|
| 461 |
spo2,
|
| 462 |
+
labs_text,
|
| 463 |
labs_show,
|
| 464 |
interpretation,
|
| 465 |
history_df,
|
|
|
|
| 483 |
notes,
|
| 484 |
labs_text,
|
| 485 |
cdss_toggle,
|
| 486 |
+
patient_type_radio,
|
| 487 |
state,
|
| 488 |
history_df,
|
| 489 |
historic_text,
|
|
|
|
| 505 |
btn_C3,
|
| 506 |
],
|
| 507 |
):
|
| 508 |
+
btn.click(inject_scenario, [gr.State(tag), cdss_toggle, history_df, historic_text], ui_outputs)
|
| 509 |
|
| 510 |
csv_outputs = [history_df, df_view, bp_plot, hr_plot, rr_plot, temp_plot, spo2_plot]
|
| 511 |
csv_file.change(load_csv, [csv_file, history_df], csv_outputs)
|