I have some large model files (*.h5) that I have upload to GitHub using LFS. My stream app loads these models from my GitHub repo.I suspect that may have something to do with why the cloning is failing.
I recommend checking out the insightful post by @dataprofessor on this subject. It provides detailed steps for managing Git LFS effectively, which should help troubleshoot your issue.
Thanks @Charly_Wargnier . I already followed the instructions you linked to but I am still not able to get my app to deploy for some reason. I will keep digging to see if anyone else has been able to solve this problem, Thanks
One note – Git LFS imposes a quota on data storage and bandwidth. Exceeding this quota can inhibit further LFS downloads. Did you verify your account’s quota status?
I am either going to have to wait for 25 days till my quota is reset or I am going to have to pay for extra bandwidth. I was hoping I could switch to another Git provider such as Bitbucket but then it looks like Streamlit does not support any other provider other than GitHub
I have stored my model files in Google drive but I do not know how to load a model in my streamlit app from gdrive. Would you have instructions for that? I can try and search how to do it. Thanks
Sure – Here’s how you can load your model from Google Drive into your app:
Publicly share your model file on Google Drive and get the shareable link.
Convert the shareable link to a direct download link by changing its format to https://drive.google.com/uc?id=FILE_ID.
Use the following Python code in your app to download and load the model:
import requests
from io import BytesIO
from your_model_library import load_model # Update this import as needed
# Replace 'YOUR_FILE_ID_HERE' with your actual file ID
url = 'https://drive.google.com/uc?id=YOUR_FILE_ID_HERE'
@st.cache
def load_model_from_gdrive(url):
response = requests.get(url)
model_file = BytesIO(response.content)
model = load_model(model_file)
return model
model = load_model_from_gdrive(url)
I followed the instructions you provided to download my .h5 models from my GooglDrive (I have made these h5 model files viewable to everyone), however, I am getting the following error. I can’t seem to find a suitable solution to this error online.
Here is the link to my GitHub source file - bestsecret/src/bestsecret_app_new.py at main · anurag-chowdhury1975/bestsecret · GitHub
OSError: Unable to load model. Filepath is not an hdf5 file (or h5py is not available) or SavedModel. Received: filepath=<_io.BytesIO object at 0x2808cbe70>
Traceback:
File “/Applications/anaconda3/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py”, line 535, in _run_script
exec(code, module.dict)
File “/Users/chaitisen/Desktop/propulsion/bestsecret/src/bestsecret_app_new.py”, line 64, in
models = load_models()
^^^^^^^^^^^^^
File “/Users/chaitisen/Desktop/propulsion/bestsecret/src/bestsecret_app_new.py”, line 42, in load_models
model_bag = load_model_from_gdrive(‘https://drive.google.com/uc?id=1VSitaSvcEuzNIPI_Mb1lIk9N4hBYVBWb’)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Applications/anaconda3/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py”, line 212, in wrapper
return cached_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Applications/anaconda3/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py”, line 241, in call
return self._get_or_create_cached_value(args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Applications/anaconda3/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py”, line 268, in _get_or_create_cached_value
return self._handle_cache_miss(cache, value_key, func_args, func_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Applications/anaconda3/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py”, line 324, in _handle_cache_miss
computed_value = self._info.func(*func_args, **func_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/chaitisen/Desktop/propulsion/bestsecret/src/bestsecret_app_new.py”, line 27, in load_model_from_gdrive
model = load_model(model_file)
^^^^^^^^^^^^^^^^^^^^^^
File “/Applications/anaconda3/lib/python3.11/site-packages/keras/src/saving/saving_api.py”, line 262, in load_model
return legacy_sm_saving_lib.load_model(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Applications/anaconda3/lib/python3.11/site-packages/keras/src/utils/traceback_utils.py”, line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File “/Applications/anaconda3/lib/python3.11/site-packages/keras/src/saving/legacy/save.py”, line 259, in load_model
raise IOError(
You could start by making sure the .h5 file on Google Drive isn’t corrupted. Maybe download it to your computer and give it a go with the same code to see if everything’s okay with the file itself.
Also, it might be a good idea to try loading the model directly from your local drive using the load_model function. This way, you can figure out if the quirk is really about streaming the file from Google Drive or something else with the file.
I was loading my models from my local drive initially and it worked fine. I even re-downloaded the models from Google drive just to make sure it wasn’t corrupted when I uploaded it the first time and I was able load the models perfectly from my local drive. This confirms that the models that are in Google drive are not corrupted.
There seems to be something else going on here…I can’t figure out what it is.
Sorry I forgot to respond to you earlier. I was successful in making it work by loading my .h5 model from an S3 bucket. I couldn’t load it directly as Keras.models.load_model() expects a local path to the model. I had to download the model to a local drive first and then load it via the following code -
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.