varun500 commited on
Commit
c6e9f07
·
1 Parent(s): 5ea6ee6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -18
app.py CHANGED
@@ -21,29 +21,24 @@ def main():
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 = []
31
- selected_keywords.append(keywords[0]) # Select the top-scoring keyword
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)
40
- max_mmr_index = mmr_scores.index(max(mmr_scores))
41
- selected_keywords.append(remaining_keywords[max_mmr_index])
 
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
 
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
+ # Get user choice for minimum n-gram value (default textbox)
25
+ min_ngram = st.number_input("Minimum N-gram", value=1, min_value=1, max_value=10, step=1)
 
 
 
 
 
 
26
 
27
+ # Get user choice for maximum n-gram value (default textbox)
28
+ max_ngram = st.number_input("Maximum N-gram", value=3, min_value=1, max_value=10, step=1)
29
 
30
+ # Extract keywords
31
+ if st.button("Extract Keywords"):
32
+ keywords = kw_model.extract_keywords(doc,
33
+ keyphrase_ngram_range=(min_ngram, max_ngram),
34
+ stop_words='english' if remove_stopwords else None,
35
+ use_mmr=apply_mmr,
36
+ diversity=0.2)
37
 
38
+ selected_keywords = keywords[:num_results]
39
 
40
  st.write(f"Top {num_results} Keywords:")
41
+ for keyword, score in selected_keywords:
42
  st.write(f"- {keyword} (Score: {score})")
43
 
44
  # Run the app