File size: 2,274 Bytes
c0ae847
03ddbfd
e081c2e
ccd2173
cce90fc
46193fd
20d6d68
 
 
 
 
 
 
 
03ddbfd
20d6d68
 
 
 
 
 
 
 
 
03ddbfd
20d6d68
5ea550e
 
 
20d6d68
 
b87bcef
20d6d68
 
2a61e91
 
 
 
03ddbfd
20d6d68
 
b87bcef
 
20d6d68
2a61e91
b87bcef
 
 
 
f497f7f
2a61e91
20d6d68
97f7d3e
 
ccd2173
 
97f7d3e
20d6d68
 
0f4d5d5
cce90fc
 
97f7d3e
20d6d68
b87bcef
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import streamlit as st
import PyPDF2
from extractive_model import summarize_with_textrank
from abstractive_model import summarize_with_bart
#from blanc import BlancHelp

# 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_area("Enter your text here:")
        uploaded_file = st.file_uploader("Upload a PDF", type="pdf")
        if st.button("Summarize"):
            if uploaded_file and user_input:
                st.warning("Please provide either text input or a PDF file, not both.")
                return
            elif uploaded_file:
                # Extract text from PDF
                file_content = load_pdf(uploaded_file)
                st.write("PDF uploaded successfully.")
            elif user_input:
                file_content = user_input
            else:
                st.warning("Please upload a PDF or enter some text to summarize.")
                return

            # Perform extractive summarization
            if radio_selection == "Extractive":
                summary = summarize_with_textrank(file_content)
                st.session_state.summary = summary

            # Perform extractive summarization
            if radio_selection == "Abstractive":
                summary = summarize_with_bart(file_content)
                st.session_state.summary = summary

    # Right column: Displaying text after pressing 'Summarize'
    with col3:
        st.write("Summary:")
        if 'summary' in st.session_state:
            st.write(st.session_state.summary)

if __name__ == "__main__":
    main()