Loading Image

Hello,
My code has worked in my laptop. But it has problem when I try to use streamlitapp.com. Images and maincode.py are in same directory

FileNotFoundError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you're on Streamlit Cloud, click on 'Manage app' in the lower right of your app).

Traceback:


File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 562, in _run_script
    exec(code, module.__dict__)File "/app/plastichingelengthwalls1/streamPHL.py", line 8, in <module>
    image1 = Image.open('./Capture1.png')File "/home/appuser/venv/lib/python3.9/site-packages/PIL/Image.py", line 3092, in open
    fp = builtins.open(filename, "rb")

Here is the code:

import   streamlit  as st; from PIL import Image; import numpy  as np
from  sklearn.ensemble   import   RandomForestRegressor
import pandas  as pd; import pickle

st.title('Plastic hinge length of reinforced concrete structural walls (RCSWs) ')
with st.container():
    image1 = Image.open('./Capture1.png')
    image2 = Image.open('./Capture2.png')

    st.image(image1)
    st.image(image2)

SCR1 = st.number_input('Insert secondary cracking ratio:',0.0)
WL1 = st.number_input('Insert wall length (m):',0.0)
HE1 = st.number_input('Insert wall effective height (m):',0.0)
ALR1 = st.number_input('Insert axial load ratio:',0.0)
SSP1 = st.number_input('Insert shear stress variable:',0.0)
WL2 = WL1*1000.0; HE2 = HE1*1000.0;
inputvec = np.array([SCR1, WL2, HE2, ALR1, SSP1])

filename = './finalized_model.sav'

with st.container():

    if st.button('Run'):
        if WL2!=0 and HE2!=0:
            loaded_model = pickle.load(open(filename, 'rb'))

            yhat1 = loaded_model.predict(inputvec.reshape(1, -1))
            st.write("Plastic hinge length is: " , round(yhat1[0]/1000.0, 4), "m")
        else:
            st.write("Secondary cracking ratio, wall length and wall effective height should not be zero.")


st.header("Developers:")
with st.container():
    image3 = Image.open('./Capture3.png')
    image4 = Image.open('./Capture4.png')

    st.image(image3)
    st.image(image4)

I also remove “./”. But it didn’t work. I see this message in Manage app:

FileNotFoundError: [Errno 2] No such file or directory: 'Capture1.png'

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