Spaces:
Runtime error
Runtime error
Update app.py #0
Browse files
app.py
CHANGED
@@ -1,28 +1,32 @@
|
|
1 |
-
import streamlit as
|
|
|
2 |
from PyPDF2 import PdfReader
|
3 |
|
4 |
from transformers import pipeline
|
5 |
|
6 |
summarizer = pipeline(task="summarization")
|
7 |
|
8 |
-
|
|
|
9 |
page_title='Text Summarizer'
|
10 |
)
|
11 |
|
12 |
-
|
|
|
|
|
13 |
|
14 |
def summarize_text(text):
|
15 |
summary = summarizer(text)
|
16 |
summary = summary[0]['summary_text']
|
17 |
return summary
|
18 |
|
19 |
-
input =
|
20 |
|
21 |
output = summarize_text(input)
|
22 |
|
23 |
|
24 |
-
if
|
25 |
-
|
26 |
<div style="background-color: black; color: white; font-weight: bold; padding: 1rem; border-radius: 10px;">
|
27 |
<h4>Results</h4>
|
28 |
<p>
|
@@ -30,46 +34,63 @@ if str.button('Summarize text'):
|
|
30 |
</p>
|
31 |
</div>
|
32 |
''', unsafe_allow_html=True)
|
33 |
-
|
34 |
|
35 |
|
36 |
#####
|
37 |
|
38 |
# PDF summary section
|
39 |
-
|
|
|
40 |
|
41 |
try:
|
42 |
-
|
|
|
43 |
|
44 |
if uploaded_pdf is not None:
|
45 |
-
|
46 |
|
|
|
47 |
def extract_text(pdf_file):
|
48 |
pdf_content = PdfReader(pdf_file)
|
49 |
-
pages =
|
50 |
# page_count = len(pages)
|
51 |
-
|
52 |
-
|
53 |
-
return page_text
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
-
|
|
|
|
|
57 |
|
58 |
-
pdf_output = summarize_text(pdf_input)
|
59 |
|
60 |
-
except:
|
61 |
-
|
62 |
|
|
|
|
|
|
|
|
|
63 |
|
64 |
|
65 |
|
66 |
-
if
|
67 |
-
|
68 |
<div style="background-color: black; color: white; font-weight: bold; padding: 1rem; border-radius: 10px;">
|
69 |
-
<h4>
|
70 |
<p>
|
71 |
{pdf_output}
|
72 |
</p>
|
73 |
</div>
|
74 |
''', unsafe_allow_html=True)
|
75 |
-
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pdfkit
|
3 |
from PyPDF2 import PdfReader
|
4 |
|
5 |
from transformers import pipeline
|
6 |
|
7 |
summarizer = pipeline(task="summarization")
|
8 |
|
9 |
+
# Basic text summary
|
10 |
+
st.set_page_config(
|
11 |
page_title='Text Summarizer'
|
12 |
)
|
13 |
|
14 |
+
st.title('Text Summarization')
|
15 |
+
|
16 |
+
# Text summary function
|
17 |
|
18 |
def summarize_text(text):
|
19 |
summary = summarizer(text)
|
20 |
summary = summary[0]['summary_text']
|
21 |
return summary
|
22 |
|
23 |
+
input = st.text_area('Enter long text')
|
24 |
|
25 |
output = summarize_text(input)
|
26 |
|
27 |
|
28 |
+
if st.button('Summarize text'):
|
29 |
+
st.markdown(f'''
|
30 |
<div style="background-color: black; color: white; font-weight: bold; padding: 1rem; border-radius: 10px;">
|
31 |
<h4>Results</h4>
|
32 |
<p>
|
|
|
34 |
</p>
|
35 |
</div>
|
36 |
''', unsafe_allow_html=True)
|
37 |
+
st.success('Done')
|
38 |
|
39 |
|
40 |
#####
|
41 |
|
42 |
# PDF summary section
|
43 |
+
|
44 |
+
st.subheader('PDF summary')
|
45 |
|
46 |
try:
|
47 |
+
# Upload file
|
48 |
+
uploaded_pdf = st.file_uploader('Choose a pdf file', type=['pdf'])
|
49 |
|
50 |
if uploaded_pdf is not None:
|
51 |
+
st.success('Succesfully uploaded')
|
52 |
|
53 |
+
# Extract PDF content
|
54 |
def extract_text(pdf_file):
|
55 |
pdf_content = PdfReader(pdf_file)
|
56 |
+
pages =pdf_content.pages
|
57 |
# page_count = len(pages)
|
58 |
+
|
59 |
+
page_text_stack = []
|
|
|
60 |
|
61 |
+
for page in pages:
|
62 |
+
page_text = page.extract_text()
|
63 |
+
page_text_stack.append(page_text)
|
64 |
+
|
65 |
+
pages_stack = []
|
66 |
+
|
67 |
+
for text_stack in page_text_stack:
|
68 |
+
pages_stack.append(text_stack)
|
69 |
|
70 |
+
return page_text
|
71 |
+
|
72 |
+
|
73 |
|
|
|
74 |
|
75 |
+
except: # Handle blank file error
|
76 |
+
st.error('Please select a valid file')
|
77 |
|
78 |
+
# Prepare output
|
79 |
+
pdf_input = extract_text(uploaded_pdf)
|
80 |
+
pdf_output = summarize_text(pdf_input)
|
81 |
+
summary_pdf = pdfkit.from_sting(pdf_input, 'Summary.pdf')
|
82 |
|
83 |
|
84 |
|
85 |
+
if st.button('Summarize pdf page'):
|
86 |
+
st.markdown(f'''
|
87 |
<div style="background-color: black; color: white; font-weight: bold; padding: 1rem; border-radius: 10px;">
|
88 |
+
<h4>Download the summary here </h4>
|
89 |
<p>
|
90 |
{pdf_output}
|
91 |
</p>
|
92 |
</div>
|
93 |
''', unsafe_allow_html=True)
|
94 |
+
st.write('Download summary pdf here')
|
95 |
+
download_button = st.download_button(summary_pdf, label='Download summary')
|
96 |
+
st.success('PDF page summarized :)', icon="✅")
|