Spaces:
Sleeping
Sleeping
Akhil Koduri
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -3,12 +3,13 @@ from transformers import pipeline
|
|
3 |
import fitz # PyMuPDF for handling PDFs
|
4 |
from docx import Document
|
5 |
import pypandoc
|
|
|
6 |
|
7 |
# Initialize the summarization pipeline
|
8 |
pipe = pipeline("summarization", model="facebook/bart-large-cnn")
|
9 |
|
10 |
# Title of the app
|
11 |
-
st.title("Text
|
12 |
|
13 |
# Input text box
|
14 |
input_text = st.text_area("Enter the text you want to summarize", height=200)
|
@@ -54,11 +55,15 @@ def chunk_text(text, max_len=1024):
|
|
54 |
|
55 |
return chunks
|
56 |
|
|
|
|
|
|
|
57 |
# Summarize button
|
58 |
if st.button("Summarize"):
|
59 |
if input_text:
|
60 |
chunks = chunk_text(input_text)
|
61 |
-
|
|
|
62 |
st.subheader("Summary")
|
63 |
st.write(' '.join(summaries))
|
64 |
elif uploaded_file is not None:
|
@@ -72,7 +77,8 @@ if st.button("Summarize"):
|
|
72 |
file_text = extract_text_from_docx(uploaded_file)
|
73 |
|
74 |
chunks = chunk_text(file_text)
|
75 |
-
|
|
|
76 |
st.subheader("Summary")
|
77 |
st.write(' '.join(summaries))
|
78 |
else:
|
|
|
3 |
import fitz # PyMuPDF for handling PDFs
|
4 |
from docx import Document
|
5 |
import pypandoc
|
6 |
+
from concurrent.futures import ThreadPoolExecutor
|
7 |
|
8 |
# Initialize the summarization pipeline
|
9 |
pipe = pipeline("summarization", model="facebook/bart-large-cnn")
|
10 |
|
11 |
# Title of the app
|
12 |
+
st.title("Text Summarizer")
|
13 |
|
14 |
# Input text box
|
15 |
input_text = st.text_area("Enter the text you want to summarize", height=200)
|
|
|
55 |
|
56 |
return chunks
|
57 |
|
58 |
+
def summarize_chunk(chunk):
|
59 |
+
return pipe(chunk)[0]['summary_text']
|
60 |
+
|
61 |
# Summarize button
|
62 |
if st.button("Summarize"):
|
63 |
if input_text:
|
64 |
chunks = chunk_text(input_text)
|
65 |
+
with ThreadPoolExecutor() as executor:
|
66 |
+
summaries = list(executor.map(summarize_chunk, chunks))
|
67 |
st.subheader("Summary")
|
68 |
st.write(' '.join(summaries))
|
69 |
elif uploaded_file is not None:
|
|
|
77 |
file_text = extract_text_from_docx(uploaded_file)
|
78 |
|
79 |
chunks = chunk_text(file_text)
|
80 |
+
with ThreadPoolExecutor() as executor:
|
81 |
+
summaries = list(executor.map(summarize_chunk, chunks))
|
82 |
st.subheader("Summary")
|
83 |
st.write(' '.join(summaries))
|
84 |
else:
|