Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,8 +23,6 @@ if "visibility" not in st.session_state:
|
|
| 23 |
|
| 24 |
#nlp = en_core_web_lg.load()
|
| 25 |
nlp = spacy.load("en_ner_bc5cdr_md")
|
| 26 |
-
#nlp0 = spacy.load("en_ner_bc5cdr_md")
|
| 27 |
-
#nlp1 = spacy.load("en_ner_bc5cdr_md")
|
| 28 |
|
| 29 |
st.set_page_config(page_title ='Clinical Note Summarization',
|
| 30 |
#page_icon= "Notes",
|
|
@@ -194,11 +192,8 @@ def get_entity_options():
|
|
| 194 |
return options
|
| 195 |
|
| 196 |
#adding a new pipeline component to identify negation
|
| 197 |
-
def neg_model(
|
| 198 |
-
nlp = spacy.load(nlp_model, disable = ['parser'])
|
| 199 |
-
# nlp.add_pipe(nlp.create_pipe('sentencizer'))
|
| 200 |
nlp.add_pipe('sentencizer')
|
| 201 |
-
# negex = Negex(nlp)
|
| 202 |
nlp.add_pipe(
|
| 203 |
"negex",
|
| 204 |
config={
|
|
@@ -207,9 +202,9 @@ def neg_model(nlp_model):
|
|
| 207 |
last=True)
|
| 208 |
return nlp
|
| 209 |
|
| 210 |
-
def negation_handling(
|
| 211 |
results = []
|
| 212 |
-
nlp = neg_model(
|
| 213 |
note = note.split(".") #sentence tokenizing based on delimeter
|
| 214 |
note = [n.strip() for n in note] #removing extra spaces at the begining and end of sentence
|
| 215 |
for t in note:
|
|
@@ -252,11 +247,11 @@ def dedupe(items):
|
|
| 252 |
|
| 253 |
lem_clinical_note= lemmatize(runtext, nlp0)
|
| 254 |
#creating a doc object using BC5CDR model
|
| 255 |
-
doc =
|
| 256 |
options = get_entity_options()
|
| 257 |
|
| 258 |
#list of negative concepts from clinical note identified by negspacy
|
| 259 |
-
results0 = negation_handling(
|
| 260 |
|
| 261 |
matcher = match(nlp, results0,"NEG_ENTITY")
|
| 262 |
|
|
@@ -315,15 +310,18 @@ with col1:
|
|
| 315 |
fulldischargesummary = historyAdmission['TEXT'].values
|
| 316 |
st.write( str(fulldischargesummary))
|
| 317 |
##====== Storing the Diseases/Text
|
| 318 |
-
table= {"Entity":[], "Class":[]}
|
| 319 |
-
ent_bc = {}
|
| 320 |
-
for x in doc.ents:
|
| 321 |
-
ent_bc[x.text] = x.label_
|
| 322 |
-
for key in ent_bc:
|
| 323 |
-
table["Entity"].append(key)
|
| 324 |
-
table["Class"].append(ent_bc[key])
|
| 325 |
-
trans_df = pd.DataFrame(table)
|
| 326 |
-
|
|
|
|
|
|
|
|
|
|
| 327 |
with col2:
|
| 328 |
st.button('NER')
|
| 329 |
st.markdown('**CHIEF COMPLAINT:**')
|
|
@@ -331,13 +329,11 @@ with col2:
|
|
| 331 |
st.markdown('**ADMISSION DIAGNOSIS:**')
|
| 332 |
st.markdown(str(diagnosis))
|
| 333 |
st.markdown('**PROBLEM/ISSUE**')
|
|
|
|
| 334 |
genEntities(trans_df, 'DISEASE')
|
| 335 |
st.markdown('**MEDICATION**')
|
| 336 |
genEntities(trans_df, 'CHEMICAL')
|
| 337 |
#st.table(trans_df)
|
| 338 |
st.markdown('**NER**')
|
| 339 |
with st.expander("See NER Details"):
|
| 340 |
-
st.markdown(ent_html, unsafe_allow_html=True)
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
|
|
|
| 23 |
|
| 24 |
#nlp = en_core_web_lg.load()
|
| 25 |
nlp = spacy.load("en_ner_bc5cdr_md")
|
|
|
|
|
|
|
| 26 |
|
| 27 |
st.set_page_config(page_title ='Clinical Note Summarization',
|
| 28 |
#page_icon= "Notes",
|
|
|
|
| 192 |
return options
|
| 193 |
|
| 194 |
#adding a new pipeline component to identify negation
|
| 195 |
+
def neg_model():
|
|
|
|
|
|
|
| 196 |
nlp.add_pipe('sentencizer')
|
|
|
|
| 197 |
nlp.add_pipe(
|
| 198 |
"negex",
|
| 199 |
config={
|
|
|
|
| 202 |
last=True)
|
| 203 |
return nlp
|
| 204 |
|
| 205 |
+
def negation_handling(note, neg_model):
|
| 206 |
results = []
|
| 207 |
+
nlp = neg_model()
|
| 208 |
note = note.split(".") #sentence tokenizing based on delimeter
|
| 209 |
note = [n.strip() for n in note] #removing extra spaces at the begining and end of sentence
|
| 210 |
for t in note:
|
|
|
|
| 247 |
|
| 248 |
lem_clinical_note= lemmatize(runtext, nlp0)
|
| 249 |
#creating a doc object using BC5CDR model
|
| 250 |
+
doc = nlp(lem_clinical_note)
|
| 251 |
options = get_entity_options()
|
| 252 |
|
| 253 |
#list of negative concepts from clinical note identified by negspacy
|
| 254 |
+
results0 = negation_handling(lem_clinical_note, neg_model)
|
| 255 |
|
| 256 |
matcher = match(nlp, results0,"NEG_ENTITY")
|
| 257 |
|
|
|
|
| 310 |
fulldischargesummary = historyAdmission['TEXT'].values
|
| 311 |
st.write( str(fulldischargesummary))
|
| 312 |
##====== Storing the Diseases/Text
|
| 313 |
+
# table= {"Entity":[], "Class":[]}
|
| 314 |
+
# ent_bc = {}
|
| 315 |
+
# for x in doc.ents:
|
| 316 |
+
# ent_bc[x.text] = x.label_
|
| 317 |
+
# for key in ent_bc:
|
| 318 |
+
# table["Entity"].append(key)
|
| 319 |
+
# table["Class"].append(ent_bc[key])
|
| 320 |
+
# trans_df = pd.DataFrame(table)
|
| 321 |
+
|
| 322 |
+
problem_entities = list(dedupe([t for t in doc0.ents if t.label_ == 'DISEASE']))
|
| 323 |
+
medication_entities = list(dedupe([t for t in doc0.ents if t.label_ == 'CHEMICAL']))
|
| 324 |
+
|
| 325 |
with col2:
|
| 326 |
st.button('NER')
|
| 327 |
st.markdown('**CHIEF COMPLAINT:**')
|
|
|
|
| 329 |
st.markdown('**ADMISSION DIAGNOSIS:**')
|
| 330 |
st.markdown(str(diagnosis))
|
| 331 |
st.markdown('**PROBLEM/ISSUE**')
|
| 332 |
+
st.markdown(f'<p style="background-color:{problem_entities};color:#080808;font-size:16px;">{entlist}</p>', unsafe_allow_html=True)
|
| 333 |
genEntities(trans_df, 'DISEASE')
|
| 334 |
st.markdown('**MEDICATION**')
|
| 335 |
genEntities(trans_df, 'CHEMICAL')
|
| 336 |
#st.table(trans_df)
|
| 337 |
st.markdown('**NER**')
|
| 338 |
with st.expander("See NER Details"):
|
| 339 |
+
st.markdown(ent_html, unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|