Generated with sparks and insights from 46 sources

img6

img7

img8

img9

img10

img11

Introduction

  • Streamlit is a Python open-source app framework that allows you to easily convert your data scripts into informative, clutter-free web applications.

  • Streamlit provides a front-end interface for visualizing data through interactive dashboards with an easy-to-use API.

  • Streamlit widgets represent various components in a typical interface that users can interact with, such as text fields and buttons.

  • Automatic widget inference in Streamlit involves creating widgets that automatically update based on user input or changes in the data.

  • Streamlit's caching mechanism can be used to load models once and avoid reloading them in a loop, improving efficiency.

  • Session state in Streamlit can be used to maintain widget states across different pages or sessions.

  • Streamlit supports integration with popular data science libraries like Numpy, Pandas, and Matplotlib, making it versatile for various applications.

Setting Up Streamlit [1]

  • Installation: Install Streamlit using the command pip install streamlit.

  • Virtual Environment: It is recommended to set up a virtual environment using virtualenv or virtualenvwrapper.

  • Testing: Test the installation by running streamlit hello to open a browser window with a sample app.

  • Compatibility: Streamlit is compatible with many commonly-used libraries for data science, such as Numpy, Pandas, and Matplotlib.

  • Documentation: Refer to Streamlit’s API reference for detailed information on its functionalities.

img6

img7

img8

img9

img10

img11

Creating Widgets [1]

  • Text Input: Use st.text_input to create text fields for user input.

  • File Uploader: Use st.sidebar.file_uploader to allow users to upload files for processing.

  • Slider: Use st.slider to create a slider widget for selecting values within a range.

  • Selectbox: Use st.selectbox to create a dropdown menu for selecting options.

  • Button: Use st.button to create a button that users can click to trigger actions.

img6

img7

img8

img9

Caching and Session State [2]

  • Caching: Use @st.cache_resource() to cache functions and avoid reloading models or data repeatedly.

  • Session State: Use st.session_state to store and manage the state of widgets across different pages or sessions.

  • Example: Cache a model loading function to improve efficiency and avoid reloading the model in a loop.

  • Clearing Cache: Use load_model.clear() to clear the cache and reload the model if needed.

  • Session State Example: Store a model in st.session_state to maintain its state across different user interactions.

img6

img7

img8

img9

img10

img11

Model Inference [1]

  • Model Loading: Load a pretrained model using libraries like TensorFlow or PyTorch.

  • Inference: Perform inference on input data and display the results using Streamlit widgets.

  • Example: Use st.text_input to input project secret and model key, and st.file_uploader to upload images for predictions.

  • Visualization: Display original and output images side-by-side with predictions overlaid.

  • JSON Output: Display the JSON output of predictions for detailed analysis.

img6

img7

img8

img9

img10

img11

Deployment Options [1]

  • Streamlit Community Cloud: Deploy your app directly via Streamlit’s Community Cloud.

  • GitHub Integration: Push your Streamlit app to a GitHub repository and deploy from there.

  • Cloud Providers: Deploy your app on cloud platforms like Google Cloud Platform, AWS, and Azure.

  • Heroku: Use Heroku for deploying your Streamlit app with ease.

  • Docker: Containerize your Streamlit app using Docker for consistent deployment across different environments.

img6

img7

img8

img9

img10

img11

Related Videos

<br><br>

<div class="-md-ext-youtube-widget"> { "title": "Streamlit Tutorial 3 - Working with Interactive Widgets of ...", "link": "https://www.youtube.com/watch?v=yMcUU_OiSVQ", "channel": { "name": ""}, "published_date": "Apr 23, 2024", "length": "" }</div>

<div class="-md-ext-youtube-widget"> { "title": "Inferencing Interface on ML Model | streamlit App", "link": "https://www.youtube.com/watch?v=mdgfwnesAdI", "channel": { "name": ""}, "published_date": "Jan 25, 2024", "length": "" }</div>

<div class="-md-ext-youtube-widget"> { "title": "How To Build A Machine Learning Application Using Streamlit ...", "link": "https://www.youtube.com/watch?v=eoH2NviL8cs", "channel": { "name": ""}, "published_date": "Feb 3, 2023", "length": "" }</div>