Spaces:
Runtime error
Runtime error
jesseliu0913 commited on
Commit ·
f7bd2a2
1
Parent(s): 8b52acf
Fix data loading: use correct JSONL file and display group information
Browse files- Load from assets/structured_results_o3_with_inputs.jsonl instead of Qwen JSONL
- Display patient group, age, gender, race, and note length in UI
- Update expected patient count from 20 to 24
- Add patient info header to raw data display
- chatgpt.py +48 -25
chatgpt.py
CHANGED
|
@@ -903,38 +903,36 @@ with gr.Blocks() as app:
|
|
| 903 |
return text.strip()
|
| 904 |
|
| 905 |
# Load from new JSONL format first (single admission per record)
|
| 906 |
-
# IMPORTANT:
|
| 907 |
-
jsonl_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '
|
| 908 |
jsonl_loaded = False
|
| 909 |
eval_data_by_patient = {} # Initialize empty to ensure clean start
|
| 910 |
|
| 911 |
-
# FORCE: Only load from
|
| 912 |
if os.path.exists(jsonl_path):
|
| 913 |
-
print(f"[INFO] ========== LOADING FROM
|
| 914 |
print(f"Loading data from JSONL: {jsonl_path}")
|
| 915 |
jsonl_data = load_jsonl(jsonl_path)
|
| 916 |
print(f"Found {len(jsonl_data)} entries in JSONL file")
|
| 917 |
entry_count = 0
|
| 918 |
for entry in jsonl_data:
|
| 919 |
entry_count += 1
|
| 920 |
-
|
| 921 |
-
|
| 922 |
-
|
| 923 |
-
|
| 924 |
-
|
| 925 |
-
|
| 926 |
-
|
| 927 |
-
|
| 928 |
-
|
| 929 |
-
|
| 930 |
-
patient_id = full_id.split('_')[0] if '_' in full_id else full_id
|
| 931 |
-
admission_id = '1' # Default admission ID
|
| 932 |
|
| 933 |
# Get input and output fields
|
| 934 |
-
input_text = entry.get('
|
| 935 |
-
raw_summary = entry.get('
|
| 936 |
# Clean the output to extract only markdown summary
|
| 937 |
-
summary = clean_summary_output(raw_summary)
|
| 938 |
|
| 939 |
# Extract admission time from input text
|
| 940 |
admittime = None
|
|
@@ -949,6 +947,11 @@ with gr.Blocks() as app:
|
|
| 949 |
'patient_id': patient_id,
|
| 950 |
'admission_id': admission_id,
|
| 951 |
'admission_index': 1,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 952 |
'input_text': input_text, # This will be shown in "Patient raw data from EHR"
|
| 953 |
'summary': summary, # This will be shown in "AI Generated Summary" (cleaned)
|
| 954 |
'admittime': admittime,
|
|
@@ -1114,12 +1117,12 @@ with gr.Blocks() as app:
|
|
| 1114 |
print(f"[DEBUG] JSONL loaded: {jsonl_loaded}")
|
| 1115 |
print(f"[DEBUG] Total patients in UI list: {len(patient_ids_list)}")
|
| 1116 |
print(f"[DEBUG] Patient IDs: {patient_ids_list}")
|
| 1117 |
-
if len(patient_ids_list) !=
|
| 1118 |
-
print(f"[
|
| 1119 |
-
print(f"[
|
| 1120 |
-
print(f"[
|
| 1121 |
else:
|
| 1122 |
-
print(f"[DEBUG] ✓ Correct number of patients (
|
| 1123 |
print(f"[DEBUG] ============================================")
|
| 1124 |
|
| 1125 |
with gr.Tabs():
|
|
@@ -1541,12 +1544,32 @@ with gr.Blocks() as app:
|
|
| 1541 |
|
| 1542 |
summary_text = clean_summary_output(rec.get('summary', '') or 'No summary available')
|
| 1543 |
input_text = rec.get('input_text', '') or 'No input data available'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1544 |
|
| 1545 |
# Replace ICD codes and Lab IDs with descriptions
|
| 1546 |
input_text_with_descriptions = replace_icd_codes_and_lab_ids(input_text)
|
|
|
|
|
|
|
|
|
|
| 1547 |
|
| 1548 |
sanitized_input = (
|
| 1549 |
-
|
| 1550 |
.replace('<', '<')
|
| 1551 |
.replace('>', '>')
|
| 1552 |
)
|
|
|
|
| 903 |
return text.strip()
|
| 904 |
|
| 905 |
# Load from new JSONL format first (single admission per record)
|
| 906 |
+
# IMPORTANT: Load from assets/structured_results_o3_with_inputs.jsonl
|
| 907 |
+
jsonl_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'assets', 'structured_results_o3_with_inputs.jsonl')
|
| 908 |
jsonl_loaded = False
|
| 909 |
eval_data_by_patient = {} # Initialize empty to ensure clean start
|
| 910 |
|
| 911 |
+
# FORCE: Only load from structured_results JSONL, completely skip all other data sources
|
| 912 |
if os.path.exists(jsonl_path):
|
| 913 |
+
print(f"[INFO] ========== LOADING FROM STRUCTURED RESULTS JSONL ONLY ==========")
|
| 914 |
print(f"Loading data from JSONL: {jsonl_path}")
|
| 915 |
jsonl_data = load_jsonl(jsonl_path)
|
| 916 |
print(f"Found {len(jsonl_data)} entries in JSONL file")
|
| 917 |
entry_count = 0
|
| 918 |
for entry in jsonl_data:
|
| 919 |
entry_count += 1
|
| 920 |
+
# Get patient and admission IDs directly from the entry
|
| 921 |
+
patient_id = str(entry.get('subject_id', ''))
|
| 922 |
+
admission_id = str(entry.get('hadm_id', ''))
|
| 923 |
+
|
| 924 |
+
# Get group information
|
| 925 |
+
group = entry.get('group', 'Unknown')
|
| 926 |
+
age = entry.get('age', 'Unknown')
|
| 927 |
+
gender = entry.get('gender', 'Unknown')
|
| 928 |
+
race = entry.get('race', 'Unknown')
|
| 929 |
+
note_length = entry.get('note_length_non_ws', 0)
|
|
|
|
|
|
|
| 930 |
|
| 931 |
# Get input and output fields
|
| 932 |
+
input_text = entry.get('raw_note', '')
|
| 933 |
+
raw_summary = entry.get('content', '')
|
| 934 |
# Clean the output to extract only markdown summary
|
| 935 |
+
summary = clean_summary_output(raw_summary) if raw_summary else ''
|
| 936 |
|
| 937 |
# Extract admission time from input text
|
| 938 |
admittime = None
|
|
|
|
| 947 |
'patient_id': patient_id,
|
| 948 |
'admission_id': admission_id,
|
| 949 |
'admission_index': 1,
|
| 950 |
+
'group': group, # Add group information
|
| 951 |
+
'age': age,
|
| 952 |
+
'gender': gender,
|
| 953 |
+
'race': race,
|
| 954 |
+
'note_length': note_length,
|
| 955 |
'input_text': input_text, # This will be shown in "Patient raw data from EHR"
|
| 956 |
'summary': summary, # This will be shown in "AI Generated Summary" (cleaned)
|
| 957 |
'admittime': admittime,
|
|
|
|
| 1117 |
print(f"[DEBUG] JSONL loaded: {jsonl_loaded}")
|
| 1118 |
print(f"[DEBUG] Total patients in UI list: {len(patient_ids_list)}")
|
| 1119 |
print(f"[DEBUG] Patient IDs: {patient_ids_list}")
|
| 1120 |
+
if len(patient_ids_list) != 24:
|
| 1121 |
+
print(f"[WARNING] Expected 24 patients but found {len(patient_ids_list)}!")
|
| 1122 |
+
print(f"[WARNING] This may indicate data is being loaded from multiple sources!")
|
| 1123 |
+
print(f"[WARNING] Check the logs above to see which sources were loaded.")
|
| 1124 |
else:
|
| 1125 |
+
print(f"[DEBUG] ✓ Correct number of patients (24) loaded from structured results JSONL")
|
| 1126 |
print(f"[DEBUG] ============================================")
|
| 1127 |
|
| 1128 |
with gr.Tabs():
|
|
|
|
| 1544 |
|
| 1545 |
summary_text = clean_summary_output(rec.get('summary', '') or 'No summary available')
|
| 1546 |
input_text = rec.get('input_text', '') or 'No input data available'
|
| 1547 |
+
|
| 1548 |
+
# Get patient metadata
|
| 1549 |
+
group = rec.get('group', 'Unknown')
|
| 1550 |
+
age = rec.get('age', 'Unknown')
|
| 1551 |
+
gender = rec.get('gender', 'Unknown')
|
| 1552 |
+
race = rec.get('race', 'Unknown')
|
| 1553 |
+
note_length = rec.get('note_length', 0)
|
| 1554 |
+
admission_id = rec.get('admission_id', 'Unknown')
|
| 1555 |
+
|
| 1556 |
+
# Add patient info header
|
| 1557 |
+
patient_info_header = (
|
| 1558 |
+
f"=== PATIENT INFORMATION ===\n"
|
| 1559 |
+
f"Patient ID: {pid} | Admission ID: {admission_id}\n"
|
| 1560 |
+
f"Group: {group} | Note Length: {note_length:,} chars\n"
|
| 1561 |
+
f"Demographics: Age {age}, {gender}, {race}\n"
|
| 1562 |
+
f"{'='*80}\n\n"
|
| 1563 |
+
)
|
| 1564 |
|
| 1565 |
# Replace ICD codes and Lab IDs with descriptions
|
| 1566 |
input_text_with_descriptions = replace_icd_codes_and_lab_ids(input_text)
|
| 1567 |
+
|
| 1568 |
+
# Prepend patient info to input text
|
| 1569 |
+
full_input_text = patient_info_header + input_text_with_descriptions
|
| 1570 |
|
| 1571 |
sanitized_input = (
|
| 1572 |
+
full_input_text.replace('&', '&')
|
| 1573 |
.replace('<', '<')
|
| 1574 |
.replace('>', '>')
|
| 1575 |
)
|