Spaces:
Sleeping
Sleeping
Wilame Lima
commited on
Commit
•
dafb744
1
Parent(s):
5e6feee
First commit
Browse files- .gitignore +1 -0
- app.py +28 -0
- config.py +7 -0
- functions.py +18 -0
- requirements.txt +3 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
*.pyc
|
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from functions import *
|
2 |
+
|
3 |
+
# set the title
|
4 |
+
st.sidebar.title(DASHBOARD_TITLE)
|
5 |
+
|
6 |
+
# load the model
|
7 |
+
with st.spinner("Loading the model..."):
|
8 |
+
model = load_pipeline()
|
9 |
+
|
10 |
+
# input
|
11 |
+
text = st.text_area(value="Woman, 43, feeling pain in the stomach. No vomiting", label="Enter the text here")
|
12 |
+
submit = st.button("Submit")
|
13 |
+
|
14 |
+
if text and submit:
|
15 |
+
|
16 |
+
# get the entities
|
17 |
+
entities = model(text)
|
18 |
+
|
19 |
+
if len(entities) == 0:
|
20 |
+
st.error("No entities found")
|
21 |
+
|
22 |
+
# annotate the entities
|
23 |
+
annotated_entities = [annotate(entity) for entity in entities]
|
24 |
+
|
25 |
+
# display the entities
|
26 |
+
annotated_text(annotated_entities)
|
27 |
+
|
28 |
+
|
config.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
from annotated_text import annotated_text
|
4 |
+
|
5 |
+
|
6 |
+
DASHBOARD_TITLE = "Medical NER Dashboard"
|
7 |
+
MODEL_PATH = "Clinical-AI-Apollo/Medical-NER"
|
functions.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from config import *
|
2 |
+
|
3 |
+
@st.cache_resource
|
4 |
+
def load_pipeline():
|
5 |
+
"""
|
6 |
+
Load the pipeline
|
7 |
+
"""
|
8 |
+
return pipeline("token-classification", model=MODEL_PATH)
|
9 |
+
|
10 |
+
@st.cache_data
|
11 |
+
def annotate(entity):
|
12 |
+
|
13 |
+
"""
|
14 |
+
Annotate the text
|
15 |
+
"""
|
16 |
+
return (entity["word"].replace('▁',''), entity["entity"])
|
17 |
+
|
18 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
st-annotated-text
|
3 |
+
transformers
|