Spaces:
Runtime error
Runtime error
EmreYY20
commited on
Commit
•
20d6d68
1
Parent(s):
a0ac68c
change web app
Browse files
app.py
CHANGED
@@ -1,18 +1,53 @@
|
|
1 |
import streamlit as st
|
2 |
from extractive_model import summarize_pdf_with_textrank
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|