Moran commited on
Commit
d305ec3
·
1 Parent(s): 1859836

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -2,7 +2,9 @@ import streamlit as st
2
  import time
3
  from huggingface_hub import from_pretrained_fastai
4
  import gensim
5
-
 
 
6
 
7
  # textRank
8
  def textrank(corpus, ratio=0.2):
@@ -44,21 +46,26 @@ model_type = st.radio('Pick a model',['RankText', 'Bart'])
44
  text = st.text_area('Enter or paste your text')
45
 
46
  def start_summarize(long_text, model):
 
 
47
  if model=="RankText":
48
  summary = textrank(long_text)[0]
49
- if summary=="":
50
- summary = long_text
51
  else:
52
  if model=="Bart":
53
  repo_id = "Aviv/Moran_Aviv_Bart"
54
  inf_learn = from_pretrained_fastai(repo_id)
55
  summary = inf_learn.blurr_generate([long_text])[0]['generated_texts']
56
- st.success(summary)
57
- time.sleep(10)
58
- grade = st.select_slider(
59
- 'What do you think about the summary?',
60
- options=['Bad', 'Good', 'Excellent'],
61
- value=('Good'))
 
 
 
62
 
63
  st.button('Summarize', on_click=start_summarize, args=(text, model_type, ) )
64
  # increment = st.button('Increment', on_click=increment_counter,
 
2
  import time
3
  from huggingface_hub import from_pretrained_fastai
4
  import gensim
5
+ import nltk
6
+ nltk.download('punkt')
7
+ from nltk.tokenize import sent_tokenize
8
 
9
  # textRank
10
  def textrank(corpus, ratio=0.2):
 
46
  text = st.text_area('Enter or paste your text')
47
 
48
  def start_summarize(long_text, model):
49
+ num_of_sentences = len(sent_tokenize(long_text))
50
+ if num_of_sentences > 4:
51
  if model=="RankText":
52
  summary = textrank(long_text)[0]
53
+ # if summary=="":
54
+ # summary = long_text
55
  else:
56
  if model=="Bart":
57
  repo_id = "Aviv/Moran_Aviv_Bart"
58
  inf_learn = from_pretrained_fastai(repo_id)
59
  summary = inf_learn.blurr_generate([long_text])[0]['generated_texts']
60
+ # repo_id = "Aviv/Moran_Aviv_Bart"
61
+ # inf_learn = from_pretrained_fastai(repo_id)
62
+ else:
63
+ summary = long_text
64
+ st.success(summary)
65
+ # time.sleep(10)
66
+ grade = st.select_slider('What do you think about the summary?', options=['Bad', 'Good', 'Excellent'], value=('Good'))
67
+
68
+
69
 
70
  st.button('Summarize', on_click=start_summarize, args=(text, model_type, ) )
71
  # increment = st.button('Increment', on_click=increment_counter,