File size: 970 Bytes
d98a0b7
 
 
96a9191
c47a0f1
 
 
 
1aaddca
c47a0f1
 
 
d98a0b7
 
 
 
 
 
5a1c6ff
d98a0b7
 
96a9191
 
c47a0f1
 
 
96a9191
c47a0f1
76d4c9c
 
 
 
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
import streamlit as st
from transformers import pipeline
from pathlib import Path
#from llama_index import download_loader
from PyPDF2 import PdfReader

def get_pdf_text(pdf_docs):
    text = ""
    pdf_reader = PdfReader(pdf_docs)
    for page in pdf_reader.pages:
        text += page.extract_text()
    return text

def main():
  st.title("PDF Summarizer")
  uploaded_file = st.file_uploader("Upload your PDF file", type="pdf")
  if uploaded_file is not None:
    #Loading mode
    print(uploaded_file)
    summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
    # data Loader for reading PDF
    # PDFReader = download_loader("PDFReader")
    # loader = PDFReader()
    #documents = loader.load_data(file=Path(uploaded_file))
    #print(type(documents))
    text  = get_pdf_text(uploaded_file)
    print(text)
    summary = summarizer(text, max_length=50, min_length=30, do_sample=False)
    st.write(summary)

if __name__ == "__main__":
  main()