Skip to content

Deploying ML Models to Streamlit

What Streamlit is

Streamlit turns Python scripts into web apps.

It’s great for:

  • demos
  • internal tools
  • quick validation with stakeholders

Minimal Streamlit inference app

app.py (Streamlit)
# Requires: streamlit, joblib
import streamlit as st
import joblib
 
model = joblib.load("model.joblib")
 
st.title("ML Prediction Demo")
 
age = st.number_input("Age", min_value=0, max_value=120, value=30)
income = st.number_input("Income", min_value=0.0, value=50000.0)
city = st.text_input("City", value="Pune")
plan = st.selectbox("Plan", ["Free", "Pro", "Enterprise"])
 
if st.button("Predict"):
    X = [{"age": age, "income": income, "city": city, "plan": plan}]
    pred = model.predict(X)[0]
    st.write("Prediction:", pred)
app.py (Streamlit)
# Requires: streamlit, joblib
import streamlit as st
import joblib
 
model = joblib.load("model.joblib")
 
st.title("ML Prediction Demo")
 
age = st.number_input("Age", min_value=0, max_value=120, value=30)
income = st.number_input("Income", min_value=0.0, value=50000.0)
city = st.text_input("City", value="Pune")
plan = st.selectbox("Plan", ["Free", "Pro", "Enterprise"])
 
if st.button("Predict"):
    X = [{"age": age, "income": income, "city": city, "plan": plan}]
    pred = model.predict(X)[0]
    st.write("Prediction:", pred)

Deployment options

  • Streamlit Community Cloud
  • Docker + any cloud VM
  • internal server

Mini-checkpoint

When would you prefer Streamlit over an API?

  • when you need a user-facing demo UI quickly.

If this helped you, consider buying me a coffee β˜•

Buy me a coffee

Was this page helpful?

Let us know how we did