AI Hints
Home›Machine Learning Tutorial›Shipping Your Model
Machine Learning · Lesson 60 of 85

A Demo App in Minutes

Streamlit for machine learning.

⏱ 2 min read▶ Video at 2:07:35🎓 Free
Watch this lesson in the Machine Learning courseWatch on YouTube ↗Full Machine Learning course

The fastest way to win support for a project is to let people touch it. A live demo beats a hundred slides. In the past, that needed a web developer. Today, a tool called Streamlit lets you build one, with a few lines of Python.

A Demo App in Minutes
From the video: A Demo App in Minutes
  • A demo beats a hundred slides
  • It once needed a web developer
  • Now a few lines of Python

A valuation app

Here's a complete app. We load the model. Streamlit's title adds a heading. Each slider call draws a real slider on the page, and gives us its current value. We fill the remaining features with typical values. And metric shows the result in large text. That is it. Each time someone moves a slider, Streamlit reruns the script from the top, and the price updates live. Save this as app dot py, and run streamlit run app dot py.

app.pypython
import joblib
import pandas as pd
import streamlit as st

model = joblib.load("homeworth.joblib")

st.title("HomeWorth")
income = st.slider("Median income (tens of thousands)", 0.5, 15.0, 4.0)
age = st.slider("House age", 1, 52, 25)
rooms = st.slider("Average rooms", 1.0, 10.0, 5.0)

row = pd.DataFrame([{
    "MedInc": income, "HouseAge": age, "AveRooms": rooms, "AveBedrms": 1.0,
    "Population": 1400, "AveOccup": 3.0,
    "Latitude": 34.2, "Longitude": -118.4}])

st.metric("Estimated value", f"${model.predict(row)[0] * 100000:,.0f}")

What the sales team sees

The sales team now has a real tool in their browser. They drag the income slider, and the estimated value updates as they move. In a client meeting, they can ask, what if the house were newer? And see the answer right away. This one small app often does more to win support for machine learning in a company, than months of careful technical work.

Summary

An A P I for software, and a Streamlit app for people. Your model is out in the world. So the job is finished, right? Actually, this is where the real trouble begins. Models don't stay good. Next, why every model slowly dies.

Key takeaways
  • Demos win support
  • Streamlit reruns the script
  • Sliders, metrics, done
Next up: Why Models Decay — drift and monitoring