StreamLit Error get_cube() error

Summary

While running Energy Framework for EVERY AI/ML Application - YouTube
[RMiftakhov/EFramework (github.com)] (GitHub - RMiftakhov/EFramework)

I get this below error

AttributeError: ‘NoneType’ object has no attribute ‘get_cube’
Traceback:
File “C:\ProgramData\anaconda3\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py”, line 565, in _run_script
exec(code, module.dict)
File “C:\GitHub\EFramework\pages\4_🟢3D Seismic Denoising+SuperResolution.py”, line 247, in
np_data = st.session_state[module_name][‘numpy_data’].get_cube()

Steps to reproduce

Code snippet:

add code here
import streamlit as st
np_data = st.session_state[module_name]['numpy_data'].get_cube()

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:

Explain what you expect to happen when you run the code above.

Actual behavior:

Explain the undesired behavior or error you see when you run the code above.
If you’re seeing an error message, share the full contents of the error message here.

Debug info

  • Streamlit version: Streamlit, version 1.23.1
  • Python version: (Python 3.9.16)
  • Using Conda
  • OS version: Windows / Linux
  • Browser version: Edge \ Firefox

Requirements file

Using Conda? PipEnv? PyEnv? Pex? Share the contents of your requirements file here.
Not sure what a requirements file is? Check out this doc and add a requirements file to your app.

altair @ file:///home/conda/feedstock_root/build_artifacts/altair_1685366427998/work
asttokens @ file:///home/conda/feedstock_root/build_artifacts/asttokens_1670263926556/work
attrs @ file:///home/conda/feedstock_root/build_artifacts/attrs_1683424013410/work
backcall @ file:///home/conda/feedstock_root/build_artifacts/backcall_1592338393461/work
backports.functools-lru-cache @ file:///home/conda/feedstock_root/build_artifacts/backports.functools_lru_cache_1618230623929/work
base==0.0.0
blinker @ file:///home/conda/feedstock_root/build_artifacts/blinker_1681349778161/work
cachetools @ file:///home/conda/feedstock_root/build_artifacts/cachetools_1674482203741/work
certifi @ file:///croot/certifi_1683875369620/work/certifi
charset-normalizer @ file:///home/conda/feedstock_root/build_artifacts/charset-normalizer_1678108872112/work
click @ file:///home/conda/feedstock_root/build_artifacts/click_1666798198223/work
cmake==3.26.4
comm @ file:///home/conda/feedstock_root/build_artifacts/comm_1679481329611/work
contourpy @ file:///opt/conda/conda-bld/contourpy_1663827406301/work
cycler @ file:///tmp/build/80754af9/cycler_1637851556182/work
debugpy @ file:///home/conda/feedstock_root/build_artifacts/debugpy_1680755452907/work
decorator @ file:///home/conda/feedstock_root/build_artifacts/decorator_1641555617451/work
executing @ file:///home/conda/feedstock_root/build_artifacts/executing_1667317341051/work
filelock==3.12.1
fonttools==4.25.0
gitdb @ file:///home/conda/feedstock_root/build_artifacts/gitdb_1669279893622/work
GitPython @ file:///home/conda/feedstock_root/build_artifacts/gitpython_1676637751542/work
gmpy2 @ file:///tmp/build/80754af9/gmpy2_1645438755360/work
idna @ file:///home/conda/feedstock_root/build_artifacts/idna_1663625384323/work
importlib-metadata @ file:///home/conda/feedstock_root/build_artifacts/importlib-metadata_1682176699712/work
importlib-resources @ file:///home/conda/feedstock_root/build_artifacts/importlib_resources_1676919000169/work
ipykernel @ file:///home/conda/feedstock_root/build_artifacts/ipykernel_1684162692319/work
ipython @ file:///home/conda/feedstock_root/build_artifacts/ipython_1685727741709/work
ipywidgets @ file:///home/conda/feedstock_root/build_artifacts/ipywidgets_1680023138361/work
jedi @ file:///home/conda/feedstock_root/build_artifacts/jedi_1669134318875/work
Jinja2 @ file:///home/conda/feedstock_root/build_artifacts/jinja2_1654302431367/work
jsonschema @ file:///home/conda/feedstock_root/build_artifacts/jsonschema-meta_1669810440410/work
jupyter_client @ file:///home/conda/feedstock_root/build_artifacts/jupyter_client_1681432441054/work
jupyter_core @ file:///home/conda/feedstock_root/build_artifacts/jupyter_core_1678994160714/work
jupyterlab-widgets @ file:///home/conda/feedstock_root/build_artifacts/jupyterlab_widgets_1684239754370/work
keras @ file:///home/builder/mesters/opt/envs/tensorflow/conda-bld/keras_1682445665871/work/keras-2.12.0-py2.py3-none-any.whl
Keras-Preprocessing @ file:///tmp/build/80754af9/keras-preprocessing_1612283640596/work
kiwisolver @ file:///croot/kiwisolver_1672387140495/work
lit==16.0.5.post0
markdown-it-py @ file:///home/conda/feedstock_root/build_artifacts/markdown-it-py_1677100944732/work
MarkupSafe @ file:///home/conda/feedstock_root/build_artifacts/markupsafe_1685769048265/work
matplotlib @ file:///croot/matplotlib-suite_1679593461707/work
matplotlib-inline @ file:///home/conda/feedstock_root/build_artifacts/matplotlib-inline_1660814786464/work
mdurl @ file:///home/conda/feedstock_root/build_artifacts/mdurl_1639515908913/work
mkl-fft==1.3.6
mkl-random @ file:///work/mkl/mkl_random_1682950433854/work
mkl-service==2.4.0
mpmath==1.2.1
munkres==1.1.4
nest-asyncio @ file:///home/conda/feedstock_root/build_artifacts/nest-asyncio_1664684991461/work
networkx @ file:///croot/networkx_1678964333703/work
numpy @ file:///work/mkl/numpy_and_numpy_base_1682953417311/work
nvidia-cublas-cu11==11.10.3.66
nvidia-cuda-cupti-cu11==11.7.101
nvidia-cuda-nvrtc-cu11==11.7.99
nvidia-cuda-runtime-cu11==11.7.99
nvidia-cudnn-cu11==8.5.0.96
nvidia-cufft-cu11==10.9.0.58
nvidia-curand-cu11==10.2.10.91
nvidia-cusolver-cu11==11.4.0.1
nvidia-cusparse-cu11==11.7.4.91
nvidia-nccl-cu11==2.14.3
nvidia-nvtx-cu11==11.7.91
packaging @ file:///home/conda/feedstock_root/build_artifacts/packaging_1681337016113/work
pandas @ file:///home/conda/feedstock_root/build_artifacts/pandas_1685342911872/work
parso @ file:///home/conda/feedstock_root/build_artifacts/parso_1638334955874/work
pexpect @ file:///home/conda/feedstock_root/build_artifacts/pexpect_1667297516076/work
pickleshare @ file:///home/conda/feedstock_root/build_artifacts/pickleshare_1602536217715/work
Pillow==9.3.0
pkgutil_resolve_name @ file:///home/conda/feedstock_root/build_artifacts/pkgutil-resolve-name_1633981968097/work
platformdirs @ file:///home/conda/feedstock_root/build_artifacts/platformdirs_1686403120743/work
plotly @ file:///home/conda/feedstock_root/build_artifacts/plotly_1686267560832/work
ply==3.11
pooch @ file:///home/conda/feedstock_root/build_artifacts/pooch_1679580333621/work
prompt-toolkit @ file:///home/conda/feedstock_root/build_artifacts/prompt-toolkit_1677600924538/work
protobuf==4.21.12
psutil @ file:///home/conda/feedstock_root/build_artifacts/psutil_1681775019467/work
ptyprocess @ file:///home/conda/feedstock_root/build_artifacts/ptyprocess_1609419310487/work/dist/ptyprocess-0.7.0-py2.py3-none-any.whl
pure-eval @ file:///home/conda/feedstock_root/build_artifacts/pure_eval_1642875951954/work
pyarrow==12.0.0
pydeck @ file:///home/conda/feedstock_root/build_artifacts/pydeck_1667589451974/work
Pygments @ file:///home/conda/feedstock_root/build_artifacts/pygments_1681904169130/work
Pympler @ file:///home/conda/feedstock_root/build_artifacts/pympler_1658620692385/work
pyparsing @ file:///opt/conda/conda-bld/pyparsing_1661452539315/work
PyQt5-sip==12.11.0
pyrsistent @ file:///home/conda/feedstock_root/build_artifacts/pyrsistent_1672681476680/work
PySocks @ file:///home/conda/feedstock_root/build_artifacts/pysocks_1661604839144/work
python-dateutil @ file:///home/conda/feedstock_root/build_artifacts/python-dateutil_1626286286081/work
pytz @ file:///home/conda/feedstock_root/build_artifacts/pytz_1680088766131/work
pytz-deprecation-shim @ file:///home/conda/feedstock_root/build_artifacts/pytz-deprecation-shim_1666781949416/work
PyYAML @ file:///home/conda/feedstock_root/build_artifacts/pyyaml_1666772387118/work
pyzmq @ file:///home/conda/feedstock_root/build_artifacts/pyzmq_1685519261210/work
requests @ file:///home/conda/feedstock_root/build_artifacts/requests_1684774241324/work
rich @ file:///home/conda/feedstock_root/build_artifacts/rich-split_1685565049610/work/dist
scipy==1.10.1
segyio==1.9.3
sip @ file:///tmp/abs_44cd77b_pu/croots/recipe/sip_1659012365470/work
six @ file:///home/conda/feedstock_root/build_artifacts/six_1620240208055/work
smmap @ file:///home/conda/feedstock_root/build_artifacts/smmap_1611376390914/work
stack-data @ file:///home/conda/feedstock_root/build_artifacts/stack_data_1669632077133/work
streamlit @ file:///home/conda/feedstock_root/build_artifacts/streamlit_1685962413017/work
streamlit-image-comparison==0.0.4
sympy @ file:///croot/sympy_1668202399572/work
tenacity @ file:///home/conda/feedstock_root/build_artifacts/tenacity_1677600641219/work
toml @ file:///home/conda/feedstock_root/build_artifacts/toml_1604308577558/work
toolz @ file:///home/conda/feedstock_root/build_artifacts/toolz_1657485559105/work
torch==2.0.1
torchaudio==2.0.2
torchvision==0.15.2
tornado @ file:///home/conda/feedstock_root/build_artifacts/tornado_1684150239299/work
tqdm @ file:///croot/tqdm_1679561862951/work
traitlets @ file:///home/conda/feedstock_root/build_artifacts/traitlets_1675110562325/work
triton==2.0.0
typing_extensions @ file:///home/conda/feedstock_root/build_artifacts/typing_extensions_1685704949284/work
tzdata @ file:///home/conda/feedstock_root/build_artifacts/python-tzdata_1680081134351/work
tzlocal @ file:///home/conda/feedstock_root/build_artifacts/tzlocal_1679156220555/work
urllib3 @ file:///home/conda/feedstock_root/build_artifacts/urllib3_1686156552494/work
validators @ file:///home/conda/feedstock_root/build_artifacts/validators_1676837160772/work
watchdog @ file:///home/conda/feedstock_root/build_artifacts/watchdog_1679332862337/work
wcwidth @ file:///home/conda/feedstock_root/build_artifacts/wcwidth_1673864653149/work
widgetsnbextension @ file:///home/conda/feedstock_root/build_artifacts/widgetsnbextension_1680021576815/work
zipp @ file:///home/conda/feedstock_root/build_artifacts/zipp_1677313463193/work

Links

Additional information

If needed, add any other context about the problem here.

The error message you provided indicates that there is an AttributeError in your code, specifically 'NoneType' object has no attribute 'get_cube'. This error occurs when you are trying to access the get_cube() method of an object that is None (i.e., it doesn’t exist).

To resolve this issue, you need to ensure that the object st.session_state[module_name]['numpy_data'] is not None before calling the get_cube() method on it. Here’s an example of how you can modify your code to handle this:

import streamlit as st

# Check if the object is not None before calling get_cube()
if 'numpy_data' in st.session_state.get(module_name, {}):
    np_data = st.session_state[module_name]['numpy_data'].get_cube()
else:
    st.error('numpy_data is not available in session_state')

By adding the condition if 'numpy_data' in st.session_state.get(module_name, {}), you check if the key 'numpy_data' exists in the session state dictionary for the given module_name. If it exists, you can safely call the get_cube() method. Otherwise, you can display an error message indicating that 'numpy_data' is not available in the session state.

Make sure to replace module_name with the actual name of the module or variable you are using.

Thanks for your reply, appreciate your help
Still having some issues with code
Code is trying to read large seismic data and de-noise

The code as below

if module_name not in st.session_state:
st.session_state[module_name] = {“numpy_data” : None,
“numpy_result” : None, “is_predicted” : False, ‘cropped_info’ : None ,
“step1_status” : None, “step2_status” : None, “step3_status” : None}

if inference_submit:
#TODO may be two times memory allocation
np_data = st.session_state[module_name][‘numpy_data’].get_cube()

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.