Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,14 @@ import os
|
|
11 |
os.environ["KERAS_BACKEND"] = "tensorflow"
|
12 |
|
13 |
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
st.title("SummarizeIt")
|
17 |
|
@@ -19,7 +26,7 @@ st.title("SummarizeIt")
|
|
19 |
uploaded_file = st.file_uploader("Choose a file", type=["pdf", "txt", "docx"])
|
20 |
|
21 |
# Text extraction
|
22 |
-
text =
|
23 |
if uploaded_file is not None:
|
24 |
if uploaded_file.type == "application/pdf":
|
25 |
pdf_reader = PyPDF2.PdfReader(uploaded_file)
|
@@ -32,20 +39,13 @@ if uploaded_file is not None:
|
|
32 |
# Text input for direct text entry
|
33 |
user_input = st.text_area("Or paste your text here:")
|
34 |
if user_input:
|
35 |
-
text
|
36 |
else:
|
37 |
-
text
|
38 |
|
39 |
def generate_text(model, input_texts, max_length=500, print_time_taken=False):
|
40 |
-
|
41 |
-
|
42 |
-
#initialize an empty list to store summaries
|
43 |
-
summaries = []
|
44 |
-
# generate summaries for each chunk
|
45 |
-
for chunk in chunks:
|
46 |
-
# Assuming your model's generate method can handle a batch of inputs
|
47 |
-
summary = model.generate(input_texts, max_length=max_length)
|
48 |
-
summaries.append(summary)
|
49 |
return summary
|
50 |
|
51 |
generated_summaries = generate_text(
|
|
|
11 |
os.environ["KERAS_BACKEND"] = "tensorflow"
|
12 |
|
13 |
|
14 |
+
preprocessor = keras_nlp.models.BartSeq2SeqLMPreprocessor.from_preset(
|
15 |
+
"hf://Grey01/bart_billsum",
|
16 |
+
encoder_sequence_length=512,
|
17 |
+
decoder_sequence_length=128,
|
18 |
+
)
|
19 |
+
|
20 |
+
bart_billsum = keras_nlp.models.BartSeq2SeqLM.from_preset("hf://Grey01/bart_billsum", preprocessor=preprocessor)
|
21 |
+
|
22 |
|
23 |
st.title("SummarizeIt")
|
24 |
|
|
|
26 |
uploaded_file = st.file_uploader("Choose a file", type=["pdf", "txt", "docx"])
|
27 |
|
28 |
# Text extraction
|
29 |
+
text = ''
|
30 |
if uploaded_file is not None:
|
31 |
if uploaded_file.type == "application/pdf":
|
32 |
pdf_reader = PyPDF2.PdfReader(uploaded_file)
|
|
|
39 |
# Text input for direct text entry
|
40 |
user_input = st.text_area("Or paste your text here:")
|
41 |
if user_input:
|
42 |
+
text = user_input
|
43 |
else:
|
44 |
+
text = text
|
45 |
|
46 |
def generate_text(model, input_texts, max_length=500, print_time_taken=False):
|
47 |
+
summary = model.generate(input_texts, max_length=max_length)
|
48 |
+
summaries.append(summary)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
return summary
|
50 |
|
51 |
generated_summaries = generate_text(
|