Ibnovate Course 3 · The Future Builders
⏱ 75 minLive session

Session 14 — Deploy Your AI

Duration: 75 min · Format: live online

What you'll learn: by the end, you can turn a model from a notebook into a real web app anyone can use — building the interface with Gradio and publishing it live on Hugging Face Spaces, so you walk away with a link you can put in a message, an email, or a portfolio.

Soft skill focus — Confidence & presenting

Today you'll also grow Confidence & presenting. There's a huge difference between "I trained a model" and "here — try it yourself" with a link. The moment strangers can click and use your work, you're no longer a student doing exercises; you're a builder who ships. That shift is mostly confidence — the willingness to put your work in front of the world.

What you'll need

Hook

Right now your model lives in a notebook. To use it, someone would have to open Colab, run every cell, and understand Python. That's not a product — that's a science experiment on your desk.

Deployment is the bridge from "it works on my machine" to "anyone can use it, anywhere". And here's the beautiful part: with modern tools, that bridge is about fifteen lines of code and one upload. Today you cross it — you turn your model into a website with buttons and boxes that your grandmother could use.

From files to a live app anyone can visit: your model, deployed

Teach — What deployment actually is

Deploying a model means three things come together and run somewhere other people can reach:

  1. The model — your trained thing (the weights) that turns inputs into predictions.
  2. The interface — the boxes, sliders and buttons a human uses to give inputs and see the answer, with no code.
  3. The host — a computer on the internet that runs it 24/7 so the app is always at a link.

In a company, teams spend serious effort on all three. For you, Gradio handles the interface in a few lines, and Hugging Face Spaces is a free host. That combination is genuinely how many real ML demos ship today.

Teach — Gradio in one idea

Gradio's whole trick is this: you write a normal Python function, and Gradio wraps a web UI around it automatically.

That's it. No HTML, no JavaScript, no web-server code. Your function is the app.

⚠ Watch out: the function you hand to Gradio must be self-contained — it has to load or hold the model and do everything needed to produce an answer from raw inputs. A common failure is a function that relies on a variable defined in some other notebook cell that won't exist on the host. Test it by imagining the function is the only thing that runs.

Activity — Build and deploy a live app

You'll wrap last session's survival model in a Gradio app, then publish it. Work in Colab first to test, then move to Spaces.

Step 1 — Install and import Gradio in your Colab:

!pip install gradio -q
import gradio as gr

Step 2 — Write the prediction function. It takes human-friendly inputs and returns a friendly answer (assumes model is your trained classifier from last session):

def predict_survival(pclass, sex, age, fare):
    sex_num = 0 if sex == "male" else 1
    features = [[pclass, sex_num, age, fare]]
    prob = model.predict_proba(features)[0][1]   # chance of survival
    return f"Survival chance: {prob:.0%}"

Step 3 — Describe the interface — one input per function argument, in order:

demo = gr.Interface(
    fn=predict_survival,
    inputs=[
        gr.Dropdown([1, 2, 3], label="Passenger class"),
        gr.Radio(["male", "female"], label="Sex"),
        gr.Slider(0, 80, value=30, label="Age"),
        gr.Slider(0, 300, value=30, label="Fare paid"),
    ],
    outputs="text",
    title="Titanic Survival Predictor",
    description="Enter passenger details to estimate survival chance.",
)

demo.launch()

Now try it:

  1. Run it. Gradio shows a working app right inside Colab — move the sliders, pick "female" vs "male", and watch the prediction change live.
  2. Set a young female first-class passenger, then an older male third-class one. Does the app reflect what your model learned last session?

Step 4 — Publish to the world. Go to huggingface.co/new-space, choose Gradio as the Space type, and create it. In the Space, add two files:

app.py            ← Steps 2–3 above, plus code that loads your saved model
requirements.txt  ← the libraries your app needs

Your requirements.txt is just a plain list:

gradio
scikit-learn
pandas

Save your trained model to a file first (import joblib; joblib.dump(model, "model.joblib")), upload that file to the Space too, and load it at the top of app.py with model = joblib.load("model.joblib"). Hugging Face builds it automatically — in a minute or two, your app is live at a public URL you can share with anyone.

Check yourself

  1. What three things must come together to deploy a model? → The model, an interface (the UI), and a host (a computer on the internet that runs it).
  2. What does Gradio do for you? → It wraps a web UI around a plain Python function — no HTML or JavaScript needed.
  3. Why must the model be saved to a file for Spaces? → Because the host runs app.py fresh; it can't see your Colab memory, so the model has to be saved and loaded from a file the Space can read.

Wrap-up

You just shipped. Your model went from cells only you could run to a website with a link anyone on Earth can open and use. That's the difference between a learner and a builder — and it's a link you can now put straight into your portfolio and university applications.

Tips & extra challenges

Vocabulary

Term Meaning
Deployment Making a model usable by others by running it on a reachable server
Gradio A Python library that builds a web UI around a function automatically
Hugging Face Spaces A free host that runs your app 24/7 at a public link
requirements.txt A file listing the libraries your app needs so the host can install them
Interface The buttons, sliders and boxes a human uses — no code required

Resources

Practice set

Practise on your own — work these easy → hard. Answers follow each arrow.

1. Name the piece. Sliders and a Submit button that a user clicks — which of the three deployment parts is that? → The interface (the UI).

2. Match the widget. A user needs to choose "male" or "female". Which Gradio input fits? → A gr.Radio (or gr.Dropdown) with those two choices.

3. Fix the file. Your Space crashes with ModuleNotFoundError: No module named 'sklearn'. What's missing? → scikit-learn is not in requirements.txt; add it and rebuild.

4. Explain the save. Why can't your Space just use the model variable from your Colab? → The host runs a fresh process with no access to Colab's memory; the model must be saved to a file and loaded in app.py.

5. Write the function (harder). Write a Gradio-ready function greet(name) that returns "Hello, <name>!". → def greet(name): return f"Hello, {name}!" (then gr.Interface(fn=greet, inputs="text", outputs="text").launch()).

6. Reason about hosting (harder). A friend says "my demo works in Colab, why deploy it?" Give one solid reason. → In Colab it only runs while your cell is running and only you can reach it; deployed on Spaces it runs 24/7 at a public link anyone can use.

Going deeper (optional)

Optional — for when you want your demo to feel like a real product.

Add a share link and cache examples. Two small touches make a big difference. First, demo.launch(share=True) in Colab gives you a temporary public URL instantly — handy for showing someone before you've published a full Space. Second, when you pass examples=, Gradio can pre-compute their outputs so the app feels instant on first load. Beyond Gradio, explore Streamlit (an alternative that gives you more control over page layout) — building the same demo in both and comparing teaches you a lot about the trade-off between "fast and automatic" (Gradio) and "flexible and custom" (Streamlit).

Common mistakes & fixes

What's next

Session 15 — Your University-Ready Portfolio: you now have deployed work worth showing off. Next you'll build the place that shows it off — a clean GitHub with strong READMEs and a sharp write-up of each project, so a university admissions officer or employer instantly sees what you can do.

Ibnovate · Build · Innovate
Type to search · Esc to close
Welcome back
Sign in to continue building.
Accounts are created by Ibnovate — ask your instructor for your login.
🔒