Gladiator commited on
Commit
ea0864a
1 Parent(s): 9471041
Files changed (1) hide show
  1. app.py +8 -15
app.py CHANGED
@@ -3,14 +3,16 @@ import streamlit as st
3
  from extractive_summarizer.model_processors import Summarizer
4
  from transformers import T5Tokenizer, T5ForConditionalGeneration, T5Config
5
 
6
- def abstractive_summarizer(text : str, model):
7
- device = torch.device("cpu")
 
 
8
  preprocess_text = text.strip().replace("\n", "")
9
  t5_prepared_text = "summarize: " + preprocess_text
10
  tokenized_text = tokenizer.encode(t5_prepared_text, return_tensors="pt").to("cpu")
11
 
12
  # summmarize
13
- summary_ids = model.generate(tokenized_text,
14
  num_beams=4,
15
  no_repeat_ngram_size=2,
16
  min_length=30,
@@ -21,17 +23,6 @@ def abstractive_summarizer(text : str, model):
21
  return abs_summarized_text
22
 
23
  if __name__ == "__main__":
24
- # ---------------------
25
- # download models
26
- # ---------------------
27
- abs_model = T5ForConditionalGeneration.from_pretrained('t5-large')
28
- tokenizer = T5Tokenizer.from_pretrained('t5-large')
29
- device = torch.device('cpu')
30
-
31
- # init extractive summarizer (bad practice, fix later)
32
- # init model
33
- ext_model = Summarizer()
34
-
35
  # ---------------------------------
36
  # Main Application
37
  # ---------------------------------
@@ -51,10 +42,12 @@ if __name__ == "__main__":
51
  if summarize_type == "Extractive":
52
  # extractive summarizer
53
 
 
54
  summarized_text = ext_model(inp_text, num_sentences=5)
55
 
56
  elif summarize_type == "Abstractive":
57
- summarized_text = abstractive_summarizer(inp_text, model=abs_model)
 
58
 
59
  # final summarized output
60
  st.subheader("Summarized text")
 
3
  from extractive_summarizer.model_processors import Summarizer
4
  from transformers import T5Tokenizer, T5ForConditionalGeneration, T5Config
5
 
6
+ def abstractive_summarizer(text : str):
7
+ abs_model = T5ForConditionalGeneration.from_pretrained('t5-large')
8
+ tokenizer = T5Tokenizer.from_pretrained('t5-large')
9
+ device = torch.device('cpu')
10
  preprocess_text = text.strip().replace("\n", "")
11
  t5_prepared_text = "summarize: " + preprocess_text
12
  tokenized_text = tokenizer.encode(t5_prepared_text, return_tensors="pt").to("cpu")
13
 
14
  # summmarize
15
+ summary_ids = abs_model.generate(tokenized_text,
16
  num_beams=4,
17
  no_repeat_ngram_size=2,
18
  min_length=30,
 
23
  return abs_summarized_text
24
 
25
  if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
26
  # ---------------------------------
27
  # Main Application
28
  # ---------------------------------
 
42
  if summarize_type == "Extractive":
43
  # extractive summarizer
44
 
45
+ ext_model = Summarizer()
46
  summarized_text = ext_model(inp_text, num_sentences=5)
47
 
48
  elif summarize_type == "Abstractive":
49
+
50
+ summarized_text = abstractive_summarizer(inp_text)
51
 
52
  # final summarized output
53
  st.subheader("Summarized text")