Spaces:
Running
Running
Update pages.py
Browse filesClear all session state when no file is uploaded
- __pycache__/pages.cpython-312.pyc +0 -0
- __pycache__/section_extract.cpython-312.pyc +0 -0
- pages.py +101 -99
__pycache__/pages.cpython-312.pyc
CHANGED
Binary files a/__pycache__/pages.cpython-312.pyc and b/__pycache__/pages.cpython-312.pyc differ
|
|
__pycache__/section_extract.cpython-312.pyc
CHANGED
Binary files a/__pycache__/section_extract.cpython-312.pyc and b/__pycache__/section_extract.cpython-312.pyc differ
|
|
pages.py
CHANGED
@@ -1,100 +1,102 @@
|
|
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 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["
|
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 |
-
st.session_state[key] =
|
39 |
-
elif key == "
|
40 |
-
st.session_state[key] =
|
41 |
-
elif key == "
|
42 |
-
st.session_state[key] = find_financial(st.session_state["uploaded_file"], "
|
43 |
-
elif key == "
|
44 |
-
st.session_state[key] = find_financial(st.session_state["uploaded_file"], "
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
if
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
st.
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
|
|
100 |
st.warning("Please upload a file first!")
|
|
|
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 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 |
+
else:
|
22 |
+
st.session_state["uploaded_file"] = uploaded_file
|
23 |
+
process_sections()
|
24 |
+
else:
|
25 |
+
# Clear all session state when no file is uploaded
|
26 |
+
keys_to_clear = ["uploaded_file", "processing", "all_processed",
|
27 |
+
"cover_path", "underwriter_path", "income_statement_path",
|
28 |
+
"balance_sheet_path", "cash_flow_path"]
|
29 |
+
for key in keys_to_clear:
|
30 |
+
if key in st.session_state:
|
31 |
+
del st.session_state[key]
|
32 |
+
|
33 |
+
def process_sections():
|
34 |
+
if "processing" in st.session_state and not st.session_state.get("all_processed", False):
|
35 |
+
for key, processed in st.session_state["processing"].items():
|
36 |
+
if not processed:
|
37 |
+
if key == "cover_path":
|
38 |
+
st.session_state[key] = find_cover(st.session_state["uploaded_file"])
|
39 |
+
elif key == "underwriter_path":
|
40 |
+
st.session_state[key] = find_underwriter(st.session_state["uploaded_file"])
|
41 |
+
elif key == "income_statement_path":
|
42 |
+
st.session_state[key] = find_financial(st.session_state["uploaded_file"], "income_statement")
|
43 |
+
elif key == "balance_sheet_path":
|
44 |
+
st.session_state[key] = find_financial(st.session_state["uploaded_file"], "balance_sheet")
|
45 |
+
elif key == "cash_flow_path":
|
46 |
+
st.session_state[key] = find_financial(st.session_state["uploaded_file"], "cash_flow")
|
47 |
+
|
48 |
+
st.session_state["processing"][key] = True # Mark as processed
|
49 |
+
break
|
50 |
+
|
51 |
+
# Check if all sections are processed
|
52 |
+
st.session_state["all_processed"] = all(st.session_state["processing"].values())
|
53 |
+
|
54 |
+
def show_section(section_key):
|
55 |
+
"""Display the section if available, otherwise inform the user."""
|
56 |
+
temp_path = st.session_state.get(section_key)
|
57 |
+
if temp_path:
|
58 |
+
pdf_viewer(temp_path)
|
59 |
+
else:
|
60 |
+
if not st.session_state["processing"].get(section_key, False):
|
61 |
+
st.info(f"{section_key.replace('_', ' ').capitalize()} is still being processed.")
|
62 |
+
else:
|
63 |
+
st.warning(f"Could not process {section_key.replace('_', ' ')}.")
|
64 |
+
|
65 |
+
def home():
|
66 |
+
st.title("Prospectus Lens")
|
67 |
+
st.write("Welcome to the Prospectus Lens! Upload the PDF of the prospectus on the left sidebar!")
|
68 |
+
|
69 |
+
def cover():
|
70 |
+
st.title("Cover")
|
71 |
+
if "uploaded_file" in st.session_state:
|
72 |
+
show_section("cover_path")
|
73 |
+
else:
|
74 |
+
st.warning("Please upload a file first!")
|
75 |
+
|
76 |
+
def underwriter():
|
77 |
+
st.title("Underwriter")
|
78 |
+
if "uploaded_file" in st.session_state:
|
79 |
+
show_section("underwriter_path")
|
80 |
+
else:
|
81 |
+
st.warning("Please upload a file first!")
|
82 |
+
|
83 |
+
def income_statement():
|
84 |
+
st.title("Income Statement")
|
85 |
+
if "uploaded_file" in st.session_state:
|
86 |
+
show_section("income_statement_path")
|
87 |
+
else:
|
88 |
+
st.warning("Please upload a file first!")
|
89 |
+
|
90 |
+
def balance_sheet():
|
91 |
+
st.title("Balance Sheet")
|
92 |
+
if "uploaded_file" in st.session_state:
|
93 |
+
show_section("balance_sheet_path")
|
94 |
+
else:
|
95 |
+
st.warning("Please upload a file first!")
|
96 |
+
|
97 |
+
def cash_flow():
|
98 |
+
st.title("Cash Flow")
|
99 |
+
if "uploaded_file" in st.session_state:
|
100 |
+
show_section("cash_flow_path")
|
101 |
+
else:
|
102 |
st.warning("Please upload a file first!")
|