Build and share a demo
What you’ll learn
Section titled “What you’ll learn”This lesson opens Phase 3 by shipping: turning a model in a notebook into a browser app anyone can try. You will use Gradio to build and share a demo with no frontend code. The source curriculum is the Hugging Face LLM Course, Chapter 9, freely available and Apache-2.0 licensed at huggingface.co/learn/llm-course/chapter9.
You will build a demo with gr.Interface(fn, inputs, outputs) and launch(); wrap a real model by putting your inference code in the function; match Gradio components (gr.Textbox, gr.Image, and more) to your model’s inputs and outputs; share a demo with a temporary public link via launch(share=True); and publish it permanently on Hugging Face Spaces with an app.py and requirements.txt.
Where this fits
Section titled “Where this fits”This is lesson 9 of 12, the first lesson of Phase 3 (demos and the LLM frontier). Phase 1 and 2 built and trained models; this lesson makes them usable by other people. It plugs directly into lesson 2 (the pipeline you wrap) and lesson 4 (Spaces share the Hub and Git-based publishing). The rest of Phase 3 turns to the LLM-specific topics.
Before you start
Section titled “Before you start”Prerequisites: lesson 2 of this track (loading a model with pipeline), since the demo’s function is just that inference call. Lesson 4 (the Hub) helps for the Spaces section. You should be comfortable writing a short Python function. Install with pip install gradio transformers. A free Hugging Face account is needed only for the permanent-hosting (Spaces) part.
About the math
Section titled “About the math”None. This is a shipping lesson: wrapping inference in a UI and publishing it. The code is short Gradio calls, and there is nothing to derive; the one idea is matching components to a model’s inputs and outputs.
By the end, you’ll be able to
Section titled “By the end, you’ll be able to”The single capability this lesson builds: wrap a model in a simple, shareable web demo with Gradio and publish it. Concretely, you will be able to:
- Build a demo with
gr.Interface(fn, inputs, outputs)andlaunch() - Wrap a model by putting inference code in the
fn - Match Gradio components to a model’s inputs and outputs
- Share a demo with a temporary public link via
launch(share=True) - Publish a demo permanently on Hugging Face Spaces
Time and difficulty
Section titled “Time and difficulty”- Read time: about 10 minutes
- Practice time: about 12 minutes (build a model demo, customize it, and get a share link, plus flashcards)
- Difficulty: standard (short code, no math; the new idea is the component-to-model mapping)