update
Browse files- .gitignore +4 -0
- app_backup_1.py +0 -135
- data/input_meta_info.csv +0 -0
- data/nacc_variable_mappings.pkl +0 -0
.gitignore
CHANGED
@@ -171,3 +171,7 @@ nacc_test_with_np_cli.csv
|
|
171 |
gen_nacc_meta.py
|
172 |
nacc_variable.csv
|
173 |
nacc_allowable_code.csv
|
|
|
|
|
|
|
|
|
|
171 |
gen_nacc_meta.py
|
172 |
nacc_variable.csv
|
173 |
nacc_allowable_code.csv
|
174 |
+
input_meta_info.toml
|
175 |
+
input_meta_info_old.csv
|
176 |
+
include_section.py
|
177 |
+
app_backup_1.py
|
app_backup_1.py
DELETED
@@ -1,135 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import json
|
3 |
-
import random
|
4 |
-
import pandas as pd
|
5 |
-
import pickle
|
6 |
-
|
7 |
-
# set page configuration to wide mode
|
8 |
-
st.set_page_config(layout="wide")
|
9 |
-
|
10 |
-
st.markdown("""
|
11 |
-
<style>
|
12 |
-
.bounding-box {
|
13 |
-
border: 2px solid #4CAF50; # Green border
|
14 |
-
border-radius: 5px; # Rounded corners
|
15 |
-
padding: 10px; # Padding inside the box
|
16 |
-
margin: 10px; # Space outside the box
|
17 |
-
}
|
18 |
-
</style>
|
19 |
-
""", unsafe_allow_html=True)
|
20 |
-
|
21 |
-
@st.cache_resource
|
22 |
-
def load_model():
|
23 |
-
import adrd
|
24 |
-
try:
|
25 |
-
ckpt_path = './ckpt_swinunetr_stripped_MNI.pt'
|
26 |
-
model = adrd.model.ADRDModel.from_ckpt(ckpt_path, device='cpu')
|
27 |
-
except:
|
28 |
-
# ckpt_path = '../adrd_tool_copied_from_sahana/dev/ckpt/ckpt_swinunetr_stripped_MNI.pt'
|
29 |
-
# model = adrd.model.ADRDModel.from_ckpt(ckpt_path, device='cpu')
|
30 |
-
return None
|
31 |
-
return model
|
32 |
-
|
33 |
-
@st.cache_resource
|
34 |
-
def load_nacc_data():
|
35 |
-
from data.dataset_csv import CSVDataset
|
36 |
-
dat = CSVDataset(
|
37 |
-
dat_file = "./data/test.csv",
|
38 |
-
cnf_file = "./data/input_meta_info.csv"
|
39 |
-
)
|
40 |
-
return dat
|
41 |
-
|
42 |
-
model = load_model()
|
43 |
-
dat_tst = load_nacc_data()
|
44 |
-
|
45 |
-
def predict_proba(data_dict):
|
46 |
-
pred_dict = model.predict_proba([data_dict])[1][0]
|
47 |
-
return pred_dict
|
48 |
-
|
49 |
-
# load NACC testing data
|
50 |
-
from data.dataset_csv import CSVDataset
|
51 |
-
dat_tst = CSVDataset(
|
52 |
-
dat_file = "./data/test.csv",
|
53 |
-
cnf_file = "./data/input_meta_info.csv"
|
54 |
-
)
|
55 |
-
|
56 |
-
# initialize session state for the text input if it's not already set
|
57 |
-
if 'input_text' not in st.session_state:
|
58 |
-
st.session_state.input_text = ""
|
59 |
-
|
60 |
-
# section 1
|
61 |
-
st.markdown("#### About")
|
62 |
-
st.markdown("Differential diagnosis of dementia remains a challenge in neurology due to symptom overlap across etiologies, yet it is crucial for formulating early, personalized management strategies. Here, we present an AI model that harnesses a broad array of data, including demographics, individual and family medical history, medication use, neuropsychological assessments, functional evaluations, and multimodal neuroimaging, to identify the etiologies contributing to dementia in individuals.")
|
63 |
-
|
64 |
-
# section 2
|
65 |
-
st.markdown("#### Demo")
|
66 |
-
st.markdown("Please enter the input features in the textbox below, formatted as a JSON dictionary. Click the \"**Random case**\" button to populate the textbox with a randomly selected case from the NACC testing dataset. Use the \"**Predict**\" button to submit your input to the model, which will then provide probability predictions for mental status and all 10 etiologies.")
|
67 |
-
|
68 |
-
# layout
|
69 |
-
layout_l, layout_r = st.columns([1, 1])
|
70 |
-
|
71 |
-
# create a form for user input
|
72 |
-
with layout_l:
|
73 |
-
with st.form("json_input_form"):
|
74 |
-
json_input = st.text_area(
|
75 |
-
"Please enter JSON-formatted input features:",
|
76 |
-
value = st.session_state.input_text,
|
77 |
-
height = 300
|
78 |
-
)
|
79 |
-
|
80 |
-
# create three columns
|
81 |
-
left_col, middle_col, right_col = st.columns([3, 4, 1])
|
82 |
-
|
83 |
-
with left_col:
|
84 |
-
sample_button = st.form_submit_button("Random case")
|
85 |
-
|
86 |
-
with right_col:
|
87 |
-
submit_button = st.form_submit_button("Predict")
|
88 |
-
|
89 |
-
with open('./data/nacc_variable_mappings.pkl', 'rb') as file:
|
90 |
-
nacc_mapping = pickle.load(file)
|
91 |
-
|
92 |
-
def convert_dictionary(original_dict, mappings):
|
93 |
-
transformed_dict = {}
|
94 |
-
|
95 |
-
for key, value in original_dict.items():
|
96 |
-
if key in mappings:
|
97 |
-
new_key, transform_map = mappings[key]
|
98 |
-
|
99 |
-
# If the value needs to be transformed
|
100 |
-
if value in transform_map:
|
101 |
-
transformed_value = transform_map[value]
|
102 |
-
else:
|
103 |
-
transformed_value = value # Keep the original value if no transformation is needed
|
104 |
-
|
105 |
-
transformed_dict[new_key] = transformed_value
|
106 |
-
|
107 |
-
return transformed_dict
|
108 |
-
|
109 |
-
if sample_button:
|
110 |
-
idx = random.randint(0, len(dat_tst) - 1)
|
111 |
-
random_case = dat_tst[idx][0]
|
112 |
-
st.session_state.input_text = json.dumps(random_case, indent=2)
|
113 |
-
|
114 |
-
# reset input text after form processing to show updated text in the input box
|
115 |
-
if 'input_text' in st.session_state:
|
116 |
-
st.experimental_rerun()
|
117 |
-
|
118 |
-
elif submit_button:
|
119 |
-
try:
|
120 |
-
# Parse the JSON input into a Python dictionary
|
121 |
-
data_dict = json.loads(json_input)
|
122 |
-
data_dict = convert_dictionary(data_dict, nacc_mapping)
|
123 |
-
# print(data_dict)
|
124 |
-
pred_dict = predict_proba(data_dict)
|
125 |
-
with layout_r:
|
126 |
-
st.write("Predicted probabilities:")
|
127 |
-
st.code(json.dumps(pred_dict, indent=2))
|
128 |
-
except json.JSONDecodeError as e:
|
129 |
-
# Handle JSON parsing errors
|
130 |
-
st.error(f"An error occurred: {e}")
|
131 |
-
|
132 |
-
# section 3
|
133 |
-
st.markdown("#### Feature Table")
|
134 |
-
df_input_meta_info = pd.read_csv('./data/input_meta_info.csv')
|
135 |
-
st.table(df_input_meta_info)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data/input_meta_info.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
data/nacc_variable_mappings.pkl
CHANGED
Binary files a/data/nacc_variable_mappings.pkl and b/data/nacc_variable_mappings.pkl differ
|
|