Streamlit Deployment

My app is working locally, but it is throwing error when I tried deploying on line.
Here is the error
’ ’ ’ ModuleNotFoundError: 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/scriptrunner/script_runner.py", line 557, in _run_script
    exec(code, module.__dict__)File "breccia_rock.py", line 9, in <module>
    from tensorflow.keras.preprocessing.image import ImageDataGenerator, array_t

Hi @Taiwo_Osunrinde,

Thanks for posting! Can you share your requirements.txt file?

Caroline :balloon:

altair==4.1.0
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
astor==0.8.1
attrs==21.2.0
backcall==0.2.0
base58==2.1.1
bleach==4.1.0
blinker==1.4
cachetools==5.0.0
certifi==2021.10.8
cffi==1.15.0
charset-normalizer==2.0.9
click==7.1.2
colorama==0.4.4
cycler==0.11.0
debugpy==1.5.1
decorator==5.1.0
defusedxml==0.7.1
entrypoints==0.3
fonttools==4.28.5
gitdb==4.0.9
GitPython==3.1.24
idna==3.3
ipykernel==6.6.0
ipython==7.30.1
ipython-genutils==0.2.0
ipywidgets==7.6.5
jedi==0.18.1
Jinja2==3.0.3
joblib==1.1.0
jsonschema==4.3.2
jupyter-client==7.1.0
jupyter-core==4.9.1
jupyterlab-pygments==0.1.2
jupyterlab-widgets==1.0.2
kiwisolver==1.3.2
MarkupSafe==2.0.1
matplotlib==3.5.1
matplotlib-inline==0.1.3
mistune==0.8.4
nbclient==0.5.9
nbconvert==6.3.0
nbformat==5.1.3
nest-asyncio==1.5.4
notebook==6.4.6
numpy==1.21.5
packaging==21.3
pandas==1.3.5
pandocfilters==1.5.0
parso==0.8.3
pickleshare==0.7.5
Pillow==8.4.0
prometheus-client==0.12.0
prompt-toolkit==3.0.24
protobuf==3.19.1
pyarrow==6.0.1
pycparser==2.21
pydeck==0.7.1
Pygments==2.10.0
Pympler==1.0.1
pyparsing==3.0.6
pyrsistent==0.18.0
python-dateutil==2.8.2
pytz==2021.3
pytz-deprecation-shim==0.1.0.post0
pywin32==303
pywinpty==1.1.6
pyzmq==22.3.0
requests==2.26.0
scikit-learn==1.0.1
scipy==1.7.3
seaborn==0.11.2
Send2Trash==1.8.0
six==1.16.0
scikit-learn==0.22.1
smmap==5.0.0
streamlit==1.3.0
terminado==0.12.1
testpath==0.5.0
threadpoolctl==3.0.0
toml==0.10.2
toolz==0.11.2
tornado==6.1
traitlets==5.1.1
typing_extensions==4.0.1
tzdata==2021.5
tzlocal==4.1
urllib3==1.26.7
validators==0.18.2
watchdog==2.1.6
wcwidth==0.2.5
webencodings==0.5.1
widgetsnbextension==3.5.2
wincertstore==0.2

It looks like you’re missing tensorflow in your requirements.txt file.

I just included it,
I got this

WARNING: You are using pip version 22.0.3; however, version 22.2.2 is available.
You should consider upgrading via the '/home/appuser/venv/bin/python -m pip install --upgrade pip' command.

────────────────────────────────────────────────────────────────────────────────────────

[15:11:04] ❗️ installer returned a non-zero exit code

Hi @Taiwo_Osunrinde, I would try restarting the app.

× Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [6 lines of output]
      
      Cargo, the Rust package manager, is not installed or is not on PATH.
      This package requires Rust and Cargo to compile extensions. Install it through
      the system's package manager or via https://rustup.rs/
      
      Checking for Rust toolchain....
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
WARNING: You are using pip version 22.0.3; however, version 22.2.2 is available.
You should consider upgrading via the '/home/appuser/venv/bin/python -m pip install --upgrade pip' command.
Checking if Streamlit is installed

────────────────────────────────────────────────────────────────────────────────────────

[15:18:37] ❗️ installer returned a non-zero exit code
[15:18:37] ❗️ Error during processing dependencies! Please fix the error and push an update, or try restarting the app.
```× Preparing metadata (pyproject.toml) did not run successfully.

  │ exit code: 1

  ╰─> [6 lines of output]

      

      Cargo, the Rust package manager, is not installed or is not on PATH.

      This package requires Rust and Cargo to compile extensions. Install it through

      the system's package manager or via https://rustup.rs/

      

      Checking for Rust toolchain....

      [end of output]

  

  note: This error originates from a subprocess, and is likely not a problem with pip.

error: metadata-generation-failed


× Encountered error while generating package metadata.

╰─> See above for output.


note: This is an issue with the package mentioned above, not pip.

hint: See above for details.

WARNING: You are using pip version 22.0.3; however, version 22.2.2 is available.

You should consider upgrading via the '/home/appuser/venv/bin/python -m pip install --upgrade pip' command.

Checking if Streamlit is installed


────────────────────────────────────────────────────────────────────────────────────────


[15:18:37] ❗️ installer returned a non-zero exit code

[15:18:37] ❗️ Error during processing dependencies! Please fix the error and push an update, or try restarting the app.

Hi @Taiwo_Osunrinde, removing pywinpty should resolve this error I believe (check out this thread)

Thanks.

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/scriptrunner/script_runner.py", line 557, in _run_script
    exec(code, module.__dict__)File "breccia_rock.py", line 17, in <module>
    image = Image.open(r"C:\Users\taiwo.osunrinde\Desktop\nevadaimage.jfif")File "/home/appuser/venv/lib/python3.9/site-packages/PIL/Image.py", line 2953, in open
    fp = builtins.open(filename, "rb")

I figured it out.

Thanks for your help

#grabbing names from working directory and removing extension
from natsort import natsorted
Image_dir=os.getcwd()
Breccia_name= []
for root, dirs, files in os.walk(Image_dir):
    j=natsorted(files)
    for i in j:
        if i.endswith('jpg'):
            Breccia_name.append(i)
            #print(i)
            #Breccia_name.extend(os.path.splitext(name)[0] for name in i)
print(Breccia_name)
      


#Grabbing the image name and depth

spliited, name, GeoFrom, GeoTo=[],[],[],[]
for i in Breccia_name:
# setting the maxsplit parameter to 3, will return a list with 4 elements!    
    x = i.split("_", 3)
    spliited.append(x)
#print(spliited)

for j in spliited:
    name_=j[0]
    GeoFrom_=j[1]
    GeoTo_=j[2]
    name.append(name_)
    GeoFrom.append(GeoFrom_)
    GeoTo.append(GeoTo_)

This code works well locally, how do I get it do work when deploying on streamlit cloud server.

It is throwing the following error:
IndexError: 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/scriptrunner/script_runner.py", line 557, in _run_script
    exec(code, module.__dict__)File "/app/ngm-app/breccia_rock.py", line 85, in <module>
    GeoFrom_=j[1]

Hi @Taiwo_Osunrinde,

Does j[1] exist? The error indicates that it doesn’t exist.

Caroline

yes.
The way the app works is that it creates a directory and save images users uploaded into that directory.
it the walk through the directory to grab the text

the j[1] is not meant to initialize until users upload the images they want

It sounds like you’re accessing j[1] before it’s initialized.

#defining a function to load image
def load_image(image_file):
    img=Image.open(image_file)
    return img



#creating a directory
dir = "Breccia_Rock"
try:
    os.mkdir(dir)
    print ("Directory is created")
except FileExistsError:
    print ("Directory already exists")
    
    

#image Preprocessing
batch_size=1

def pre_process():
    Breccia_Predict_Images = os.getcwd()
    Breccia_Predict_datagen = ImageDataGenerator(rescale=1. / 255)
    img_width, img_height = 400, 600
    Breccia_predict_generator = Breccia_Predict_datagen.flow_from_directory(Breccia_Predict_Images, target_size=(img_width, img_height),
                                                                            batch_size=1, class_mode=None, shuffle=False)
    return Breccia_predict_generator

here is the code before the j[1] block

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