Spaces:
Runtime error
Runtime error
try reducing run time
Browse files
app.py
CHANGED
|
@@ -3,11 +3,7 @@ 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):
|
| 7 |
-
|
| 8 |
-
model = T5ForConditionalGeneration.from_pretrained('t5-large')
|
| 9 |
-
tokenizer = T5Tokenizer.from_pretrained('t5-large')
|
| 10 |
-
device = torch.device('cpu')
|
| 11 |
|
| 12 |
preprocess_text = text.strip().replace("\n", "")
|
| 13 |
t5_prepared_text = "summarize: " + preprocess_text
|
|
@@ -25,7 +21,20 @@ def abstractive_summarizer(text : str):
|
|
| 25 |
return abs_summarized_text
|
| 26 |
|
| 27 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
st.title("Text Summarizer π")
|
| 30 |
summarize_type = st.sidebar.selectbox("Summarization type", options=["Extractive", "Abstractive"])
|
| 31 |
|
|
@@ -41,12 +50,11 @@ if __name__ == "__main__":
|
|
| 41 |
if summarize:
|
| 42 |
if summarize_type == "Extractive":
|
| 43 |
# extractive summarizer
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
summarized_text = model(inp_text, num_sentences=5)
|
| 47 |
|
| 48 |
elif summarize_type == "Abstractive":
|
| 49 |
-
summarized_text = abstractive_summarizer(inp_text)
|
| 50 |
|
| 51 |
# final summarized output
|
| 52 |
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, model):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
preprocess_text = text.strip().replace("\n", "")
|
| 9 |
t5_prepared_text = "summarize: " + preprocess_text
|
|
|
|
| 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 |
+
# ---------------------------------
|
| 38 |
st.title("Text Summarizer π")
|
| 39 |
summarize_type = st.sidebar.selectbox("Summarization type", options=["Extractive", "Abstractive"])
|
| 40 |
|
|
|
|
| 50 |
if summarize:
|
| 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")
|