Spaces:
Runtime error
Runtime error
Jesse Liu commited on
Commit ·
88cb0d9
1
Parent(s): a25d70c
Sync latest app + data (clinician groups, jsonl)
Browse files- chatgpt.py +84 -70
chatgpt.py
CHANGED
|
@@ -1035,19 +1035,20 @@ with gr.Blocks() as app:
|
|
| 1035 |
clinician_choices = sorted(eval_groups.keys())
|
| 1036 |
eval_group_dropdown = gr.Dropdown(
|
| 1037 |
choices=clinician_choices,
|
| 1038 |
-
label="Select
|
| 1039 |
value=None,
|
| 1040 |
interactive=True
|
| 1041 |
)
|
| 1042 |
group_info_display = gr.Markdown(
|
| 1043 |
-
value="
|
| 1044 |
visible=True
|
| 1045 |
)
|
| 1046 |
|
| 1047 |
option_titles = [option["title"] for option in options]
|
| 1048 |
|
| 1049 |
# Single patient selector (one admission per patient)
|
| 1050 |
-
|
|
|
|
| 1051 |
eval_patient_radio = gr.Radio(
|
| 1052 |
choices=patient_ids,
|
| 1053 |
label="Choose Patient",
|
|
@@ -1075,6 +1076,7 @@ with gr.Blocks() as app:
|
|
| 1075 |
)
|
| 1076 |
|
| 1077 |
# Patient Data Display (based on selected sample)
|
|
|
|
| 1078 |
with gr.Accordion("Patient raw data from EHR", open=True):
|
| 1079 |
patient_input_display = gr.HTML(
|
| 1080 |
value="Select a patient sample to view data",
|
|
@@ -1083,20 +1085,21 @@ with gr.Blocks() as app:
|
|
| 1083 |
)
|
| 1084 |
|
| 1085 |
# AI Summary Display (scrollable)
|
|
|
|
| 1086 |
with gr.Accordion("🤖 AI Generated Summary", open=True):
|
| 1087 |
ai_summary_display = gr.Markdown(
|
| 1088 |
value="Select a patient to view AI summary...",
|
| 1089 |
label="AI Generated Summary",
|
| 1090 |
elem_id="ai_summary_display"
|
| 1091 |
)
|
| 1092 |
-
timestamp_display = gr.Markdown(value="", label="Timestamp")
|
| 1093 |
|
| 1094 |
# Overall Quality Rating
|
|
|
|
| 1095 |
overall_rating = gr.Slider(
|
| 1096 |
minimum=1,
|
| 1097 |
maximum=10,
|
| 1098 |
step=1,
|
| 1099 |
-
label="Overall Quality
|
| 1100 |
value=0
|
| 1101 |
)
|
| 1102 |
gr.Markdown("*A global assessment integrating all dimensions (accuracy, completeness, relevance...)*")
|
|
@@ -1104,95 +1107,107 @@ with gr.Blocks() as app:
|
|
| 1104 |
# Core Evaluation Dimensions
|
| 1105 |
gr.Markdown("### Core Evaluation Dimensions")
|
| 1106 |
with gr.Row():
|
| 1107 |
-
|
| 1108 |
-
|
| 1109 |
-
|
| 1110 |
-
|
| 1111 |
-
|
| 1112 |
-
|
| 1113 |
-
|
| 1114 |
-
|
| 1115 |
-
|
| 1116 |
-
|
| 1117 |
-
|
| 1118 |
-
|
| 1119 |
-
|
| 1120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1121 |
|
| 1122 |
with gr.Row():
|
| 1123 |
-
|
| 1124 |
-
|
| 1125 |
-
|
| 1126 |
-
|
| 1127 |
-
|
| 1128 |
-
|
| 1129 |
-
|
| 1130 |
-
|
| 1131 |
-
|
| 1132 |
-
|
| 1133 |
-
|
| 1134 |
-
|
| 1135 |
-
|
| 1136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1137 |
|
| 1138 |
with gr.Row():
|
| 1139 |
-
|
| 1140 |
-
|
| 1141 |
-
|
| 1142 |
-
|
| 1143 |
-
|
| 1144 |
-
|
| 1145 |
-
|
| 1146 |
-
|
| 1147 |
-
|
| 1148 |
-
|
| 1149 |
-
|
| 1150 |
-
|
| 1151 |
-
|
| 1152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1153 |
|
| 1154 |
# Critical Error Assessment
|
| 1155 |
gr.Markdown("### Critical Error Assessment")
|
| 1156 |
-
gr.Markdown("*
|
| 1157 |
with gr.Row():
|
| 1158 |
hallucination = gr.Slider(
|
| 1159 |
minimum=1,
|
| 1160 |
maximum=10,
|
| 1161 |
step=1,
|
| 1162 |
-
label="Hallucination
|
| 1163 |
value=0
|
| 1164 |
)
|
| 1165 |
critical_omission = gr.Slider(
|
| 1166 |
minimum=1,
|
| 1167 |
maximum=10,
|
| 1168 |
step=1,
|
| 1169 |
-
label="Critical Omission
|
| 1170 |
value=0
|
| 1171 |
)
|
| 1172 |
|
| 1173 |
-
# Detailed feedback
|
| 1174 |
-
feedback_text = gr.Textbox(
|
| 1175 |
-
label="Overall Feedback",
|
| 1176 |
-
placeholder="Please provide specific feedback about the AI summary...",
|
| 1177 |
-
lines=3
|
| 1178 |
-
)
|
| 1179 |
-
|
| 1180 |
# Hallucination and Critical Omission Comments
|
| 1181 |
-
gr.Markdown("### Point Out Issues")
|
| 1182 |
with gr.Row():
|
| 1183 |
hallucination_comments = gr.Textbox(
|
| 1184 |
label="Hallucination",
|
| 1185 |
-
placeholder="
|
| 1186 |
-
lines=
|
| 1187 |
value=""
|
| 1188 |
)
|
| 1189 |
critical_omission_comments = gr.Textbox(
|
| 1190 |
label="Critical Omission",
|
| 1191 |
-
placeholder="
|
| 1192 |
-
lines=
|
| 1193 |
value=""
|
| 1194 |
)
|
| 1195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1196 |
# Submit evaluation button
|
| 1197 |
submit_eval_button = gr.Button(
|
| 1198 |
"Submit Patient Evaluation",
|
|
@@ -1391,22 +1406,21 @@ with gr.Blocks() as app:
|
|
| 1391 |
|
| 1392 |
def update_patient_eval_display(patient_id, admission_label=None):
|
| 1393 |
"""
|
| 1394 |
-
Return patient input HTML
|
| 1395 |
Single-admission mode: always uses the first (only) record for that patient.
|
| 1396 |
"""
|
| 1397 |
try:
|
| 1398 |
if not patient_id:
|
| 1399 |
-
return "No patient selected", "Select a patient to view AI summary..."
|
| 1400 |
|
| 1401 |
pid = str(patient_id)
|
| 1402 |
if pid not in eval_data_by_patient or not eval_data_by_patient[pid]:
|
| 1403 |
-
return "Patient data not found", "AI summary not found"
|
| 1404 |
|
| 1405 |
# Single admission per patient
|
| 1406 |
first_key = list(eval_data_by_patient[pid].keys())[0]
|
| 1407 |
rec = eval_data_by_patient[pid][first_key]
|
| 1408 |
|
| 1409 |
-
at = rec.get('admittime') or 'None'
|
| 1410 |
summary_text = clean_summary_output(rec.get('summary', '') or 'No summary available')
|
| 1411 |
input_text = rec.get('input_text', '') or 'No input data available'
|
| 1412 |
|
|
@@ -1426,12 +1440,12 @@ with gr.Blocks() as app:
|
|
| 1426 |
'</pre>'
|
| 1427 |
)
|
| 1428 |
# Return raw markdown text; scrolling controlled by CSS on elem_id
|
| 1429 |
-
return input_html, summary_text
|
| 1430 |
except Exception as e:
|
| 1431 |
import traceback
|
| 1432 |
error_msg = f"Error loading patient data: {str(e)}\n{traceback.format_exc()}"
|
| 1433 |
print(f"[ERROR] {error_msg}")
|
| 1434 |
-
return "Error loading data", f"Error: {str(e)}"
|
| 1435 |
|
| 1436 |
# Handle clinician ID selection to filter patient list
|
| 1437 |
if eval_groups:
|
|
@@ -1439,7 +1453,7 @@ with gr.Blocks() as app:
|
|
| 1439 |
"""Filter patient list based on selected clinician ID and auto-fill clinician ID field"""
|
| 1440 |
if not selected_clinician:
|
| 1441 |
filtered_patients = []
|
| 1442 |
-
info_text = "
|
| 1443 |
clinician_id_update = gr.update()
|
| 1444 |
else:
|
| 1445 |
# Directly use selected_clinician as key (no mapping needed)
|
|
@@ -1474,7 +1488,7 @@ with gr.Blocks() as app:
|
|
| 1474 |
eval_patient_radio.change(
|
| 1475 |
fn=on_patient_change,
|
| 1476 |
inputs=[eval_patient_radio],
|
| 1477 |
-
outputs=[patient_input_display, ai_summary_display
|
| 1478 |
)
|
| 1479 |
|
| 1480 |
|
|
|
|
| 1035 |
clinician_choices = sorted(eval_groups.keys())
|
| 1036 |
eval_group_dropdown = gr.Dropdown(
|
| 1037 |
choices=clinician_choices,
|
| 1038 |
+
label="Select your ID to see assigned patient cases",
|
| 1039 |
value=None,
|
| 1040 |
interactive=True
|
| 1041 |
)
|
| 1042 |
group_info_display = gr.Markdown(
|
| 1043 |
+
value="",
|
| 1044 |
visible=True
|
| 1045 |
)
|
| 1046 |
|
| 1047 |
option_titles = [option["title"] for option in options]
|
| 1048 |
|
| 1049 |
# Single patient selector (one admission per patient)
|
| 1050 |
+
# Default to empty list - patients will be shown only after clinician selects their ID
|
| 1051 |
+
patient_ids = [] if eval_groups else patient_ids_list
|
| 1052 |
eval_patient_radio = gr.Radio(
|
| 1053 |
choices=patient_ids,
|
| 1054 |
label="Choose Patient",
|
|
|
|
| 1076 |
)
|
| 1077 |
|
| 1078 |
# Patient Data Display (based on selected sample)
|
| 1079 |
+
gr.Markdown("### Patient Raw Data from EHR")
|
| 1080 |
with gr.Accordion("Patient raw data from EHR", open=True):
|
| 1081 |
patient_input_display = gr.HTML(
|
| 1082 |
value="Select a patient sample to view data",
|
|
|
|
| 1085 |
)
|
| 1086 |
|
| 1087 |
# AI Summary Display (scrollable)
|
| 1088 |
+
gr.Markdown("### AI Generated Summary")
|
| 1089 |
with gr.Accordion("🤖 AI Generated Summary", open=True):
|
| 1090 |
ai_summary_display = gr.Markdown(
|
| 1091 |
value="Select a patient to view AI summary...",
|
| 1092 |
label="AI Generated Summary",
|
| 1093 |
elem_id="ai_summary_display"
|
| 1094 |
)
|
|
|
|
| 1095 |
|
| 1096 |
# Overall Quality Rating
|
| 1097 |
+
gr.Markdown("### Overall evaluation")
|
| 1098 |
overall_rating = gr.Slider(
|
| 1099 |
minimum=1,
|
| 1100 |
maximum=10,
|
| 1101 |
step=1,
|
| 1102 |
+
label="Overall Quality",
|
| 1103 |
value=0
|
| 1104 |
)
|
| 1105 |
gr.Markdown("*A global assessment integrating all dimensions (accuracy, completeness, relevance...)*")
|
|
|
|
| 1107 |
# Core Evaluation Dimensions
|
| 1108 |
gr.Markdown("### Core Evaluation Dimensions")
|
| 1109 |
with gr.Row():
|
| 1110 |
+
with gr.Column():
|
| 1111 |
+
clinical_accuracy = gr.Slider(
|
| 1112 |
+
minimum=1,
|
| 1113 |
+
maximum=10,
|
| 1114 |
+
step=1,
|
| 1115 |
+
label="Clinical Accuracy",
|
| 1116 |
+
value=0
|
| 1117 |
+
)
|
| 1118 |
+
gr.Markdown("*The extent to which the content is factually correct and consistent with the source EHR.*")
|
| 1119 |
+
with gr.Column():
|
| 1120 |
+
completeness_coverage = gr.Slider(
|
| 1121 |
+
minimum=1,
|
| 1122 |
+
maximum=10,
|
| 1123 |
+
step=1,
|
| 1124 |
+
label="Completeness / Coverage",
|
| 1125 |
+
value=0
|
| 1126 |
+
)
|
| 1127 |
+
gr.Markdown("*Whether all information required for a comprehensive preoperative evaluation is included.*")
|
| 1128 |
|
| 1129 |
with gr.Row():
|
| 1130 |
+
with gr.Column():
|
| 1131 |
+
clinical_relevance = gr.Slider(
|
| 1132 |
+
minimum=1,
|
| 1133 |
+
maximum=10,
|
| 1134 |
+
step=1,
|
| 1135 |
+
label="Clinical Relevance",
|
| 1136 |
+
value=0
|
| 1137 |
+
)
|
| 1138 |
+
gr.Markdown("*The degree to which the summary prioritizes information most important for preoperative decision-making.*")
|
| 1139 |
+
with gr.Column():
|
| 1140 |
+
clarity_structure = gr.Slider(
|
| 1141 |
+
minimum=1,
|
| 1142 |
+
maximum=10,
|
| 1143 |
+
step=1,
|
| 1144 |
+
label="Clarity and Structure",
|
| 1145 |
+
value=0
|
| 1146 |
+
)
|
| 1147 |
+
gr.Markdown("*How easily clinicians can understand, navigate, and apply the summary in practice.*")
|
| 1148 |
|
| 1149 |
with gr.Row():
|
| 1150 |
+
with gr.Column():
|
| 1151 |
+
reasoning_risk = gr.Slider(
|
| 1152 |
+
minimum=1,
|
| 1153 |
+
maximum=10,
|
| 1154 |
+
step=1,
|
| 1155 |
+
label="Reasoning / Risk Stratification",
|
| 1156 |
+
value=0
|
| 1157 |
+
)
|
| 1158 |
+
gr.Markdown("*Accurate identification of perioperative risk factors, appropriate interpretation, and required follow-up actions.*")
|
| 1159 |
+
with gr.Column():
|
| 1160 |
+
actionability = gr.Slider(
|
| 1161 |
+
minimum=1,
|
| 1162 |
+
maximum=10,
|
| 1163 |
+
step=1,
|
| 1164 |
+
label="Actionability",
|
| 1165 |
+
value=0
|
| 1166 |
+
)
|
| 1167 |
+
gr.Markdown("*Whether the summary supports clear clinical decisions and next steps.*")
|
| 1168 |
|
| 1169 |
# Critical Error Assessment
|
| 1170 |
gr.Markdown("### Critical Error Assessment")
|
| 1171 |
+
gr.Markdown("*If critical errors were identified, please provide detail information below*")
|
| 1172 |
with gr.Row():
|
| 1173 |
hallucination = gr.Slider(
|
| 1174 |
minimum=1,
|
| 1175 |
maximum=10,
|
| 1176 |
step=1,
|
| 1177 |
+
label="Hallucination",
|
| 1178 |
value=0
|
| 1179 |
)
|
| 1180 |
critical_omission = gr.Slider(
|
| 1181 |
minimum=1,
|
| 1182 |
maximum=10,
|
| 1183 |
step=1,
|
| 1184 |
+
label="Critical Omission",
|
| 1185 |
value=0
|
| 1186 |
)
|
| 1187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1188 |
# Hallucination and Critical Omission Comments
|
|
|
|
| 1189 |
with gr.Row():
|
| 1190 |
hallucination_comments = gr.Textbox(
|
| 1191 |
label="Hallucination",
|
| 1192 |
+
placeholder="Copy the relevant portion of the summary and provide your feedback directly underneath",
|
| 1193 |
+
lines=5,
|
| 1194 |
value=""
|
| 1195 |
)
|
| 1196 |
critical_omission_comments = gr.Textbox(
|
| 1197 |
label="Critical Omission",
|
| 1198 |
+
placeholder="Copy the relevant portion of the summary and provide your feedback directly underneath",
|
| 1199 |
+
lines=5,
|
| 1200 |
value=""
|
| 1201 |
)
|
| 1202 |
|
| 1203 |
+
# Detailed feedback
|
| 1204 |
+
gr.Markdown("### Other Feedback and Comment")
|
| 1205 |
+
feedback_text = gr.Textbox(
|
| 1206 |
+
label="Other Feedback and Comment",
|
| 1207 |
+
placeholder="Please provide any additional feedback or comments...",
|
| 1208 |
+
lines=3
|
| 1209 |
+
)
|
| 1210 |
+
|
| 1211 |
# Submit evaluation button
|
| 1212 |
submit_eval_button = gr.Button(
|
| 1213 |
"Submit Patient Evaluation",
|
|
|
|
| 1406 |
|
| 1407 |
def update_patient_eval_display(patient_id, admission_label=None):
|
| 1408 |
"""
|
| 1409 |
+
Return patient input HTML and summary markdown for the selected patient.
|
| 1410 |
Single-admission mode: always uses the first (only) record for that patient.
|
| 1411 |
"""
|
| 1412 |
try:
|
| 1413 |
if not patient_id:
|
| 1414 |
+
return "No patient selected", "Select a patient to view AI summary..."
|
| 1415 |
|
| 1416 |
pid = str(patient_id)
|
| 1417 |
if pid not in eval_data_by_patient or not eval_data_by_patient[pid]:
|
| 1418 |
+
return "Patient data not found", "AI summary not found"
|
| 1419 |
|
| 1420 |
# Single admission per patient
|
| 1421 |
first_key = list(eval_data_by_patient[pid].keys())[0]
|
| 1422 |
rec = eval_data_by_patient[pid][first_key]
|
| 1423 |
|
|
|
|
| 1424 |
summary_text = clean_summary_output(rec.get('summary', '') or 'No summary available')
|
| 1425 |
input_text = rec.get('input_text', '') or 'No input data available'
|
| 1426 |
|
|
|
|
| 1440 |
'</pre>'
|
| 1441 |
)
|
| 1442 |
# Return raw markdown text; scrolling controlled by CSS on elem_id
|
| 1443 |
+
return input_html, summary_text
|
| 1444 |
except Exception as e:
|
| 1445 |
import traceback
|
| 1446 |
error_msg = f"Error loading patient data: {str(e)}\n{traceback.format_exc()}"
|
| 1447 |
print(f"[ERROR] {error_msg}")
|
| 1448 |
+
return "Error loading data", f"Error: {str(e)}"
|
| 1449 |
|
| 1450 |
# Handle clinician ID selection to filter patient list
|
| 1451 |
if eval_groups:
|
|
|
|
| 1453 |
"""Filter patient list based on selected clinician ID and auto-fill clinician ID field"""
|
| 1454 |
if not selected_clinician:
|
| 1455 |
filtered_patients = []
|
| 1456 |
+
info_text = ""
|
| 1457 |
clinician_id_update = gr.update()
|
| 1458 |
else:
|
| 1459 |
# Directly use selected_clinician as key (no mapping needed)
|
|
|
|
| 1488 |
eval_patient_radio.change(
|
| 1489 |
fn=on_patient_change,
|
| 1490 |
inputs=[eval_patient_radio],
|
| 1491 |
+
outputs=[patient_input_display, ai_summary_display]
|
| 1492 |
)
|
| 1493 |
|
| 1494 |
|