How to Deploy Machine Learning Models with Streamlit

5 Ways AI Is Changing Data Analytics in 2026

You’ve trained your machine learning model, now what?
Building a great model is only half the job; getting it into the hands of users is where the real impact happens. That’s where Streamlit comes in. Streamlit allows data scientists and developers to turn models into interactive web apps in just a few lines of Python (no web development experience needed).

Whether you’re sharing a predictive model, a data visualization dashboard, or an AI-powered tool, Streamlit makes deployment simple, fast, and visually appealing. In this tutorial, you’ll learn how to deploy your first ML model step-by-step.

What is Streamlit?

Streamlit is an open-source Python library designed for building data apps quickly and easily. It bridges the gap between your Jupyter Notebook and a user-friendly web interface allowing anyone to interact with your model using sliders, buttons, and input fields.

Key benefits of Streamlit:

  • No HTML, CSS, or JavaScript required
  • Fast to build and iterate
  • Ideal for ML model deployment and data visualization
  • Easy cloud hosting (Streamlit Community Cloud, Hugging Face Spaces, etc.)

Step 1: Install Streamlit

Run this in your terminal or notebook:

pip install streamlit

To verify it’s working, run:

streamlit hello

This opens an example app in your browser.

Step 2: Prepare Your Model

Let’s say you’ve trained a simple regression model using Scikit-learn:

import pickle
from sklearn.linear_model import LinearRegression

# Example training
X = [[1], [2], [3], [4]]
y = [2, 4, 6, 8]

model = LinearRegression()
model.fit(X, y)

# Save model
pickle.dump(model, open('model.pkl', 'wb'))

Step 3: Build the Streamlit App

Create a new file called app.py:

import streamlit as st
import pickle

# Load model
model = pickle.load(open('model.pkl', 'rb'))

st.title("Simple ML Model Deployment")
st.write("Predict outcomes instantly with your trained model!")

# Input from user
value = st.number_input("Enter a number:", min_value=0.0)

if st.button("Predict"):
    prediction = model.predict([[value]])
    st.success(f"Predicted result: {prediction[0]:.2f}")

Run your app:

streamlit run app.py

Step 4: Deploy Online

You can easily host your app using:

Just upload your files (app.py, model.pkl, and requirements.txt) to GitHub and connect it to one of these platforms.

Step 5: Share Your App

Once deployed, share your app link and anyone can interact with your model from their browser! It’s perfect for portfolio projects, client demos, and product prototypes.

You Can Also

  • Use st.cache_data() or st.cache_resource() to speed up your app.
  • Add visualizations using Matplotlib or Plotly.
  • Include custom CSS for branded designs.
  • For advanced users: combine Streamlit with APIs or database connections.

FAQ

Q1. Is Streamlit free to use?

Yes! Streamlit is open-source and free. You can also deploy apps for free on Streamlit Community Cloud.

Q2. Can I deploy deep learning models?

Absolutely. You can load TensorFlow, PyTorch, or Keras models in your app and deploy them like any other Python model.

Q3. Do I need web development skills?

No, Streamlit takes care of the UI for you. If you can write Python, you can deploy apps.

Q4. How do I share private apps?

Use paid hosting (like Render or AWS) or set up authentication in your app.

Q5. What’s the difference between Streamlit and Flask?

Streamlit is simpler and focused on data apps. Flask is a general-purpose web framework that requires more coding for UI.

Deploying machine learning models doesn’t have to be complex. With Streamlit, you can go from model to interactive web app in minutes and no front-end experience required.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top