File size: 936 Bytes
a674005
0e6c3f4
 
a674005
 
 
 
0e6c3f4
 
 
 
a674005
 
a7a9d9e
a674005
 
 
 
 
0e6c3f4
 
 
 
 
 
 
 
 
a674005
 
 
 
 
 
 
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
import streamlit as st
from streamlit import session_state as ss
from streamlit_pdf_viewer import pdf_viewer
from summarize import Summarizer
import pdfplumber

def createDemoPage(path):
    # For displaying pdf
    if 'pdf_ref' not in ss:
        ss.pdf_ref = None

    with st.spinner("Summarizing text..."):
        summarizer = Summarizer(model = "groq")
        text = readpdf(path)
        summary = summarizer.summarize(text)

    st.subheader("Summary")
    st.write(summary)
    
    #st.subheader("Extracted Text")
    with st.expander("Extracted Text", expanded = False):
        st.write(text)
    
    st.subheader("Original pdf")
    with open(path, 'rb') as pdf_ref:
        bytes_data = pdf_ref.read()
    pdf_viewer(input=bytes_data, width=700)    


def readpdf(path):
    text = ""
    with pdfplumber.open(path) as pdf_file:
        for page in pdf_file.pages:
            text += page.extract_text()
    return text