EmreYY20
update
03ddbfd
raw
history blame
1.84 kB
import streamlit as st
import PyPDF2
from extractive_model import summarize_pdf_with_textrank
# Set page to wide mode
st.set_page_config(layout="wide")
# Function to handle file upload and return its content
def load_pdf(file):
pdf_reader = PyPDF2.PdfReader(file)
pdf_text = ""
for page_num in range(len(pdf_reader.pages)):
pdf_text += pdf_reader.pages[page_num].extract_text() or ""
return pdf_text
# Main app
def main():
st.title("Terms of Service Summarizer")
# Layout: 3 columns
col1, col2, col3 = st.columns([1, 3, 2], gap="large")
# Left column: Radio buttons for summarizer choice
with col1:
radio_options = ['Abstractive', 'Extractive']
radio_selection = st.radio("Choose type of summarizer:", radio_options)
# Middle column: Text input and File uploader
with col2:
user_input = st.text_input("Enter your text here:")
uploaded_file = st.file_uploader("Upload a PDF", type="pdf")
if st.button("Summarize"):
summary = ""
if uploaded_file is not None:
# Extract text from PDF
file_content = load_pdf(uploaded_file)
st.write("PDF uploaded successfully.")
if radio_selection == "Extractive":
# Perform extractive summarization
summary = summarize_pdf_with_textrank(file_content)
else:
None
else:
st.write("Please upload a PDF or enter some text to summarize.")
st.session_state.summary = summary
# Right column: Displaying text after pressing 'Summarize'
with col3:
st.write("Output:")
if 'summary' in st.session_state:
st.write(st.session_state.summary)
if __name__ == "__main__":
main()