EmreYY20 commited on
Commit
20d6d68
1 Parent(s): a0ac68c

change web app

Browse files
Files changed (1) hide show
  1. app.py +50 -15
app.py CHANGED
@@ -1,18 +1,53 @@
1
  import streamlit as st
2
  from extractive_model import summarize_pdf_with_textrank
3
 
4
- st.title("PDF Summarization App")
5
-
6
- pdf_file = st.file_uploader("Upload a PDF file", type=["pdf"])
7
-
8
- if pdf_file is not None and st.button("Summarize"):
9
- # Save uploaded PDF to a temporary file
10
- with open("temp_pdf.pdf", "wb") as f:
11
- f.write(pdf_file.getbuffer())
12
-
13
- # Generate summary
14
- summary = summarize_pdf_with_textrank("temp_pdf.pdf")
15
-
16
- # Display summary
17
- st.write("Summary:")
18
- st.write(summary)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from extractive_model import summarize_pdf_with_textrank
3
 
4
+ # Set page to wide mode
5
+ st.set_page_config(layout="wide")
6
+
7
+ # Function to handle file upload and return its content
8
+ def load_pdf(file):
9
+ pdf_reader = PyPDF2.PdfReader(file)
10
+ pdf_text = ""
11
+ for page_num in range(len(pdf_reader.pages)):
12
+ pdf_text += pdf_reader.pages[page_num].extract_text()
13
+ return pdf_text
14
+
15
+ # Main app
16
+ def main():
17
+
18
+ st.title("Terms of Service Summarizer")
19
+
20
+ # Layout: 3 columns
21
+ col1, col2, col3 = st.columns([1, 3, 2], gap="large")
22
+
23
+ # Left column: Dropdown menu
24
+ with col1:
25
+ dropdown_options = ['Abstractive', 'Extractive']
26
+ dropdown_selection = st.selectbox("Choose type of summerizer:", dropdown_options)
27
+
28
+ # Middle column: Text input and File uploader
29
+ with col2:
30
+ user_input = st.text_input("Enter your text here:")
31
+ uploaded_file = st.file_uploader("Upload a PDF", type="pdf")
32
+ if st.button("Summarize"):
33
+ # Handling file upload
34
+ if uploaded_file is not None:
35
+ file_content = load_pdf(uploaded_file)
36
+ st.write("PDF uploaded successfully.")
37
+ # summary = summarizer(file_content)
38
+ summary = file_content
39
+ elif user_input is not None:
40
+ # summary = summarizer(user_input)
41
+ summary = user_input
42
+ else:
43
+ st.wirte("Upload a PDF or put in your text!")
44
+ st.session_state.summary = summary
45
+
46
+ # Right column: Displaying text after pressing 'Summarize'
47
+ with col3:
48
+ st.write("Output:")
49
+ if 'summary' in st.session_state:
50
+ st.write(st.session_state.summary)
51
+
52
+ if __name__ == "__main__":
53
+ main()