streamlit-uploads-library


Namestreamlit-uploads-library JSON
Version 0.1.4 PyPI version JSON
download
home_pagehttps://github.com/hreikin/streamlit-uploads-library
SummaryA simple library or gallery for Streamlit made from widgets.
upload_time2023-04-01 08:40:49
maintainer
docs_urlNone
authorMichael Haslam
requires_python
licenseMIT
keywords streamlit uploads library gallery widgets
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Streamlit Uploads Library

[![Open in Streamlit](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://hreikin-streamlit-uploads-library-home-ar6h9h.streamlit.app/)

A simple uploads library and gallery for use in Streamlit projects. Check out the demo using the 
Streamlit Cloud button above. This package provides a simple wrapper around `st.file_uploader` 
with a save function included and also provides library and gallery views for use in Streamlit 
projects.

## Installation

Installation is available via pip:

```
pip install streamlit-uploads-library
```

## Usage

Using any of the provided views is easy, import `streamlit_uploads_library` and then instantiate the class 
with the required `directory` variable. Other options can be configured by passing in different variables 
when instantiating the class.

### Library View

- `directory` (required): A str() of the path to the folder containing the library images, for example, "assets".
- `file_extensions` (optional): A tuple() containing strings of the file extensions to include in the library, default is (".png", ".jpg", ".jpeg").
- `image_alignment` (optional): A str() with the CSS keyword used to align the images and details columns.
- `number_of_columns` (optional): An int() defining the number of required columns, default is 5.
- `show_details` (optional): A bool() to show or hide the file and edit details, False hides them, default is True to show them.
- `uid` (optional): A str() containing a unique identifier allowing you to create multiple libraries on the same page containing the same images.

```python
import streamlit as st
from streamlit_uploads_library.library import Library

st.set_page_config(page_title="Streamlit Uploads Library", layout="wide")
library = Library(directory="assets/landscape/")
library_columns = Library(directory="assets/portrait/", number_of_columns=4, uid="library-columns")
library_mixed = Library(directory="assets/mixed/", uid="mixed-library")
```

### Gallery View

- `directory` (required): A str() of the path to the folder containing the gallery images, for example, "assets".
- `file_extensions` (optional): A tuple() containing strings of the file extensions to include in the gallery, default is (".png", ".jpg", ".jpeg").
- `image_alignment` (optional): A str() with the CSS keyword used to align the images and details columns.
- `number_of_columns` (optional): An int() defining the number of required columns, default is 5.
- `show_details` (optional): A bool() to show or hide the file and edit details, True shows them, default is False to hide them and create a gallery.
- `uid` (optional): A str() containing a unique identifier allowing you to create multiple galleries on the same page containing the same images.

```python
import streamlit as st
from streamlit_uploads_library.gallery import Gallery

st.set_page_config(page_title="Streamlit Uploads Library", layout="wide")
default_gallery = Gallery(directory="assets/landscape/")
columns_gallery = Gallery(directory="assets/portrait/", number_of_columns=4, uid="gallery-columns")
mixed_gallery = Gallery(directory="assets/mixed/", uid="mixed-gallery")
```

### Upload View

The file uploader comes with multiple options able to be configured including 2 different view 
types. It is not required to use this and you can easily replace it with your own, it is provided 
as a convenience so you don't need to create the code yourself or replicate it across multiple 
projects.

- `save_location` (required): A str() of the path to the folder you wish to save images to, for example, "assets".
- `expander` (optional): A bool() used to set the initial state of the expander, only used when using the "expander" widget_type.
- `file_extensions` (optional): A list() containing strings of the file extensions to include in the library, default is (".png", ".jpg", ".jpeg").
- `info_msg` (optional): A str() used to set an info message above the uploader, default is "Upload new files here.".
- `header` (optional): A str() used to set the header of the "expander" or the header in the "container" type widget, default is "Upload Files", can be set to None to not display it.
- `uid` (optional): A str() containing a unique identifier allowing you to create multiple file uploaders on the same page.
- `upload_label` (optional): A str() used to set the label of the file uploader widget, default is "Upload Files", can be set to None to display an empty string instead.
- `widget_type` (optional): A str() defining the type of widget to use to display the file uploader, options are "container" or "expander", default is "container".

```python
import streamlit as st
from streamlit_uploads_library.uploads import UploadFiles

st.set_page_config(page_title="Streamlit Uploads Library", layout="wide")
default_uploader = UploadFiles(save_location="assets")
expander_uploader = UploadFiles(save_location="assets", widget_type="expander")
```

## Custom File Details

A default set of basic file details is provided for each image within the library. Using class 
inheritance this can be overridden to create your own file details section if you wish to include 
more information or different options.

```
import streamlit as st
from streamlit_uploads_library.library import Library

class CustomLibrary(Library):
    def __init__(self, directory, file_extensions=(".png", ".jpg", ".jpeg"), image_alignment="center", number_of_columns=5, show_details=True, uid="custom"):
        self.directory = directory
        self.file_extensions = file_extensions
        self.image_alignment = image_alignment
        self.number_of_columns = number_of_columns
        self.show_details = show_details
        self.uid = uid
        super(CustomLibrary, self).__init__(self.directory, self.file_extensions, self.image_alignment, self.number_of_columns, self.show_details, self.uid)

    def create_details(_self, img, filename_idx, uid):
        # Your details section code here
```

## Caching

Streamlit Uploads Library makes use of the `st.cache_resource` decorator so the library and gallery 
on this page will load from the cache instead of reloading the images each time the app is run. You 
will probably want to clear your cache after uploading new files to your app, the file uploader view 
provided by this package takes care of that for you but if you use your own file uploader and save 
function then to clear the cache you can use the `st.cache_resource.clear()` function provided by 
Streamlit.

## Example App (Demo)

To run the example application provided in the repository:

```bash
git clone https://github.com/hreikin/streamlit-uploads-library
cd streamlit-uploads-library/
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
streamlit run Home.py
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hreikin/streamlit-uploads-library",
    "name": "streamlit-uploads-library",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "streamlit,uploads,library,gallery,widgets",
    "author": "Michael Haslam",
    "author_email": "hreikin@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/39/d6/4495b9a600b1eb0f264927b997c259dd9b0e70be08c402b35465d8f3bc99/streamlit_uploads_library-0.1.4.tar.gz",
    "platform": null,
    "description": "# Streamlit Uploads Library\n\n[![Open in Streamlit](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://hreikin-streamlit-uploads-library-home-ar6h9h.streamlit.app/)\n\nA simple uploads library and gallery for use in Streamlit projects. Check out the demo using the \nStreamlit Cloud button above. This package provides a simple wrapper around `st.file_uploader` \nwith a save function included and also provides library and gallery views for use in Streamlit \nprojects.\n\n## Installation\n\nInstallation is available via pip:\n\n```\npip install streamlit-uploads-library\n```\n\n## Usage\n\nUsing any of the provided views is easy, import `streamlit_uploads_library` and then instantiate the class \nwith the required `directory` variable. Other options can be configured by passing in different variables \nwhen instantiating the class.\n\n### Library View\n\n- `directory` (required): A str() of the path to the folder containing the library images, for example, \"assets\".\n- `file_extensions` (optional): A tuple() containing strings of the file extensions to include in the library, default is (\".png\", \".jpg\", \".jpeg\").\n- `image_alignment` (optional): A str() with the CSS keyword used to align the images and details columns.\n- `number_of_columns` (optional): An int() defining the number of required columns, default is 5.\n- `show_details` (optional): A bool() to show or hide the file and edit details, False hides them, default is True to show them.\n- `uid` (optional): A str() containing a unique identifier allowing you to create multiple libraries on the same page containing the same images.\n\n```python\nimport streamlit as st\nfrom streamlit_uploads_library.library import Library\n\nst.set_page_config(page_title=\"Streamlit Uploads Library\", layout=\"wide\")\nlibrary = Library(directory=\"assets/landscape/\")\nlibrary_columns = Library(directory=\"assets/portrait/\", number_of_columns=4, uid=\"library-columns\")\nlibrary_mixed = Library(directory=\"assets/mixed/\", uid=\"mixed-library\")\n```\n\n### Gallery View\n\n- `directory` (required): A str() of the path to the folder containing the gallery images, for example, \"assets\".\n- `file_extensions` (optional): A tuple() containing strings of the file extensions to include in the gallery, default is (\".png\", \".jpg\", \".jpeg\").\n- `image_alignment` (optional): A str() with the CSS keyword used to align the images and details columns.\n- `number_of_columns` (optional): An int() defining the number of required columns, default is 5.\n- `show_details` (optional): A bool() to show or hide the file and edit details, True shows them, default is False to hide them and create a gallery.\n- `uid` (optional): A str() containing a unique identifier allowing you to create multiple galleries on the same page containing the same images.\n\n```python\nimport streamlit as st\nfrom streamlit_uploads_library.gallery import Gallery\n\nst.set_page_config(page_title=\"Streamlit Uploads Library\", layout=\"wide\")\ndefault_gallery = Gallery(directory=\"assets/landscape/\")\ncolumns_gallery = Gallery(directory=\"assets/portrait/\", number_of_columns=4, uid=\"gallery-columns\")\nmixed_gallery = Gallery(directory=\"assets/mixed/\", uid=\"mixed-gallery\")\n```\n\n### Upload View\n\nThe file uploader comes with multiple options able to be configured including 2 different view \ntypes. It is not required to use this and you can easily replace it with your own, it is provided \nas a convenience so you don't need to create the code yourself or replicate it across multiple \nprojects.\n\n- `save_location` (required): A str() of the path to the folder you wish to save images to, for example, \"assets\".\n- `expander` (optional): A bool() used to set the initial state of the expander, only used when using the \"expander\" widget_type.\n- `file_extensions` (optional): A list() containing strings of the file extensions to include in the library, default is (\".png\", \".jpg\", \".jpeg\").\n- `info_msg` (optional): A str() used to set an info message above the uploader, default is \"Upload new files here.\".\n- `header` (optional): A str() used to set the header of the \"expander\" or the header in the \"container\" type widget, default is \"Upload Files\", can be set to None to not display it.\n- `uid` (optional): A str() containing a unique identifier allowing you to create multiple file uploaders on the same page.\n- `upload_label` (optional): A str() used to set the label of the file uploader widget, default is \"Upload Files\", can be set to None to display an empty string instead.\n- `widget_type` (optional): A str() defining the type of widget to use to display the file uploader, options are \"container\" or \"expander\", default is \"container\".\n\n```python\nimport streamlit as st\nfrom streamlit_uploads_library.uploads import UploadFiles\n\nst.set_page_config(page_title=\"Streamlit Uploads Library\", layout=\"wide\")\ndefault_uploader = UploadFiles(save_location=\"assets\")\nexpander_uploader = UploadFiles(save_location=\"assets\", widget_type=\"expander\")\n```\n\n## Custom File Details\n\nA default set of basic file details is provided for each image within the library. Using class \ninheritance this can be overridden to create your own file details section if you wish to include \nmore information or different options.\n\n```\nimport streamlit as st\nfrom streamlit_uploads_library.library import Library\n\nclass CustomLibrary(Library):\n    def __init__(self, directory, file_extensions=(\".png\", \".jpg\", \".jpeg\"), image_alignment=\"center\", number_of_columns=5, show_details=True, uid=\"custom\"):\n        self.directory = directory\n        self.file_extensions = file_extensions\n        self.image_alignment = image_alignment\n        self.number_of_columns = number_of_columns\n        self.show_details = show_details\n        self.uid = uid\n        super(CustomLibrary, self).__init__(self.directory, self.file_extensions, self.image_alignment, self.number_of_columns, self.show_details, self.uid)\n\n    def create_details(_self, img, filename_idx, uid):\n        # Your details section code here\n```\n\n## Caching\n\nStreamlit Uploads Library makes use of the `st.cache_resource` decorator so the library and gallery \non this page will load from the cache instead of reloading the images each time the app is run. You \nwill probably want to clear your cache after uploading new files to your app, the file uploader view \nprovided by this package takes care of that for you but if you use your own file uploader and save \nfunction then to clear the cache you can use the `st.cache_resource.clear()` function provided by \nStreamlit.\n\n## Example App (Demo)\n\nTo run the example application provided in the repository:\n\n```bash\ngit clone https://github.com/hreikin/streamlit-uploads-library\ncd streamlit-uploads-library/\npython -m venv .venv\nsource .venv/bin/activate\npip install -r requirements.txt\nstreamlit run Home.py\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A simple library or gallery for Streamlit made from widgets.",
    "version": "0.1.4",
    "split_keywords": [
        "streamlit",
        "uploads",
        "library",
        "gallery",
        "widgets"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b4ae10b181ee6f96f8d87e384c45e774528f04ac59461e062b13e959386785a0",
                "md5": "6aea39c50c8a05df4c28b007f75268f2",
                "sha256": "0435348f096f766754572dc898e7408ee5bb2468c5435c57c57954ccd9885e5f"
            },
            "downloads": -1,
            "filename": "streamlit_uploads_library-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6aea39c50c8a05df4c28b007f75268f2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10290,
            "upload_time": "2023-04-01T08:40:47",
            "upload_time_iso_8601": "2023-04-01T08:40:47.890835Z",
            "url": "https://files.pythonhosted.org/packages/b4/ae/10b181ee6f96f8d87e384c45e774528f04ac59461e062b13e959386785a0/streamlit_uploads_library-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "39d64495b9a600b1eb0f264927b997c259dd9b0e70be08c402b35465d8f3bc99",
                "md5": "561260fa39a5074c4f268fc237b5b226",
                "sha256": "83481deed6fab85feb7b4823efe41c6dcaff9eae30847ceb1cf9eefc9ce384d0"
            },
            "downloads": -1,
            "filename": "streamlit_uploads_library-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "561260fa39a5074c4f268fc237b5b226",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8634,
            "upload_time": "2023-04-01T08:40:49",
            "upload_time_iso_8601": "2023-04-01T08:40:49.498899Z",
            "url": "https://files.pythonhosted.org/packages/39/d6/4495b9a600b1eb0f264927b997c259dd9b0e70be08c402b35465d8f3bc99/streamlit_uploads_library-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-01 08:40:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "hreikin",
    "github_project": "streamlit-uploads-library",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "streamlit-uploads-library"
}
        
Elapsed time: 0.09543s