Spaces:
Runtime error
Runtime error
File size: 1,373 Bytes
3480ee3 f575c3b 5a02f0c 6e7f3ff f575c3b 2f41a67 4cc1f8a f575c3b 5b24454 4cc1f8a f575c3b 4cc1f8a 2c173e4 05ad86c 2f41a67 16006a4 |
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 |
import os
import PyPDF2
from PIL import Image
import streamlit as st
from transformers import T5ForConditionalGeneration,T5TokenizerFast
model = T5ForConditionalGeneration.from_pretrained("t5-base")
tokenizer = T5TokenizerFast.from_pretrained("t5-base")
def read_pdf(pdf):
reader=PyPDF2.PdfReader(pdf)
text=''
for page in reader.pages:
text+=page.extract_text()
# text_file_name = 'text.txt'
# text_file_path = '/content/text.txt'
# with open(text_file_path, 'w') as text_file:
# text_file.write(text)
return text
def summarizer(text):
inputs = tokenizer.encode("summarize: " + text,return_tensors="pt", max_length=1000,truncation=True)
outputs = model.generate(inputs,max_length=1000, min_length=100,length_penalty=2.0, num_beams=4,early_stopping=True)
summary = tokenizer.decode(outputs[0])
return summary
st.title(':blue[Abstractive Summarizer]')
st.header('by: _Team_ _Rare_ _species_')
uploaded_file = st.file_uploader('Choose your .pdf file', type="pdf")
if uploaded_file is not None:
if st.button('Summarize Document'):
with st.spinner("📚 Please wait while we produce a summary..."):
text=read_pdf(uploaded_file)
summary=summarizer(text)
st.divider()
st.markdown(summary, unsafe_allow_html=True)
st.divider() |