Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as str
|
2 |
+
from PyPDF2 import PdfReader
|
3 |
+
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
summarizer = pipeline(task="summarization")
|
7 |
+
|
8 |
+
str.set_page_config(
|
9 |
+
page_title='Text Summarizer'
|
10 |
+
)
|
11 |
+
|
12 |
+
str.title('Text Summarization')
|
13 |
+
|
14 |
+
def summarize_text(text):
|
15 |
+
summary = summarizer(text)
|
16 |
+
summary = summary[0]['summary_text']
|
17 |
+
return summary
|
18 |
+
|
19 |
+
input = str.text_area('Enter long text')
|
20 |
+
|
21 |
+
output = summarize_text(input)
|
22 |
+
|
23 |
+
|
24 |
+
if str.button('Summarize text'):
|
25 |
+
str.markdown(f'''
|
26 |
+
<div style="background-color: black; color: white; font-weight: bold; padding: 1rem; border-radius: 10px;">
|
27 |
+
<h4>Results</h4>
|
28 |
+
<p>
|
29 |
+
{output}
|
30 |
+
</p>
|
31 |
+
</div>
|
32 |
+
''', unsafe_allow_html=True)
|
33 |
+
str.success('Done')
|
34 |
+
|
35 |
+
|
36 |
+
#####
|
37 |
+
|
38 |
+
# PDF summary section
|
39 |
+
str.subheader('PDF summary')
|
40 |
+
|
41 |
+
try:
|
42 |
+
uploaded_pdf = str.file_uploader('Choose a pdf file', type=['pdf'])
|
43 |
+
|
44 |
+
if uploaded_pdf is not None:
|
45 |
+
str.success('Succesfully uploaded')
|
46 |
+
|
47 |
+
def extract_text(pdf_file):
|
48 |
+
pdf_content = PdfReader(pdf_file)
|
49 |
+
pages = pdf_content.pages
|
50 |
+
# page_count = len(pages)
|
51 |
+
page_text = pages[17].extract_text()
|
52 |
+
|
53 |
+
return page_text
|
54 |
+
|
55 |
+
|
56 |
+
pdf_input = extract_text(uploaded_pdf)
|
57 |
+
|
58 |
+
pdf_output = summarize_text(pdf_input)
|
59 |
+
|
60 |
+
except:
|
61 |
+
str.error('Please select a valid file')
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
if str.button('Summarize pdf page'):
|
67 |
+
str.markdown(f'''
|
68 |
+
<div style="background-color: black; color: white; font-weight: bold; padding: 1rem; border-radius: 10px;">
|
69 |
+
<h4>Results</h4>
|
70 |
+
<p>
|
71 |
+
{pdf_output}
|
72 |
+
</p>
|
73 |
+
</div>
|
74 |
+
''', unsafe_allow_html=True)
|
75 |
+
str.success('PDF page summarized :)', icon="✅")
|