Harsh502s commited on
Commit
a70ecf8
·
1 Parent(s): 0797b32

Fix tag assignment bug and add loading spinners

Browse files
Files changed (3) hide show
  1. Pages/About.py +1 -1
  2. Pages/Models.py +24 -11
  3. Pages/Topic Model Results.py +13 -8
Pages/About.py CHANGED
@@ -4,7 +4,7 @@ import streamlit as st
4
  # Display the about page of the app with information about the creator, code and data.
5
  def about_page():
6
  with st.container():
7
- col = st.columns([1.5, 1])
8
  with col[0]:
9
  st.title("About Us")
10
  st.write("\n")
 
4
  # Display the about page of the app with information about the creator, code and data.
5
  def about_page():
6
  with st.container():
7
+ col = st.columns([1, 1])
8
  with col[0]:
9
  st.title("About Us")
10
  st.write("\n")
Pages/Models.py CHANGED
@@ -79,9 +79,12 @@ def supervised_page():
79
  text = st.text_area("Enter text to assign tags", height=200, key="supervised_text")
80
  text = clean_text(text)
81
  if st.button("Assign tags", key="supervised_button"):
82
- with st.spinner("Assigning tags..."):
83
- tags = tag_cnn_model(text)[0]
84
- tagger_component("Tags:", tags)
 
 
 
85
 
86
 
87
  # Display the unsupervised model using bertopic page of the app
@@ -95,8 +98,11 @@ def unsupervised_page_bertopic():
95
  "Enter number of tags to assign", value=5, key="unsupervised_n_bertopic"
96
  )
97
  if st.button("Assign tags", key="unsupervised_button_bertopic"):
98
- with st.spinner("Assigning tags..."):
99
- output_bertopic(text, n)
 
 
 
100
 
101
 
102
  def unsupervised_page_keybert():
@@ -109,8 +115,11 @@ def unsupervised_page_keybert():
109
  "Enter number of tags to assign", value=5, key="unsupervised_n_keybert"
110
  )
111
  if st.button("Assign tags", key="unsupervised_button_keybert"):
112
- with st.spinner("Assigning tags..."):
113
- output_keybert(text, n)
 
 
 
114
 
115
 
116
  # Display the unsupervised model using bertopic page of the app
@@ -124,16 +133,19 @@ def unsupervised_page_mmr():
124
  "Enter number of tags to assign", value=5, key="unsupervised_n_mmr"
125
  )
126
  if st.button("Assign tags", key="unsupervised_button_mmr"):
127
- with st.spinner("Assigning tags..."):
128
- output_mmr(text, n)
 
 
 
129
 
130
 
131
  # Display the model page of the app
132
  def model_page():
133
  stype_for_page = """
134
  <style>
135
- button.st-emotion-cache-c766yy.ef3psqc11:hover {
136
- scale: 1.07;
137
  transition-duration: 0.3s;
138
  }
139
  </style>
@@ -159,6 +171,7 @@ def model_page():
159
  with tab4:
160
  unsupervised_page_bertopic()
161
  with st.container():
 
162
  with st.expander("Example Texts", expanded=False):
163
  st.markdown(
164
  """
 
79
  text = st.text_area("Enter text to assign tags", height=200, key="supervised_text")
80
  text = clean_text(text)
81
  if st.button("Assign tags", key="supervised_button"):
82
+ if text == "":
83
+ st.error("Please enter some text to assign tags")
84
+ else:
85
+ with st.spinner("Assigning tags..."):
86
+ tags = tag_cnn_model(text)[0]
87
+ tagger_component("Tags:", tags)
88
 
89
 
90
  # Display the unsupervised model using bertopic page of the app
 
98
  "Enter number of tags to assign", value=5, key="unsupervised_n_bertopic"
99
  )
100
  if st.button("Assign tags", key="unsupervised_button_bertopic"):
101
+ if text == "":
102
+ st.error("Please enter some text to assign tags")
103
+ else:
104
+ with st.spinner("Assigning tags..."):
105
+ output_bertopic(text, n)
106
 
107
 
108
  def unsupervised_page_keybert():
 
115
  "Enter number of tags to assign", value=5, key="unsupervised_n_keybert"
116
  )
117
  if st.button("Assign tags", key="unsupervised_button_keybert"):
118
+ if text == "":
119
+ st.error("Please enter some text to assign tags")
120
+ else:
121
+ with st.spinner("Assigning tags..."):
122
+ output_keybert(text, n)
123
 
124
 
125
  # Display the unsupervised model using bertopic page of the app
 
133
  "Enter number of tags to assign", value=5, key="unsupervised_n_mmr"
134
  )
135
  if st.button("Assign tags", key="unsupervised_button_mmr"):
136
+ if text == "":
137
+ st.error("Please enter some text to assign tags")
138
+ else:
139
+ with st.spinner("Assigning tags..."):
140
+ output_mmr(text, n)
141
 
142
 
143
  # Display the model page of the app
144
  def model_page():
145
  stype_for_page = """
146
  <style>
147
+ [data-testid="baseButton-secondary"]:hover {
148
+ scale: 1.05;
149
  transition-duration: 0.3s;
150
  }
151
  </style>
 
171
  with tab4:
172
  unsupervised_page_bertopic()
173
  with st.container():
174
+ st.info("Click on the arrow to expand the example texts.")
175
  with st.expander("Example Texts", expanded=False):
176
  st.markdown(
177
  """
Pages/Topic Model Results.py CHANGED
@@ -22,19 +22,24 @@ def topic_model_results():
22
  ]
23
  )
24
  with tab1:
25
- st.write(bertopic_model.visualize_barchart(top_n_topics=20))
 
26
  with tab2:
27
- st.write(bertopic_model.visualize_topics())
 
28
  with tab3:
29
- st.write(
30
- bertopic_model.visualize_distribution(
31
- bertopic_model.probabilities_[0], min_probability=0.015
 
 
32
  )
33
- )
34
  with tab4:
35
- st.write(bertopic_model.visualize_hierarchy())
 
36
  with tab5:
37
- st.write(bertopic_model.visualize_heatmap())
 
38
 
39
 
40
  if __name__ == "__main__":
 
22
  ]
23
  )
24
  with tab1:
25
+ with st.spinner("Loading the Visualization..."):
26
+ st.write(bertopic_model.visualize_barchart(top_n_topics=20))
27
  with tab2:
28
+ with st.spinner("Loading the Visualization..."):
29
+ st.write(bertopic_model.visualize_topics())
30
  with tab3:
31
+ with st.spinner("Loading the Visualization..."):
32
+ st.write(
33
+ bertopic_model.visualize_distribution(
34
+ bertopic_model.probabilities_[0], min_probability=0.015
35
+ )
36
  )
 
37
  with tab4:
38
+ with st.spinner("Loading the Visualization..."):
39
+ st.write(bertopic_model.visualize_hierarchy())
40
  with tab5:
41
+ with st.spinner("Loading the Visualization..."):
42
+ st.write(bertopic_model.visualize_heatmap())
43
 
44
 
45
  if __name__ == "__main__":