EmreYY20 commited on
Commit
03ddbfd
1 Parent(s): 5ea550e
Files changed (2) hide show
  1. app.py +12 -14
  2. extractive_model.py +0 -1
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import streamlit as st
 
2
  from extractive_model import summarize_pdf_with_textrank
3
 
4
  # Set page to wide mode
@@ -9,42 +10,39 @@ 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
- # Options for the radio buttons
26
  radio_options = ['Abstractive', 'Extractive']
27
-
28
- # Create radio buttons and get the selected option
29
  radio_selection = st.radio("Choose type of summarizer:", radio_options)
30
 
31
-
32
  # Middle column: Text input and File uploader
33
  with col2:
34
  user_input = st.text_input("Enter your text here:")
35
  uploaded_file = st.file_uploader("Upload a PDF", type="pdf")
36
  if st.button("Summarize"):
37
- # Handling file upload
38
  if uploaded_file is not None:
 
39
  file_content = load_pdf(uploaded_file)
40
  st.write("PDF uploaded successfully.")
41
- # summary = summarizer(file_content)
42
- summary = file_content
43
- elif user_input is not None:
44
- # summary = summarizer(user_input)
45
- summary = user_input
46
  else:
47
- st.wirte("Upload a PDF or put in your text!")
 
48
  st.session_state.summary = summary
49
 
50
  # Right column: Displaying text after pressing 'Summarize'
 
1
  import streamlit as st
2
+ import PyPDF2
3
  from extractive_model import summarize_pdf_with_textrank
4
 
5
  # Set page to wide mode
 
10
  pdf_reader = PyPDF2.PdfReader(file)
11
  pdf_text = ""
12
  for page_num in range(len(pdf_reader.pages)):
13
+ pdf_text += pdf_reader.pages[page_num].extract_text() or ""
14
  return pdf_text
15
 
16
  # Main app
17
  def main():
 
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: Radio buttons for summarizer choice
24
  with col1:
 
25
  radio_options = ['Abstractive', 'Extractive']
 
 
26
  radio_selection = st.radio("Choose type of summarizer:", radio_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
+ summary = ""
34
  if uploaded_file is not None:
35
+ # Extract text from PDF
36
  file_content = load_pdf(uploaded_file)
37
  st.write("PDF uploaded successfully.")
38
+ if radio_selection == "Extractive":
39
+ # Perform extractive summarization
40
+ summary = summarize_pdf_with_textrank(file_content)
41
+ else:
42
+ None
43
  else:
44
+ st.write("Please upload a PDF or enter some text to summarize.")
45
+
46
  st.session_state.summary = summary
47
 
48
  # Right column: Displaying text after pressing 'Summarize'
extractive_model.py CHANGED
@@ -9,7 +9,6 @@ from pysummarization.abstractabledoc.top_n_rank_abstractor import TopNRankAbstra
9
  from sumy.nlp.stemmers import Stemmer
10
  from sumy.utils import get_stop_words"""
11
 
12
- import PyPDF2
13
  from sumy.parsers.plaintext import PlaintextParser
14
  from sumy.nlp.tokenizers import Tokenizer
15
  from sumy.summarizers.text_rank import TextRankSummarizer
 
9
  from sumy.nlp.stemmers import Stemmer
10
  from sumy.utils import get_stop_words"""
11
 
 
12
  from sumy.parsers.plaintext import PlaintextParser
13
  from sumy.nlp.tokenizers import Tokenizer
14
  from sumy.summarizers.text_rank import TextRankSummarizer