Summary
I get message error that st.session_state has no attribute “files” in the last line of the code bellow.
Steps to reproduce
Code snippet:
import streamlit as st
import os
import random
state = st.session_state
generated_path = 'generated_predictions.txt'
ORI_RES = f'path_ori'
# CONTEXT_SENT_0_h_0_RES = f'path_1/{generated_path}'
CONTEXT_SENT_0_h_1_RES = f'/path2/{generated_path}'
CONTEXT_SENT_1_h_1_RES = f'/path3/{generated_path}'
source_path = 'path_source'
OPTIONS = ["label 1", "label 2"]
if "annotations" not in state:
state.annotations = {}
f_0 = open(source_path)
source = f_0.read().split('\n')[:-1]
f_1 = open(ORI_RES)
ori_res = f_1.read().split('\n')[:-1]
# f_2 = open(CONTEXT_SENT_0_h_0_RES)
f_3 = open(CONTEXT_SENT_0_h_1_RES)
sent_0_h_1 = f_3.read().split('\n')[:-1]
f_4 = open(CONTEXT_SENT_1_h_1_RES)
sent_1_h_1 = f_4.read().split('\n')[:-1]
state.files = list()
state.files = list(zip(source, ori_res, sent_0_h_1, sent_1_h_1))
state.current_file = state.files[0]
Actual behavior:
st.session_state has no attribute “files”. Did you forget to initialize it? More info: Add statefulness to apps - Streamlit Docs
Debug info
- Streamlit version: 1.15.2
- Python version: 3.9.15
- Using Conda