Spaces:
Running
Running
Restructure the py files.
Browse filesAdding: section_handlers.py and sidebar.py
- __pycache__/pages.cpython-312.pyc +0 -0
- __pycache__/section_handlers.cpython-312.pyc +0 -0
- __pycache__/sidebar.cpython-312.pyc +0 -0
- app.py +2 -1
- pages.py +2 -119
- section_handlers.py +90 -0
- sidebar.py +32 -0
__pycache__/pages.cpython-312.pyc
CHANGED
Binary files a/__pycache__/pages.cpython-312.pyc and b/__pycache__/pages.cpython-312.pyc differ
|
|
__pycache__/section_handlers.cpython-312.pyc
ADDED
Binary file (5.75 kB). View file
|
|
__pycache__/sidebar.cpython-312.pyc
ADDED
Binary file (1.55 kB). View file
|
|
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
-
from
|
|
|
3 |
|
4 |
uploader_sidebar()
|
5 |
|
|
|
1 |
import streamlit as st
|
2 |
+
from sidebar import uploader_sidebar
|
3 |
+
from pages import home, cover, underwriter, income_statement, balance_sheet, cash_flow
|
4 |
|
5 |
uploader_sidebar()
|
6 |
|
pages.py
CHANGED
@@ -1,124 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
-
from
|
3 |
-
from
|
4 |
|
5 |
-
def uploader_sidebar():
|
6 |
-
uploaded_file = st.sidebar.file_uploader("Upload your Prospectus File", accept_multiple_files=False, type=["pdf"])
|
7 |
-
st.sidebar.caption("Made with ❤️ by @michael_sr24")
|
8 |
-
|
9 |
-
if uploaded_file:
|
10 |
-
# Initialize session state for processing flags and paths
|
11 |
-
if "uploaded_file" not in st.session_state:
|
12 |
-
st.session_state["uploaded_file"] = uploaded_file
|
13 |
-
st.session_state["processing"] = {
|
14 |
-
"cover_path": False,
|
15 |
-
"underwriter_path": False,
|
16 |
-
"income_statement_path": False,
|
17 |
-
"balance_sheet_path": False,
|
18 |
-
"cash_flow_path": False,
|
19 |
-
}
|
20 |
-
st.session_state["all_processed"] = False
|
21 |
-
st.session_state["current_page"] = None
|
22 |
-
st.session_state["processing_lock"] = False
|
23 |
-
else:
|
24 |
-
st.session_state["uploaded_file"] = uploaded_file
|
25 |
-
process_sections()
|
26 |
-
else:
|
27 |
-
# Clear all session state when no file is uploaded
|
28 |
-
keys_to_clear = ["uploaded_file", "processing", "all_processed",
|
29 |
-
"cover_path", "underwriter_path", "income_statement_path",
|
30 |
-
"balance_sheet_path", "cash_flow_path", "current_page", "processing_lock"]
|
31 |
-
for key in keys_to_clear:
|
32 |
-
if key in st.session_state:
|
33 |
-
del st.session_state[key]
|
34 |
-
|
35 |
-
def process_sections():
|
36 |
-
if "processing" not in st.session_state or st.session_state.get("all_processed", False):
|
37 |
-
return
|
38 |
-
|
39 |
-
# Only process the current page if it's set and not processed
|
40 |
-
current_page = st.session_state.get("current_page")
|
41 |
-
current_page_needs_processing = False
|
42 |
-
|
43 |
-
if current_page and not st.session_state.get(current_page, None):
|
44 |
-
if not st.session_state["processing"].get(current_page, False):
|
45 |
-
current_page_needs_processing = True
|
46 |
-
key = current_page
|
47 |
-
if key == "cover_path":
|
48 |
-
st.session_state[key] = find_cover(st.session_state["uploaded_file"])
|
49 |
-
elif key == "underwriter_path":
|
50 |
-
st.session_state[key] = find_underwriter(st.session_state["uploaded_file"])
|
51 |
-
elif key == "income_statement_path":
|
52 |
-
st.session_state[key] = find_financial(st.session_state["uploaded_file"], "income_statement")
|
53 |
-
elif key == "balance_sheet_path":
|
54 |
-
st.session_state[key] = find_financial(st.session_state["uploaded_file"], "balance_sheet")
|
55 |
-
elif key == "cash_flow_path":
|
56 |
-
st.session_state[key] = find_financial(st.session_state["uploaded_file"], "cash_flow")
|
57 |
-
st.session_state["processing"][key] = True
|
58 |
-
st.rerun()
|
59 |
-
|
60 |
-
# Process remaining sections if not processing current page and not locked
|
61 |
-
if not current_page_needs_processing and not st.session_state.get("processing_lock", False):
|
62 |
-
sections_to_process = [
|
63 |
-
("cover_path", lambda: find_cover(st.session_state["uploaded_file"])),
|
64 |
-
("underwriter_path", lambda: find_underwriter(st.session_state["uploaded_file"])),
|
65 |
-
("income_statement_path", lambda: find_financial(st.session_state["uploaded_file"], "income_statement")),
|
66 |
-
("balance_sheet_path", lambda: find_financial(st.session_state["uploaded_file"], "balance_sheet")),
|
67 |
-
("cash_flow_path", lambda: find_financial(st.session_state["uploaded_file"], "cash_flow"))
|
68 |
-
]
|
69 |
-
|
70 |
-
# Store the section being processed
|
71 |
-
if "processing_section" not in st.session_state:
|
72 |
-
st.session_state["processing_section"] = None
|
73 |
-
|
74 |
-
for key, process_func in sections_to_process:
|
75 |
-
if not st.session_state["processing"].get(key, False):
|
76 |
-
# Check if we've switched pages during processing
|
77 |
-
if (st.session_state.get("processing_section") is not None and
|
78 |
-
st.session_state["processing_section"] != current_page):
|
79 |
-
st.session_state["processing_section"] = None
|
80 |
-
return # Stop processing if we've switched pages
|
81 |
-
|
82 |
-
st.session_state["processing_section"] = key
|
83 |
-
st.session_state[key] = process_func()
|
84 |
-
st.session_state["processing"][key] = True
|
85 |
-
st.session_state["processing_section"] = None
|
86 |
-
|
87 |
-
if not st.session_state.get("all_processed", False):
|
88 |
-
st.rerun() # Trigger another run to process next section
|
89 |
-
break
|
90 |
-
|
91 |
-
# Check if all sections are processed
|
92 |
-
st.session_state["all_processed"] = all(st.session_state["processing"].values())
|
93 |
-
|
94 |
-
def show_section(section_key):
|
95 |
-
"""Display the section if available, otherwise inform the user."""
|
96 |
-
# Check if we're switching to a different page
|
97 |
-
if st.session_state.get("current_page") != section_key:
|
98 |
-
# Reset processing state when switching pages
|
99 |
-
st.session_state["processing_lock"] = True
|
100 |
-
st.session_state["processing_section"] = None
|
101 |
-
|
102 |
-
# Update current page
|
103 |
-
st.session_state["current_page"] = section_key
|
104 |
-
|
105 |
-
temp_path = st.session_state.get(section_key)
|
106 |
-
if temp_path:
|
107 |
-
# If we have the section, allow background processing of other sections
|
108 |
-
st.session_state["processing_lock"] = False
|
109 |
-
pdf_viewer(temp_path)
|
110 |
-
# Continue processing remaining sections
|
111 |
-
if not st.session_state.get("all_processed", False):
|
112 |
-
process_sections()
|
113 |
-
else:
|
114 |
-
# Lock processing and process this section first
|
115 |
-
st.session_state["processing_lock"] = True
|
116 |
-
if not st.session_state["processing"].get(section_key, False):
|
117 |
-
st.info(f"Processing {section_key.replace('_path', '').replace('_', ' ').title()}...")
|
118 |
-
process_sections()
|
119 |
-
else:
|
120 |
-
st.warning(f"Could not process {section_key.replace('_path', '').replace('_', ' ')}.")
|
121 |
-
|
122 |
def home():
|
123 |
st.title("Prospectus Lens")
|
124 |
st.write("Welcome to the Prospectus Lens! Upload the PDF of the prospectus on the left sidebar!")
|
|
|
1 |
import streamlit as st
|
2 |
+
from sidebar import uploader_sidebar
|
3 |
+
from section_handlers import show_section
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
def home():
|
6 |
st.title("Prospectus Lens")
|
7 |
st.write("Welcome to the Prospectus Lens! Upload the PDF of the prospectus on the left sidebar!")
|
section_handlers.py
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from section_extract import find_cover, find_underwriter, find_financial
|
3 |
+
from streamlit_pdf_viewer import pdf_viewer
|
4 |
+
|
5 |
+
def process_sections():
|
6 |
+
if "processing" not in st.session_state or st.session_state.get("all_processed", False):
|
7 |
+
return
|
8 |
+
|
9 |
+
# Only process the current page if it's set and not processed
|
10 |
+
current_page = st.session_state.get("current_page")
|
11 |
+
current_page_needs_processing = False
|
12 |
+
|
13 |
+
if current_page and not st.session_state.get(current_page, None):
|
14 |
+
if not st.session_state["processing"].get(current_page, False):
|
15 |
+
current_page_needs_processing = True
|
16 |
+
key = current_page
|
17 |
+
if key == "cover_path":
|
18 |
+
st.session_state[key] = find_cover(st.session_state["uploaded_file"])
|
19 |
+
elif key == "underwriter_path":
|
20 |
+
st.session_state[key] = find_underwriter(st.session_state["uploaded_file"])
|
21 |
+
elif key == "income_statement_path":
|
22 |
+
st.session_state[key] = find_financial(st.session_state["uploaded_file"], "income_statement")
|
23 |
+
elif key == "balance_sheet_path":
|
24 |
+
st.session_state[key] = find_financial(st.session_state["uploaded_file"], "balance_sheet")
|
25 |
+
elif key == "cash_flow_path":
|
26 |
+
st.session_state[key] = find_financial(st.session_state["uploaded_file"], "cash_flow")
|
27 |
+
st.session_state["processing"][key] = True
|
28 |
+
st.rerun()
|
29 |
+
|
30 |
+
# Process remaining sections if not processing current page and not locked
|
31 |
+
if not current_page_needs_processing and not st.session_state.get("processing_lock", False):
|
32 |
+
sections_to_process = [
|
33 |
+
("cover_path", lambda: find_cover(st.session_state["uploaded_file"])),
|
34 |
+
("underwriter_path", lambda: find_underwriter(st.session_state["uploaded_file"])),
|
35 |
+
("income_statement_path", lambda: find_financial(st.session_state["uploaded_file"], "income_statement")),
|
36 |
+
("balance_sheet_path", lambda: find_financial(st.session_state["uploaded_file"], "balance_sheet")),
|
37 |
+
("cash_flow_path", lambda: find_financial(st.session_state["uploaded_file"], "cash_flow"))
|
38 |
+
]
|
39 |
+
|
40 |
+
# Store the section being processed
|
41 |
+
if "processing_section" not in st.session_state:
|
42 |
+
st.session_state["processing_section"] = None
|
43 |
+
|
44 |
+
for key, process_func in sections_to_process:
|
45 |
+
if not st.session_state["processing"].get(key, False):
|
46 |
+
# Check if we've switched pages during processing
|
47 |
+
if (st.session_state.get("processing_section") is not None and
|
48 |
+
st.session_state["processing_section"] != current_page):
|
49 |
+
st.session_state["processing_section"] = None
|
50 |
+
return # Stop processing if we've switched pages
|
51 |
+
|
52 |
+
st.session_state["processing_section"] = key
|
53 |
+
st.session_state[key] = process_func()
|
54 |
+
st.session_state["processing"][key] = True
|
55 |
+
st.session_state["processing_section"] = None
|
56 |
+
|
57 |
+
if not st.session_state.get("all_processed", False):
|
58 |
+
st.rerun() # Trigger another run to process next section
|
59 |
+
break
|
60 |
+
|
61 |
+
# Check if all sections are processed
|
62 |
+
st.session_state["all_processed"] = all(st.session_state["processing"].values())
|
63 |
+
|
64 |
+
def show_section(section_key):
|
65 |
+
"""Display the section if available, otherwise inform the user."""
|
66 |
+
# Check if we're switching to a different page
|
67 |
+
if st.session_state.get("current_page") != section_key:
|
68 |
+
# Reset processing state when switching pages
|
69 |
+
st.session_state["processing_lock"] = True
|
70 |
+
st.session_state["processing_section"] = None
|
71 |
+
|
72 |
+
# Update current page
|
73 |
+
st.session_state["current_page"] = section_key
|
74 |
+
|
75 |
+
temp_path = st.session_state.get(section_key)
|
76 |
+
if temp_path:
|
77 |
+
# If we have the section, allow background processing of other sections
|
78 |
+
st.session_state["processing_lock"] = False
|
79 |
+
pdf_viewer(temp_path)
|
80 |
+
# Continue processing remaining sections
|
81 |
+
if not st.session_state.get("all_processed", False):
|
82 |
+
process_sections()
|
83 |
+
else:
|
84 |
+
# Lock processing and process this section first
|
85 |
+
st.session_state["processing_lock"] = True
|
86 |
+
if not st.session_state["processing"].get(section_key, False):
|
87 |
+
st.info(f"Processing {section_key.replace('_path', '').replace('_', ' ').title()}...")
|
88 |
+
process_sections()
|
89 |
+
else:
|
90 |
+
st.warning(f"Could not process {section_key.replace('_path', '').replace('_', ' ')}.")
|
sidebar.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from section_handlers import process_sections
|
3 |
+
|
4 |
+
def uploader_sidebar():
|
5 |
+
uploaded_file = st.sidebar.file_uploader("Upload your Prospectus File", accept_multiple_files=False, type=["pdf"])
|
6 |
+
st.sidebar.caption("Made with ❤️ by @michael_sr24")
|
7 |
+
|
8 |
+
if uploaded_file:
|
9 |
+
# Initialize session state for processing flags and paths
|
10 |
+
if "uploaded_file" not in st.session_state:
|
11 |
+
st.session_state["uploaded_file"] = uploaded_file
|
12 |
+
st.session_state["processing"] = {
|
13 |
+
"cover_path": False,
|
14 |
+
"underwriter_path": False,
|
15 |
+
"income_statement_path": False,
|
16 |
+
"balance_sheet_path": False,
|
17 |
+
"cash_flow_path": False,
|
18 |
+
}
|
19 |
+
st.session_state["all_processed"] = False
|
20 |
+
st.session_state["current_page"] = None
|
21 |
+
st.session_state["processing_lock"] = False
|
22 |
+
else:
|
23 |
+
st.session_state["uploaded_file"] = uploaded_file
|
24 |
+
process_sections()
|
25 |
+
else:
|
26 |
+
# Clear all session state when no file is uploaded
|
27 |
+
keys_to_clear = ["uploaded_file", "processing", "all_processed",
|
28 |
+
"cover_path", "underwriter_path", "income_statement_path",
|
29 |
+
"balance_sheet_path", "cash_flow_path", "current_page", "processing_lock"]
|
30 |
+
for key in keys_to_clear:
|
31 |
+
if key in st.session_state:
|
32 |
+
del st.session_state[key]
|