Summarize / page.py
IsakNordgren's picture
fler exempel och förbättrad prompt. Testar steg-för-steg-prompting
a7a9d9e
raw
history blame contribute delete
936 Bytes
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