loubnabnl HF staff commited on
Commit
85a8c20
1 Parent(s): f2ed9e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -15,20 +15,32 @@ Our approach involved prompting Mixtral to evaluate whether the topics in each c
15
  Additionally, the model was tasked with finding the topic of each cluster.
16
  """)
17
 
 
18
  @st.cache_data
19
- def load_data(min_score=1, max_score=10):
20
  ds = load_dataset("HuggingFaceTB/FW_clusters_free_topics", split="train", token=HF_TOKEN, num_proc=2)
21
- ds = ds.filter(lambda x: int(x['educational_score']) <= max_score and int(x['educational_score']) >= min_score)
 
 
 
 
 
 
 
 
22
  return ds
23
 
24
  st.subheader("Cluster information")
25
- col_1, col_2 = st.columns(2)
26
  with col_1:
27
  min_value = st.slider('Select minimum educational score', 1, 10, 1, key='min_score')
28
  with col_2:
29
  max_value = st.slider('Select maximum educational score', 1, 10, 10, key='max_score')
30
-
31
- ds = load_data(min_value, max_value)
 
 
 
32
  selected_category_type = st.selectbox("Select a topic", categories)
33
  categories = list(set(ds["category"]))
34
  selected_cluster = ds.filter(lambda x: x['category'] == selected_category)
 
15
  Additionally, the model was tasked with finding the topic of each cluster.
16
  """)
17
 
18
+
19
  @st.cache_data
20
+ def load_data(min_score=1, max_score=10, show_special=False):
21
  ds = load_dataset("HuggingFaceTB/FW_clusters_free_topics", split="train", token=HF_TOKEN, num_proc=2)
22
+ def filter_func(x):
23
+ try:
24
+ score = int(x['educational_score'])
25
+ return max(min_score <= score <= max_score, show_special)
26
+ except (ValueError, TypeError):
27
+ # Return True if show_special is checked and educational_score is None or ''
28
+ return show_special
29
+
30
+ ds = ds.filter(filter_func)
31
  return ds
32
 
33
  st.subheader("Cluster information")
34
+ col_1, col_2, col_3 = st.columns(2)
35
  with col_1:
36
  min_value = st.slider('Select minimum educational score', 1, 10, 1, key='min_score')
37
  with col_2:
38
  max_value = st.slider('Select maximum educational score', 1, 10, 10, key='max_score')
39
+ with col_3:
40
+ show_special = st.checkbox('Show clusters with undefined educational score', False)
41
+
42
+ # Load data based on slider values and checkbox status
43
+ ds = load_data(min_value, max_value, show_special)
44
  selected_category_type = st.selectbox("Select a topic", categories)
45
  categories = list(set(ds["category"]))
46
  selected_cluster = ds.filter(lambda x: x['category'] == selected_category)