# Upload Keras models or pickled files

**URL:** <https://discuss.streamlit.io/t/upload-keras-models-or-pickled-files/2246>\
**Category:** Using Streamlit\
**Tags:** keras\
**Created:** [March 20, 2020, 7:45pm UTC](https://discuss.streamlit.io/t/upload-keras-models-or-pickled-files/2246 "2020-03-20T19:45:23Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![pchalasani](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/pchalasani/32/1943_2.png) [@pchalasani](https://discuss.streamlit.io/u/pchalasani)\
**Post date:** [June 28, 2020, 12:24am UTC](https://discuss.streamlit.io/t/upload-keras-models-or-pickled-files/2246/3 "2020-06-28T00:24:35Z")

</div>

For those wondering how to upload a pre-trained keras model to a streamlit app, this might save you an afternoon of googling: 🙂

```auto
import zipfile
import tempfile

stream = st.file_uploader('TF.Keras model file (.h5py.zip)', type='zip')
if stream is not None:
  myzipfile = zipfile.ZipFile(stream)
  with tempfile.TemporaryDirectory() as tmp_dir:
    myzipfile.extractall(tmp_dir)
    root_folder = myzipfile.namelist()[0] # e.g. "model.h5py"
    model_dir = os.path.join(tmp_dir, root_folder)
    #st.info(f'trying to load model from tmp dir {model_dir}...')
    model = tf.keras.models.load_model(model_dir)
```

---

_[View the full topic](https://discuss.streamlit.io/t/upload-keras-models-or-pickled-files/2246)._
