Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,13 +9,7 @@ from keras.models import load_model
|
|
9 |
|
10 |
|
11 |
def predict(new_data):
|
12 |
-
|
13 |
-
with open("biobert_rf.pkl", 'rb') as f:
|
14 |
-
rf = pickle.load(f)
|
15 |
-
# Load the BioBERT model and tokenizer
|
16 |
-
model_name = "dmis-lab/biobert-base-cased-v1.1"
|
17 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
18 |
-
model = AutoModel.from_pretrained(model_name)
|
19 |
tokens = tokenizer(new_data.split(), padding=True, truncation=True, max_length=128, return_tensors='pt')
|
20 |
with torch.no_grad():
|
21 |
embeddings = model(tokens['input_ids'], attention_mask=tokens['attention_mask'])[0][:, 0, :].numpy()
|
@@ -34,9 +28,8 @@ def predict(new_data):
|
|
34 |
labels.append(label)
|
35 |
prev_label=label
|
36 |
return(data,labels)
|
37 |
-
|
38 |
|
39 |
-
|
40 |
def highlight(sentence):
|
41 |
highlighted_text = ""
|
42 |
entity_colors = {"Symptom":"#87cefa","Medical Condition":"#ffb6c1"}
|
@@ -54,46 +47,41 @@ def highlight(sentence):
|
|
54 |
highlighted_text += f'{words} '
|
55 |
st.markdown(highlighted_text, unsafe_allow_html=True)
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
|
59 |
|
60 |
-
def main():
|
61 |
-
st.title('Oral Medicine Meets NLP')
|
62 |
-
st.subheader('Named Entity Recoginition System For Oral Medicine ')
|
63 |
-
sentence = st.text_area('Enter a sentence:')
|
64 |
-
|
65 |
-
st.write("OR")
|
66 |
-
selected_options = st.selectbox(
|
67 |
-
'Choose a text from dropdown: ',
|
68 |
-
(None,
|
69 |
-
'Anemia and gingival bleeding are connected in that anemia can be a contributing cause to the occurrence of gingival bleeding. Anemia is a condition characterized by a shortage in the number or quality of red blood cells, which can lead to a reduced ability of the blood to carry oxygen throughout the body.',
|
70 |
-
'Hemophilia is a genetic illness that mainly affects the blood ability to clot properly. Individuals with significant hemophilia are at an elevated possibility of experiencing unforeseen bleeding episodes, which can occur in various parts of the body, including the mouth. Oral bleeding can be a sign of hemophilia and can present as gum bleeding or mouth sores.',
|
71 |
-
"Von Willebrand disease VWD is a genetic condition that impairs the blood's ability to clot properly. One of the symptoms of VWD is spontaneous gingival bleeding , which can occur without any apparent cause or trauma"),
|
72 |
-
index=0) # set default to None
|
73 |
|
74 |
-
# Define the colors for each label
|
75 |
-
|
76 |
-
if st.button('Analyze'):
|
77 |
-
if sentence and selected_options:
|
78 |
-
st.write('Please provide either a sentence or choose an option, not both.')
|
79 |
-
elif sentence:
|
80 |
-
highlight(sentence)
|
81 |
-
elif selected_options:
|
82 |
-
highlight(selected_options)
|
83 |
-
else:
|
84 |
-
st.write('Please enter a sentence or select an option from the dropdown.')
|
85 |
-
st.markdown("""---""")
|
86 |
-
st.caption("""
|
87 |
-
Developed by Applied NLP Research Lab
|
88 |
-
School of Digital Sciences,
|
89 |
-
Kerala University of Digital Sciences, Innovation and Technology,
|
90 |
-
Technopark phase 4, Thiruvananthapuram, India |
|
91 |
-
Email: [email protected]| https://sites.google.com/duk.ac.in/anlprl
|
92 |
|
93 |
-
""", unsafe_allow_html=True)
|
94 |
|
95 |
-
if __name__ == '__main__':
|
96 |
-
main()
|
97 |
|
98 |
|
99 |
|
|
|
9 |
|
10 |
|
11 |
def predict(new_data):
|
12 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
tokens = tokenizer(new_data.split(), padding=True, truncation=True, max_length=128, return_tensors='pt')
|
14 |
with torch.no_grad():
|
15 |
embeddings = model(tokens['input_ids'], attention_mask=tokens['attention_mask'])[0][:, 0, :].numpy()
|
|
|
28 |
labels.append(label)
|
29 |
prev_label=label
|
30 |
return(data,labels)
|
|
|
31 |
|
32 |
+
|
33 |
def highlight(sentence):
|
34 |
highlighted_text = ""
|
35 |
entity_colors = {"Symptom":"#87cefa","Medical Condition":"#ffb6c1"}
|
|
|
47 |
highlighted_text += f'{words} '
|
48 |
st.markdown(highlighted_text, unsafe_allow_html=True)
|
49 |
|
50 |
+
#Load the trained model
|
51 |
+
with open(r"E:\biobert_rf.pkl", 'rb') as f:
|
52 |
+
rf = pickle.load(f)
|
53 |
+
# Load the BioBERT model and tokenizer
|
54 |
+
model_name = "dmis-lab/biobert-base-cased-v1.1"
|
55 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
56 |
+
model = AutoModel.from_pretrained(model_name)
|
57 |
+
st.title('Oral Medicine Meets NLP')
|
58 |
+
st.subheader('Named Entity Recoginition System For Oral Medicine ')
|
59 |
+
sentence = st.text_area('Enter a sentence:')
|
60 |
+
|
61 |
+
st.write("OR")
|
62 |
+
selected_options = st.selectbox(
|
63 |
+
'Choose a text from dropdown: ',
|
64 |
+
(" ",
|
65 |
+
'Anemia and gingival bleeding are connected in that anemia can be a contributing cause to the occurrence of gingival bleeding. Anemia is a condition characterized by a shortage in the number or quality of red blood cells, which can lead to a reduced ability of the blood to carry oxygen throughout the body.',
|
66 |
+
'Hemophilia is a genetic illness that mainly affects the blood ability to clot properly. Individuals with significant hemophilia are at an elevated possibility of experiencing unforeseen bleeding episodes, which can occur in various parts of the body, including the mouth. Oral bleeding can be a sign of hemophilia and can present as gum bleeding or mouth sores.',
|
67 |
+
"Von Willebrand disease VWD is a genetic condition that impairs the blood's ability to clot properly. One of the symptoms of VWD is spontaneous gingival bleeding , which can occur without any apparent cause or trauma")) # set default to None
|
68 |
+
|
69 |
+
# Define the colors for each label
|
70 |
+
|
71 |
+
if st.button('Analyze'):
|
72 |
+
if sentence:
|
73 |
+
highlight(sentence)
|
74 |
+
elif selected_options:
|
75 |
+
highlight(selected_options)
|
76 |
+
else:
|
77 |
+
st.write("Please enter a text or select an example to analyze")
|
78 |
+
|
79 |
|
80 |
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
|
|
84 |
|
|
|
|
|
85 |
|
86 |
|
87 |
|