wzkariampuzha commited on
Commit
9f09f8c
1 Parent(s): 6792ef6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -11,10 +11,12 @@ import tensorflow as tf
11
  import pickle
12
  import plotly.graph_objects as go
13
 
14
- ########## Title for the Web App ##########
15
  st.markdown('''<img src="https://huggingface.co/spaces/ncats/EpiPipeline4GARD/resolve/main/Logo_GARD_fullres.png" alt="NIH Genetic and Rare Diseases Information Center Logo" width=550>''',unsafe_allow_html=True)
16
  #st.markdown("![National Center for Advancing Translational Sciences (NCATS) Logo](https://huggingface.co/spaces/ncats/EpiPipeline4GARD/resolve/main/NCATS_logo.png)")
17
  #st.markdown('''<img src="https://huggingface.co/spaces/ncats/EpiPipeline4GARD/raw/main/NCATS_logo.svg" alt="National Center for Advancing Translational Sciences Logo" width="800" height="300">''',unsafe_allow_html=True)
 
 
18
  st.title("Epidemiology Extraction Pipeline for Rare Diseases")
19
  #st.subheader("National Center for Advancing Translational Sciences (NIH/NCATS)")
20
 
@@ -34,8 +36,11 @@ st.markdown(
34
  unsafe_allow_html=True,
35
  )
36
 
 
37
  st.markdown("This application was built by the [National Center for Advancing Translational Sciences (NCATS)](https://ncats.nih.gov/) for the [National Institutes of Health (NIH)](https://www.nih.gov/) [Genetic and Rare Diseases Information Center](https://rarediseases.info.nih.gov/) to automatically search PubMed abstracts for rare disease epidemiology information.")
38
 
 
 
39
  #max_results is Maximum number of PubMed ID's to retrieve BEFORE filtering
40
  max_results = st.sidebar.number_input("Maximum number of articles to find in PubMed", min_value=1, max_value=None, value=50)
41
 
@@ -43,6 +48,8 @@ filtering = st.sidebar.radio("What type of filtering would you like?",('Strict',
43
 
44
  extract_diseases = st.sidebar.checkbox("Extract Rare Diseases", value=False)
45
 
 
 
46
  @st.experimental_singleton(show_spinner=False)
47
  def load_models_experimental():
48
  classify_model_vars = classify_abs.init_classify_model()
@@ -50,26 +57,15 @@ def load_models_experimental():
50
  GARD_dict, max_length = extract_abs.load_GARD_diseases()
51
  return classify_model_vars, NER_pipeline, entity_classes, GARD_dict, max_length
52
 
53
- @st.cache(allow_output_mutation=True)
54
- def load_models():
55
- # load the tokenizer
56
- with open('tokenizer.pickle', 'rb') as handle:
57
- classify_tokenizer = pickle.load(handle)
58
-
59
- # load the model
60
- classify_model = tf.keras.models.load_model("LSTM_RNN_Model")
61
-
62
- #classify_model_vars = classify_abs.init_classify_model()
63
- NER_pipeline, entity_classes = extract_abs.init_NER_pipeline()
64
- GARD_dict, max_length = extract_abs.load_GARD_diseases()
65
- return classify_tokenizer, classify_model, NER_pipeline, entity_classes, GARD_dict, max_length
66
 
67
  @st.cache
68
  def convert_df(df):
69
  # IMPORTANT: Cache the conversion to prevent computation on every rerun
70
  return df.to_csv().encode('utf-8')
71
 
72
- #@st.experimental_memo
 
73
  @st.cache(allow_output_mutation=True)
74
  def epi_sankey(sankey_data,disease_or_gard_id):
75
  gathered, relevant, epidemiologic = sankey_data
@@ -96,6 +92,8 @@ def epi_sankey(sankey_data,disease_or_gard_id):
96
 
97
  return fig
98
 
 
 
99
  with st.spinner('Loading Epidemiology Models and Dependencies...'):
100
  classify_model_vars, NER_pipeline, entity_classes, GARD_dict, max_length = load_models_experimental()
101
  #classify_tokenizer, classify_model, NER_pipeline, entity_classes, GARD_dict, max_length = load_models()
@@ -104,9 +102,13 @@ with st.spinner('Loading Epidemiology Models and Dependencies...'):
104
  #nlpSci = spacy.load("en_ner_bc5cdr_md")
105
  #nlpSci2 = spacy.load('en_ner_bionlp13cg_md')
106
  #classify_model_vars = (nlp, nlpSci, nlpSci2, classify_model, classify_tokenizer)
 
107
  loaded = st.success('All Models and Dependencies Loaded!')
 
108
  st.markdown("Input a rare disease term or GARD ID.")
109
- disease_or_gard_id = st.text_input()
 
 
110
  loaded.empty()
111
 
112
  st.markdown("Examples of rare diseases include [**Fellman syndrome**](https://rarediseases.info.nih.gov/diseases/1/gracile-syndrome), [**Classic Homocystinuria**](https://rarediseases.info.nih.gov/diseases/6667/classic-homocystinuria), [**7383**](https://rarediseases.info.nih.gov/diseases/7383/phenylketonuria), and [**GARD:0009941**](https://rarediseases.info.nih.gov/diseases/9941/fshmd1a).")
 
11
  import pickle
12
  import plotly.graph_objects as go
13
 
14
+ #### LOGO ####
15
  st.markdown('''<img src="https://huggingface.co/spaces/ncats/EpiPipeline4GARD/resolve/main/Logo_GARD_fullres.png" alt="NIH Genetic and Rare Diseases Information Center Logo" width=550>''',unsafe_allow_html=True)
16
  #st.markdown("![National Center for Advancing Translational Sciences (NCATS) Logo](https://huggingface.co/spaces/ncats/EpiPipeline4GARD/resolve/main/NCATS_logo.png)")
17
  #st.markdown('''<img src="https://huggingface.co/spaces/ncats/EpiPipeline4GARD/raw/main/NCATS_logo.svg" alt="National Center for Advancing Translational Sciences Logo" width="800" height="300">''',unsafe_allow_html=True)
18
+
19
+ #### TITLE ####
20
  st.title("Epidemiology Extraction Pipeline for Rare Diseases")
21
  #st.subheader("National Center for Advancing Translational Sciences (NIH/NCATS)")
22
 
 
36
  unsafe_allow_html=True,
37
  )
38
 
39
+ #### DESCRIPTION ####
40
  st.markdown("This application was built by the [National Center for Advancing Translational Sciences (NCATS)](https://ncats.nih.gov/) for the [National Institutes of Health (NIH)](https://www.nih.gov/) [Genetic and Rare Diseases Information Center](https://rarediseases.info.nih.gov/) to automatically search PubMed abstracts for rare disease epidemiology information.")
41
 
42
+ #### SIDEBAR WIDGETS ####
43
+
44
  #max_results is Maximum number of PubMed ID's to retrieve BEFORE filtering
45
  max_results = st.sidebar.number_input("Maximum number of articles to find in PubMed", min_value=1, max_value=None, value=50)
46
 
 
48
 
49
  extract_diseases = st.sidebar.checkbox("Extract Rare Diseases", value=False)
50
 
51
+ #### MODEL LOADING ####
52
+
53
  @st.experimental_singleton(show_spinner=False)
54
  def load_models_experimental():
55
  classify_model_vars = classify_abs.init_classify_model()
 
57
  GARD_dict, max_length = extract_abs.load_GARD_diseases()
58
  return classify_model_vars, NER_pipeline, entity_classes, GARD_dict, max_length
59
 
60
+ #### DOWNLOAD FUNCTION ####
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  @st.cache
63
  def convert_df(df):
64
  # IMPORTANT: Cache the conversion to prevent computation on every rerun
65
  return df.to_csv().encode('utf-8')
66
 
67
+ #### SANKEY FUNCTION ####
68
+
69
  @st.cache(allow_output_mutation=True)
70
  def epi_sankey(sankey_data,disease_or_gard_id):
71
  gathered, relevant, epidemiologic = sankey_data
 
92
 
93
  return fig
94
 
95
+ #### BEGIN APP ####
96
+
97
  with st.spinner('Loading Epidemiology Models and Dependencies...'):
98
  classify_model_vars, NER_pipeline, entity_classes, GARD_dict, max_length = load_models_experimental()
99
  #classify_tokenizer, classify_model, NER_pipeline, entity_classes, GARD_dict, max_length = load_models()
 
102
  #nlpSci = spacy.load("en_ner_bc5cdr_md")
103
  #nlpSci2 = spacy.load('en_ner_bionlp13cg_md')
104
  #classify_model_vars = (nlp, nlpSci, nlpSci2, classify_model, classify_tokenizer)
105
+
106
  loaded = st.success('All Models and Dependencies Loaded!')
107
+
108
  st.markdown("Input a rare disease term or GARD ID.")
109
+
110
+ disease_or_gard_id = st.text_input('')
111
+
112
  loaded.empty()
113
 
114
  st.markdown("Examples of rare diseases include [**Fellman syndrome**](https://rarediseases.info.nih.gov/diseases/1/gracile-syndrome), [**Classic Homocystinuria**](https://rarediseases.info.nih.gov/diseases/6667/classic-homocystinuria), [**7383**](https://rarediseases.info.nih.gov/diseases/7383/phenylketonuria), and [**GARD:0009941**](https://rarediseases.info.nih.gov/diseases/9941/fshmd1a).")