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