-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapp.py
73 lines (56 loc) · 2.24 KB
/
app.py
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
67
68
69
70
71
72
73
"""
Smart PDF Highlighter
This script provides a Streamlit web application for automatically identifying and
highlighting important content within PDF files. It utilizes AI techniques such as
deep learning, clustering, and advanced algorithms such as PageRank to analyze text
and intelligently select key sentences for highlighting.
Author: Farzad Salajegheh
Date: 2024
"""
import logging
import time
import streamlit as st
from src import generate_highlighted_pdf
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def main():
"""Main function to run the PDF Highlighter tool."""
st.set_page_config(page_title="Smart PDF Highlighter", page_icon="./photos/icon.png")
st.title("Smart PDF Highlighter")
show_description()
uploaded_file = st.file_uploader("Upload a PDF file", type=["pdf"])
if uploaded_file is not None:
st.write("PDF file successfully uploaded.")
process_pdf(uploaded_file)
def show_description():
"""Display description of functionality and maximum limits."""
st.write("""Welcome to Smart PDF Highlighter! This tool automatically identifies
and highlights important content within your PDF files. It utilizes many
AI techniques such as deep learning and other advanced algorithms to
analyze the text and intelligently select key sentences for highlighting.""")
st.write("Maximum Limits: 40 pages, 2000 sentences.")
def process_pdf(uploaded_file):
"""Process the uploaded PDF file and generate highlighted PDF."""
st.write("Generating highlighted PDF...")
start_time = time.time()
with st.spinner("Processing..."):
result = generate_highlighted_pdf(uploaded_file)
if isinstance(result, str):
st.error(result)
logger.error("Error generating highlighted PDF: %s", result)
return
else:
file = result
end_time = time.time()
execution_time = end_time - start_time
st.success(
f"Highlighted PDF generated successfully in {execution_time:.2f} seconds."
)
st.write("Download the highlighted PDF:")
st.download_button(
label="Download",
data=file,
file_name="highlighted_pdf.pdf",
)
if __name__ == "__main__":
main()