varun500 commited on
Commit
5ea6ee6
1 Parent(s): 2020d9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -12,16 +12,19 @@ def main():
12
  # Get user input
13
  doc = st.text_area("Document")
14
 
15
- # Get user choice for stopwords removal
16
- remove_stopwords = st.checkbox("Remove Stopwords")
 
 
 
 
 
 
17
 
18
  # Extract keywords
19
  if st.button("Extract Keywords"):
20
  keywords = kw_model.extract_keywords(doc, stop_words=None if remove_stopwords else "english")
21
 
22
- # Get user choice for MMR
23
- apply_mmr = st.checkbox("Apply Maximal Marginal Relevance (MMR)")
24
-
25
  if apply_mmr:
26
  # Apply Maximal Marginal Relevance (MMR)
27
  selected_keywords = []
@@ -29,9 +32,8 @@ def main():
29
 
30
  # Set the MMR hyperparameters
31
  lambda_param = 0.7 # Weight for the trade-off between relevance and diversity
32
- num_keywords = 5 # Number of keywords to select
33
 
34
- for i in range(1, num_keywords):
35
  selected_keywords_scores = [kw[1] for kw in selected_keywords]
36
  remaining_keywords = [kw for kw in keywords if kw[0] not in [kw[0] for kw in selected_keywords]]
37
  mmr_scores = kw_model.maximal_marginal_relevance(doc, remaining_keywords, selected_keywords_scores, lambda_param)
@@ -40,10 +42,10 @@ def main():
40
 
41
  keywords = selected_keywords # Update keywords with MMR-selected keywords
42
 
43
- st.write("Keywords:")
44
  for keyword, score in keywords:
45
  st.write(f"- {keyword} (Score: {score})")
46
 
47
  # Run the app
48
  if __name__ == "__main__":
49
- main()
 
12
  # Get user input
13
  doc = st.text_area("Document")
14
 
15
+ # Get user choice for stopwords removal (default checkbox)
16
+ remove_stopwords = st.checkbox("Remove Stopwords", value=True)
17
+
18
+ # Get user choice for MMR (default checkbox)
19
+ apply_mmr = st.checkbox("Apply Maximal Marginal Relevance (MMR)", value=True)
20
+
21
+ # Get user choice for number of results (slider)
22
+ num_results = st.slider("Number of Results", min_value=1, max_value=30, value=5, step=1)
23
 
24
  # Extract keywords
25
  if st.button("Extract Keywords"):
26
  keywords = kw_model.extract_keywords(doc, stop_words=None if remove_stopwords else "english")
27
 
 
 
 
28
  if apply_mmr:
29
  # Apply Maximal Marginal Relevance (MMR)
30
  selected_keywords = []
 
32
 
33
  # Set the MMR hyperparameters
34
  lambda_param = 0.7 # Weight for the trade-off between relevance and diversity
 
35
 
36
+ for i in range(1, num_results):
37
  selected_keywords_scores = [kw[1] for kw in selected_keywords]
38
  remaining_keywords = [kw for kw in keywords if kw[0] not in [kw[0] for kw in selected_keywords]]
39
  mmr_scores = kw_model.maximal_marginal_relevance(doc, remaining_keywords, selected_keywords_scores, lambda_param)
 
42
 
43
  keywords = selected_keywords # Update keywords with MMR-selected keywords
44
 
45
+ st.write(f"Top {num_results} Keywords:")
46
  for keyword, score in keywords:
47
  st.write(f"- {keyword} (Score: {score})")
48
 
49
  # Run the app
50
  if __name__ == "__main__":
51
+ main()