-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add grants_tagger visualize #74
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,6 @@ venv/** | |
|
||
# Logs | ||
logs/ | ||
|
||
# Notebooks | ||
notebooks/ |
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"] |
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": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice model dispatcher, although in the future you can probably accept the model config file as parameter to your There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I plan to save all these in |
||
"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...'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So easy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. <3 streamlit |
||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if there is a way to run Streamlit programatically, like Flasks'
import app; app.run()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not find a way, but will look again. Btw @jdu is this a good way if invoking a script? I remember hunter had mentioned that some python way was better than another
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a few different ways of spawning a sub-process across the different python versions. This is probably fine for what is just a labs component.