File size: 1,636 Bytes
02649bc
0366b15
99218ae
ab06917
d305ec3
c3bcfeb
d305ec3
e3ddc6a
4090c46
e3ddc6a
0206efd
ab06917
 
50699d0
82a2c37
ab06917
e3ddc6a
ab06917
0206efd
5bc0d22
 
 
0206efd
5bc0d22
 
1a85251
5bc0d22
 
 
 
2e63706
2700cac
 
bfeba45
6fc2b4c
e3ddc6a
e18be68
 
71105bb
 
2c71b9c
e18be68
 
49a1d79
28ebbb9
ccfd87d
 
535d55e
0206efd
5bc0d22
 
202dc49
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import streamlit as st
import time
from huggingface_hub import from_pretrained_fastai
import gensim
import nltk
nltk.download('punkt')
from nltk.tokenize import sent_tokenize

st.caption(" © Aviv Lazar & Moran Shemesh")

def textrank(corpus, ratio):    
  if type(corpus) is str:        
      corpus = [corpus]    
  summaries = [gensim.summarization.summarize(txt, ratio=ratio) for txt in corpus][0]
#  st.write(summaries)   
  return summaries
#end textrank

def start_summarize(long_text, model, size):
  num_of_sentences = len(sent_tokenize(long_text))
  if num_of_sentences > 4:
    if model=="RankText":
      summary = textrank(long_text, size/100)
    elif model=="Bart":
      repo_id = "Aviv/Moran_Aviv_Bart"
      
      inf_learn = from_pretrained_fastai(repo_id)  
      summary = inf_learn.blurr_generate([long_text])[0]['generated_texts']
  else:
    summary = long_text
  st.success(summary)
  st.select_slider('What do you think about the summary?', options=['Bad', 'Good', 'Excellent'], value=('Good'))


#end start_summarize

st.title ("Text Summarization") 
model_type = st.radio('Pick a model',['RankText', 'Bart'])
textrank_summary_size = 0
if model_type=="RankText":
  textrank_summary_size = st.slider('How long would you like the summary to be? (Percentage of full text)', 5,50)
user_text = st.text_area('Enter or paste text to summarize') 
start = st.button('Summarize')#, on_click=start_summarize, args=(user_text, model_type,  ) )

if start:
  start = False
  st.markdown("Summary")
  with st.spinner("We are summarizing your text..."):
    start_summarize(user_text, model_type, textrank_summary_size)