EmreYY20 commited on
Commit
0f4d5d5
·
1 Parent(s): 7fbb920

del overlap func

Browse files
Files changed (1) hide show
  1. app.py +6 -28
app.py CHANGED
@@ -1,8 +1,6 @@
1
  import streamlit as st
2
  import PyPDF2
3
- from extractive_model import summarize_with_textrank
4
- from nltk.tokenize import sent_tokenize
5
-
6
 
7
  # Set page to wide mode
8
  st.set_page_config(layout="wide")
@@ -15,14 +13,6 @@ def load_pdf(file):
15
  pdf_text += pdf_reader.pages[page_num].extract_text() or ""
16
  return pdf_text
17
 
18
- # Function to calculate overlap
19
- def calculate_overlap(original_text, summary_text):
20
- original_sentences = set(sent_tokenize(original_text))
21
- summary_sentences = set(sent_tokenize(summary_text))
22
- overlap_count = sum(1 for sentence in summary_sentences if sentence in original_sentences)
23
- overlap_percentage = (overlap_count / len(original_sentences)) * 100 if original_sentences else 0
24
- return overlap_percentage
25
-
26
  # Main app
27
  def main():
28
  st.title("Terms of Service Summarizer")
@@ -43,12 +33,6 @@ def main():
43
  if uploaded_file and user_input:
44
  st.warning("Please provide either text input or a PDF file, not both.")
45
  return
46
-
47
- # Perform overlap calculation
48
- if 'summary' in st.session_state:
49
- overlap = calculate_overlap(file_content, st.session_state.summary)
50
- st.session_state.overlap = overlap
51
-
52
  elif uploaded_file:
53
  # Extract text from PDF
54
  file_content = load_pdf(uploaded_file)
@@ -60,27 +44,21 @@ def main():
60
  return
61
 
62
  # Perform extractive summarization
63
- summary = ""
64
  if radio_selection == "Extractive":
65
- # Perform extractive summarization
66
  summary = summarize_with_textrank(file_content)
67
  st.session_state.summary = summary
68
- # Calculate and reset overlap
69
- st.session_state.overlap = calculate_overlap(file_content, summary)
70
 
71
  # Perform extractive summarization
72
  if radio_selection == "Abstractive":
73
  None
74
-
 
75
 
76
  # Right column: Displaying text after pressing 'Summarize'
77
  with col3:
78
- st.write("Summary:")
79
- if st.session_state.get('summary'):
80
- st.write(st.session_state.summary)
81
- if radio_selection == "Extractive" and st.session_state.get('overlap') is not None:
82
- st.write(f"Overlap with Original Text: {st.session_state.overlap:.2f}%")
83
-
84
 
85
  if __name__ == "__main__":
86
  main()
 
1
  import streamlit as st
2
  import PyPDF2
3
+ from extractive_model import summarize_with_textrank # Renamed function
 
 
4
 
5
  # Set page to wide mode
6
  st.set_page_config(layout="wide")
 
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")
 
33
  if uploaded_file and user_input:
34
  st.warning("Please provide either text input or a PDF file, not both.")
35
  return
 
 
 
 
 
 
36
  elif uploaded_file:
37
  # Extract text from PDF
38
  file_content = load_pdf(uploaded_file)
 
44
  return
45
 
46
  # Perform extractive summarization
 
47
  if radio_selection == "Extractive":
 
48
  summary = summarize_with_textrank(file_content)
49
  st.session_state.summary = summary
 
 
50
 
51
  # Perform extractive summarization
52
  if radio_selection == "Abstractive":
53
  None
54
+ #summary = summarize_with_textrank(file_content)
55
+ #st.session_state.summary = summary
56
 
57
  # Right column: Displaying text after pressing 'Summarize'
58
  with col3:
59
+ st.write("Summary:")
60
+ if 'summary' in st.session_state:
61
+ st.write(st.session_state.summary)
 
 
 
62
 
63
  if __name__ == "__main__":
64
  main()