# Libraries
import io
import os
import numpy as np
import pandas as pd
import streamlit as st
def login():
# interface codes for the login screen
# (css,buttons,background,input area etc )
path_input_0 = st.text_input(
"File Path:",
"Please enter the path to the folder containing the Abstract_Account_Web_App.py file",
key="PATH_INPUT_LAST"
)
st.write(path_input_0)
global proceed
if st.button("Proceed"):
st.session_state["page"] = "main"
st.balloons()
st.experimental_rerun()
def main():
if 'PATH_INPUT_LAST' in st.session_state:
file0 = st.session_state["PATH_INPUT_LAST"]+"/Bankomat AlıĆveriĆ Ăzeti.csv"
st.write(file0)
if(os.path.exists(file0) and os.path.isfile(file0)):
os.remove(file0)
print("file was deleted as preprocessing")
else:
print("file was not found to delete")
# interface codes for the main screen
# (css,input,buttons etc.)
def set_texts(pdf_files:list):
print("starting to text process")
#This function reads pdf and gets "CRC-32" components as texts
for pdf_file in pdf_files:
with fitz.open(pdf_file) as doc:
text = ""
for page in doc:
new_text = page.get_text()
text += new_text
return text
pathz = st.session_state["PATH_INPUT_LAST"] + "/Bankomat AlıĆveriĆ Ăzeti.pdf"
st.write("path1:", pathz)
file_names = r'%s' % pathz
st.write(file_names)
set_texts([file_names])
if st.button('Show Info Analysis'):
st.write(file_names)
if __name__ == "__main__":
if "page" not in st.session_state:
st.session_state["page"] = "login"
if st.session_state["page"] == "login":
login()
elif st.session_state["page"] == "main":
st.balloons()
main()
Hello friends, Iâm entering the input area on the login screen: âfolder path containing the Abstract_Account_Web_App.py fileâ and then I am pressing the Proceed button.
When it comes to the main screen, path1, and file_names are displayed correctly and properly. However, when I click the âShow Info Analysisâ button on the main screen, I get an error as below:
âKeyError: 'st.session_state has no key âPATH_INPUT_LASTâ. Did you forget to initialize it? More info: https://docs.streamlit.io/library/advanced -features/session-state#initializationâ
How can I solve this problem?
Traceback:
File "f:\anaconda\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 556, in _run_script
exec(code, module.__dict__)
File "C:\Users\Desktop\abstract_account\Abstract_Account_Web_App.py", line 85, in <module>
main()
File "C:\Users\Desktop\abstract_account\Abstract_Account_Web_App.py", line 64, in main
pathz = st.session_state["PATH_INPUT_LAST"] + "/Bankomat AlıĆveriĆ Ăzeti.pdf"
File "f:\anaconda\lib\site-packages\streamlit\runtime\state\session_state_proxy.py", line 93, in __getitem__
return get_session_state()[key]
File "f:\anaconda\lib\site-packages\streamlit\runtime\state\safe_session_state.py", line 111, in __getitem__
return self._state[key]
File "f:\anaconda\lib\site-packages\streamlit\runtime\state\session_state.py", line 440, in __getitem__
raise KeyError(_missing_key_error_message(key))