Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import en_ner_bc5cdr_md
|
| 2 |
import spacy
|
| 3 |
from spacy import displacy
|
|
@@ -13,6 +16,23 @@ def listToString(s):
|
|
| 13 |
str1 = " ; "
|
| 14 |
return (str1.join(s))
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
### Defining List
|
| 17 |
lst_chk = ["PHI Masking","Disease & Drug Extraction","Question Answering"]
|
| 18 |
|
|
@@ -31,16 +51,10 @@ hom =st.sidebar.radio("Text Predictions",["Home","Text Prediction Models","Feedb
|
|
| 31 |
|
| 32 |
### Main Code
|
| 33 |
if hom == "Home":
|
| 34 |
-
#colm1 , colm2, colm3, colm4, colm5 = st.columns(5)
|
| 35 |
-
#with colm5:
|
| 36 |
-
# st.image("data//Goofy.jpg", width = 100)
|
| 37 |
|
| 38 |
col1 , col2 = st.columns([0.8,3])
|
| 39 |
with col2:
|
| 40 |
st.title("GOOFY THE ASSIST :male-doctor:")
|
| 41 |
-
# :male-doctor:, :person_doing_cartwheel:
|
| 42 |
-
#with col3:
|
| 43 |
-
#st.write("[Gavs](https://www.gavstech.com/)")
|
| 44 |
st.caption("")
|
| 45 |
st.video("https://www.youtube.com/watch?v=q_hfdvmS8As")
|
| 46 |
|
|
@@ -76,7 +90,10 @@ if hom == "Text Prediction Models":
|
|
| 76 |
lst_person = []
|
| 77 |
lst_gpe = []
|
| 78 |
|
| 79 |
-
tagger = SequenceTagger.load("flair/ner-english-ontonotes-large")
|
|
|
|
|
|
|
|
|
|
| 80 |
sentence = Sentence(txt_input1)
|
| 81 |
tagger.predict(sentence)
|
| 82 |
|
|
@@ -128,8 +145,8 @@ if hom == "Text Prediction Models":
|
|
| 128 |
lst_person = []
|
| 129 |
lst_gpe = []
|
| 130 |
|
| 131 |
-
tagger =
|
| 132 |
-
sentence = Sentence(
|
| 133 |
tagger.predict(sentence)
|
| 134 |
|
| 135 |
out_txt = txt_input1
|
|
@@ -188,7 +205,8 @@ if hom == "Text Prediction Models":
|
|
| 188 |
if st.button("Submit"):
|
| 189 |
|
| 190 |
##### Scispacy Model
|
| 191 |
-
nlp_bc5cdr = en_ner_bc5cdr_md.load()
|
|
|
|
| 192 |
doc_nlp_bc5cdr = nlp_bc5cdr(txt_input1)
|
| 193 |
#displacy_image = displacy.render(doc_nlp_bc5cdr, jupyter=True,style='ent')
|
| 194 |
lst_disease = []
|
|
@@ -225,7 +243,8 @@ if hom == "Text Prediction Models":
|
|
| 225 |
#### Scispacy Model full dataframe
|
| 226 |
phi_df_full = pd.DataFrame()
|
| 227 |
for row in df.itertuples():
|
| 228 |
-
nlp_bc5cdr = en_ner_bc5cdr_md.load()
|
|
|
|
| 229 |
doc_nlp_bc5cdr = nlp_bc5cdr(str(row.Medical_Record))
|
| 230 |
#displacy_image = displacy.render(doc_nlp_bc5cdr, jupyter=True,style='ent')
|
| 231 |
lst_disease = []
|
|
@@ -264,19 +283,14 @@ if hom == "Text Prediction Models":
|
|
| 264 |
qstn = st.selectbox("Select Question",questions,index = 0)
|
| 265 |
|
| 266 |
if st.button("Submit"):
|
| 267 |
-
|
| 268 |
-
import transformers
|
| 269 |
-
from transformers import pipeline
|
| 270 |
-
qa_model = pipeline("question-answering")
|
| 271 |
qa_op = qa_model(question = qstn, context = context)
|
| 272 |
-
|
| 273 |
cnt = 0
|
| 274 |
for i in qa_op.values():
|
| 275 |
cnt += 1
|
| 276 |
if cnt == 4:
|
| 277 |
op_fin = str(i)
|
| 278 |
-
|
| 279 |
-
#st.write("Output",op_fin)
|
| 280 |
st.success(op_fin)
|
| 281 |
|
| 282 |
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer
|
| 2 |
+
import transformers
|
| 3 |
+
from transformers import pipeline
|
| 4 |
import en_ner_bc5cdr_md
|
| 5 |
import spacy
|
| 6 |
from spacy import displacy
|
|
|
|
| 16 |
str1 = " ; "
|
| 17 |
return (str1.join(s))
|
| 18 |
|
| 19 |
+
|
| 20 |
+
@st.cache(allow_output_mutation=True)
|
| 21 |
+
def flair_model(model_name):
|
| 22 |
+
return SequenceTagger.load(model_name)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
@st.cache(allow_output_mutation=True)
|
| 26 |
+
def scispacy_model():
|
| 27 |
+
return en_ner_bc5cdr_md.load()
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@st.cache(allow_output_mutation=True)
|
| 31 |
+
def questionna(model_nm):
|
| 32 |
+
return pipeline(model_nm)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
### Defining List
|
| 37 |
lst_chk = ["PHI Masking","Disease & Drug Extraction","Question Answering"]
|
| 38 |
|
|
|
|
| 51 |
|
| 52 |
### Main Code
|
| 53 |
if hom == "Home":
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
col1 , col2 = st.columns([0.8,3])
|
| 56 |
with col2:
|
| 57 |
st.title("GOOFY THE ASSIST :male-doctor:")
|
|
|
|
|
|
|
|
|
|
| 58 |
st.caption("")
|
| 59 |
st.video("https://www.youtube.com/watch?v=q_hfdvmS8As")
|
| 60 |
|
|
|
|
| 90 |
lst_person = []
|
| 91 |
lst_gpe = []
|
| 92 |
|
| 93 |
+
# tagger = SequenceTagger.load("flair/ner-english-ontonotes-large")
|
| 94 |
+
# sentence = Sentence(txt_input1)
|
| 95 |
+
# tagger.predict(sentence)
|
| 96 |
+
tagger = flair_model('flair/ner-english-ontonotes-large')
|
| 97 |
sentence = Sentence(txt_input1)
|
| 98 |
tagger.predict(sentence)
|
| 99 |
|
|
|
|
| 145 |
lst_person = []
|
| 146 |
lst_gpe = []
|
| 147 |
|
| 148 |
+
tagger = flair_model('flair/ner-english-ontonotes-large')
|
| 149 |
+
sentence = Sentence(txt_input1)
|
| 150 |
tagger.predict(sentence)
|
| 151 |
|
| 152 |
out_txt = txt_input1
|
|
|
|
| 205 |
if st.button("Submit"):
|
| 206 |
|
| 207 |
##### Scispacy Model
|
| 208 |
+
# nlp_bc5cdr = en_ner_bc5cdr_md.load()
|
| 209 |
+
nlp_bc5cdr = scispacy_model()
|
| 210 |
doc_nlp_bc5cdr = nlp_bc5cdr(txt_input1)
|
| 211 |
#displacy_image = displacy.render(doc_nlp_bc5cdr, jupyter=True,style='ent')
|
| 212 |
lst_disease = []
|
|
|
|
| 243 |
#### Scispacy Model full dataframe
|
| 244 |
phi_df_full = pd.DataFrame()
|
| 245 |
for row in df.itertuples():
|
| 246 |
+
# nlp_bc5cdr = en_ner_bc5cdr_md.load()
|
| 247 |
+
nlp_bc5cdr = scispacy_model()
|
| 248 |
doc_nlp_bc5cdr = nlp_bc5cdr(str(row.Medical_Record))
|
| 249 |
#displacy_image = displacy.render(doc_nlp_bc5cdr, jupyter=True,style='ent')
|
| 250 |
lst_disease = []
|
|
|
|
| 283 |
qstn = st.selectbox("Select Question",questions,index = 0)
|
| 284 |
|
| 285 |
if st.button("Submit"):
|
| 286 |
+
qa_model = questionna('question-answering')
|
|
|
|
|
|
|
|
|
|
| 287 |
qa_op = qa_model(question = qstn, context = context)
|
| 288 |
+
|
| 289 |
cnt = 0
|
| 290 |
for i in qa_op.values():
|
| 291 |
cnt += 1
|
| 292 |
if cnt == 4:
|
| 293 |
op_fin = str(i)
|
|
|
|
|
|
|
| 294 |
st.success(op_fin)
|
| 295 |
|
| 296 |
|