-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from wellcometrust/visualize
Add grants_tagger visualize
- Loading branch information
Showing
9 changed files
with
173 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,6 @@ venv/** | |
|
||
# Logs | ||
logs/ | ||
|
||
# Notebooks | ||
notebooks/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM python:3.8 | ||
|
||
WORKDIR /code | ||
|
||
COPY grants_tagger/ /code/grants_tagger | ||
COPY setup.py /code | ||
COPY requirements.txt /code | ||
|
||
RUN pip install --upgrade pip | ||
RUN pip install -r requirements.txt | ||
RUN pip install . --no-dependencies | ||
|
||
COPY models/disease_mesh_cnn-2021.03.1/ models/disease_mesh_cnn-2021.03.1/ | ||
COPY models/tfidf-svm-2020.05.2.pkl models/ | ||
COPY models/scibert-2020.05.5/ models/scibert-2020.05.5/ | ||
COPY models/label_binarizer.pkl models/ | ||
COPY models/disease_mesh_label_binarizer.pkl models/ | ||
|
||
CMD ["streamlit", "run", "grants_tagger/streamlit_visualize.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import streamlit as st | ||
import pandas as pd | ||
|
||
from grants_tagger.predict import predict_tags | ||
|
||
threshold = st.sidebar.slider("Threshold", min_value=0.0, max_value=1.0, value=0.5) | ||
text = st.text_area('Grant abstract', 'The cell is...', height=300) | ||
|
||
models = { | ||
"disease_mesh_cnn-2021.03.1": { | ||
"model_path": "models/disease_mesh_cnn-2021.03.1/", | ||
"label_binarizer_path": "models/disease_mesh_label_binarizer.pkl", | ||
"approach": "mesh-cnn" | ||
}, | ||
"tfidf-svm-2020.05.2": { | ||
"model_path": "models/tfidf-svm-2020.05.2.pkl", | ||
"label_binarizer_path": "models/label_binarizer.pkl", | ||
"approach": "tfidf-svm" | ||
}, | ||
"scibert-2020.05.5": { | ||
"model_path": "models/scibert-2020.05.5/", | ||
"label_binarizer_path": "models/label_binarizer.pkl", | ||
"approach": "scibert" | ||
} | ||
} | ||
|
||
model_option = st.sidebar.selectbox("Model", options=list(models.keys())) | ||
model = models[model_option] | ||
|
||
probabilities = st.sidebar.checkbox("Display probabilities") | ||
|
||
with st.spinner('Calculating tags...'): | ||
tags = predict_tags([text], model["model_path"], model["label_binarizer_path"], | ||
model["approach"], probabilities=probabilities, threshold=threshold) | ||
tags = tags[0] | ||
st.success("Done!") | ||
|
||
if probabilities: | ||
tags = [{"Tag": tag, "Prob": prob} for tag, prob in tags.items() if prob > threshold] | ||
st.table(pd.DataFrame(tags)) | ||
else: | ||
for tag in tags: | ||
st.button(tag) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.