vanessbut commited on
Commit
033c2c9
1 Parent(s): bfa3a29

Исправление кандидатов.

Browse files
Files changed (2) hide show
  1. app.py +5 -1
  2. utils/utils.py +5 -2
app.py CHANGED
@@ -75,6 +75,10 @@ text = preprocess([title + ". " + abstract])[0]
75
  if not text is None and len(text) > 0:
76
  #keywords = get_candidates(text, main_nlp)
77
  keywords = get_keywords(text, main_nlp, main_model, main_tokenizer)
 
 
 
 
78
  labels = [kw[0].replace(' ', '\n') for kw in keywords]
79
  scores = [kw[1] for kw in keywords]
80
  #st.markdown(f"{keywords}")
@@ -97,4 +101,4 @@ if not text is None and len(text) > 0:
97
 
98
  st.pyplot(fig)
99
  else:
100
- st.markdown("Please, try to enter something.")
 
75
  if not text is None and len(text) > 0:
76
  #keywords = get_candidates(text, main_nlp)
77
  keywords = get_keywords(text, main_nlp, main_model, main_tokenizer)
78
+ if keywords is None:
79
+ st.markdown("Вы ввели либо слишком короткий, либо грамматически некорректный текст. Попробуйте еще раз.")
80
+ break
81
+
82
  labels = [kw[0].replace(' ', '\n') for kw in keywords]
83
  scores = [kw[1] for kw in keywords]
84
  #st.markdown(f"{keywords}")
 
101
 
102
  st.pyplot(fig)
103
  else:
104
+ st.markdown("Пожалуйста, введите что-нибудь.")
utils/utils.py CHANGED
@@ -121,8 +121,11 @@ def score_candidates(text, candidates, model, tokenizer):
121
 
122
 
123
  def get_keywords(text, nlp, model, tokenizer, top=0.95, max_words=None):
124
- candidates = get_candidates(text, nlp)
125
- score = score_candidates(text, candidates, model, tokenizer)
 
 
 
126
 
127
  candidates_scored = [(candidates[index], score[index]) for index in score.argsort()[::-1]]
128
 
 
121
 
122
 
123
  def get_keywords(text, nlp, model, tokenizer, top=0.95, max_words=None):
124
+ try:
125
+ candidates = get_candidates(text, nlp)
126
+ score = score_candidates(text, candidates, model, tokenizer)
127
+ except Exception as ex:
128
+ return None
129
 
130
  candidates_scored = [(candidates[index], score[index]) for index in score.argsort()[::-1]]
131