OSError: Unable to open file (file signature not found)

OSError: Unable to open file (file signature not found)

Traceback:

File "/app/.heroku/python/lib/python3.9/site-packages/streamlit/scriptrunner/script_runner.py", line 443, in _run_script
    exec(code, module.__dict__)File "/app/rps_app.py", line 21, in <module>
    model = tf.keras.models.load_model('my__model.hdf5')File "/app/.heroku/python/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler
    raise e.with_traceback(filtered_tb) from NoneFile "/app/.heroku/python/lib/python3.9/site-packages/h5py/_hl/files.py", line 507, in __init__
    fid = make_fid(name, mode, userblock_size, fapl, fcpl, swmr=swmr)File "/app/.heroku/python/lib/python3.9/site-packages/h5py/_hl/files.py", line 220, in make_fid
    fid = h5f.open(name, flags, fapl=fapl)File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapperFile "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapperFile "h5py/h5f.pyx", line 106, in h5py.h5f.open

Hi @sarthakgarg77, welcome to the Streamlit community!

Can you provide the code snippet that demonstrates this behavior?

Best,
Randy

I got the same error, Can anyone help?

Hi @Thisara_Shyamalee, welcome to the Streamlit community!

Can you provide the code snippet or a link to a GitHub repo that demonstrates this behavior?

Hi @snehankekre,
Here it is.

@Thisara_Shyamalee This looks like a bug in how Streamlit Cloud clones Git LFS objects. I’ve raised this issue internally.

In the meantime, here’s a workaround:

  1. Right after your imports, include the following snippet to download your .h5 model with curl to Streamlit Cloud:
import subprocess
if not os.path.isfile('model.h5'):
    subprocess.run(['curl --output model.h5 "https://media.githubusercontent.com/media/ShyamaleeT/glaucocare/main/sep_5.h5"'], shell=True)
  1. Replace model = tf.keras.models.load_model('sep_5.h5', compile=False) with:
model = tf.keras.models.load_model('model.h5', compile=False)
  1. Don’t delete or rename the sep_5.h5 file from your repo, as we’re using its url to download your model in Step 1

Once you make the above changes, your app should successfully load your model! :rocket:

2 Likes

Thank You @snehankekre.
This is working! :smiley:

1 Like

Hi @snehankekre,
I used two .h5 files (Inside the models folder of the GitHub repository) for my application. So I’m getting the same error " OSError: Unable to open file (file signature not found)". Can you guide me?

My Git Hub Link: https://github.com/ShyamaleeT/glaucocare

I am getting the same error, can anybody solve this?

2023-02-10 06:29:38.372 Uncaught app exception

Traceback (most recent call last):

  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script

    exec(code, module.__dict__)

  File "/app/stock_prediction_model/app.py", line 59, in <module>

    model = load_model('keras_model.h5')

  File "/home/appuser/venv/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 70, in error_handler

    raise e.with_traceback(filtered_tb) from None

  File "/home/appuser/venv/lib/python3.9/site-packages/h5py/_hl/files.py", line 567, in __init__

    fid = make_fid(name, mode, userblock_size, fapl, fcpl, swmr=swmr)

  File "/home/appuser/venv/lib/python3.9/site-packages/h5py/_hl/files.py", line 231, in make_fid

    fid = h5f.open(name, flags, fapl=fapl)

  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper

  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper

  File "h5py/h5f.pyx", line 106, in h5py.h5f.open

OSError: Unable to open file (file signature not found)

2023-02-10 06:36:56.080 Uncaught app exception

Traceback (most recent call last):

  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script

    exec(code, module.__dict__)

  File "/app/stock_prediction_model/app.py", line 59, in <module>

    model = load_model('keras_model.h5')

  File "/home/appuser/venv/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 70, in error_handler

    raise e.with_traceback(filtered_tb) from None

  File "/home/appuser/venv/lib/python3.9/site-packages/h5py/_hl/files.py", line 567, in __init__

    fid = make_fid(name, mode, userblock_size, fapl, fcpl, swmr=swmr)

  File "/home/appuser/venv/lib/python3.9/site-packages/h5py/_hl/files.py", line 231, in make_fid

    fid = h5f.open(name, flags, fapl=fapl)

  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper

  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper

  File "h5py/h5f.pyx", line 106, in h5py.h5f.open

OSError: Unable to open file (file signature not found)

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