AttributeError: '_thread._local' object has no attribute 'value'

Iā€™m having an issue when I try to use a conditional statement to display text. My code is as follows:

st.header('Expected Winnings Based on Risk Profile')
option = st.radio("What level of risk would you like to adopt?",("High","Medium","Low"))
if option == "High":
    st.write("Your expected returns are: ",High_Risk_Winnings)
elif option == "Medium":
    st.write("Your expected returns are: ",Medium_Risk_Winnings)
else:
    st.write("Your expected returns are: ",Low_Risk_Winnings)

High / Medium / Low _Risk_Winnings are all objects from my preceding code.

Once Iā€™ve run the code, when I click on one of the radio buttons I get the following error message:
AttributeError: ā€˜_thread._localā€™ object has no attribute 'valueā€™

Is anyone able to help me please?

Hey @Charly-Isabella, welcome to the Streamlit forums!

I tried running your code snippet and canā€™t reproduce the error. But after looking at the traceback you provided and doing a little more research, I think this is a Keras issue related to version 2.3.0 of Keras.

Is that the version youā€™re using? If so, can you try 2.2.5 or 2.3.1?

See this related Stack Overflow question for more info: https://stackoverflow.com/a/58023399

Otherwise, if this doesnā€™t fix your issue, would it be possible to share a more complete code snippet that includes the Keras part?

Thanks!

Hello,

The previously proposed solution did not satisfied me as i did not want to downgrade Keras and TF. After searching online, I found this fix, which worked for me :

Iā€™m using keras 2.3.1, tensorflow 2.0.0, python 3.6, linux Mint 19.2 Cinnamon.
My project is based on Waitress, so I canā€™t use ā€œthreaded=Falseā€.

I found an UGLY workaroundā€¦
In the main ā€œpost managerā€ function I put this codeā€¦

import keras.backend.tensorflow_backend as tb
tb._SYMBOLIC_SCOPE.value = True

And this solved the problem for meā€¦
I hope it will be useful to find a solution

By @ccasadei

I hope this can be a solution for others having the same problem as us.

Best,

2 Likes

Hi I set the

tb._SYMBOLIC_SCOPE.value = True

Then I am facing the issue of

ValueError: Cannot create an execution function which is comprised of elements from multiple graphs.

Hi @johnymephisto,

Welcome to the forum :wave:

Can you try the recommendation in this comment?

Use
from tensorflow.keras ...

Instead of
from keras ...

3 Likes

Hi @Jonathan_Rhone, I already did this and it worked for me.
Thanks

This made my day, thank you!
I needed:

from tensorflow.keras.applications.vgg16 import VGG16
instead of:
from keras.applications.vgg16 import VGG16
Although it was working in one folder right but not another.

1 Like

@Jonathan_Rhone Thank you for the recommendation. It works.

1 Like

I tried downgrading Keras-gpu (which is currently 2.3.1). However, for any version I try to downgrade to, I get an error. For example:


PackageNotFoundError: Packages missing in current channels:

  • keras-gpu 2.2.5*

We have searched for the packages in the following channels:


I have been stuck for many days trying to solve this. Please help.