Rapid Prototyping Tools
Turn Python logic into a shareable web app in hours β no HTML, CSS or JavaScript. Learn why traditional web dev is slow, and how Streamlit and Gradio fix it.
In this lecture
17.1 GenAI Rapid Prototyping
Why rapid prototyping matters:
- Speed wins β build and test ideas in hours, not weeks.
- Ideas need testing β validate assumptions early, gather feedback fast.
- Democratising access β turn Python logic into tools non-technical teams can actually use.
17.2 HTML/CSS Limitations
Why does traditional web development slow you down?
| Step | The friction |
|---|---|
| HTML structure | Even a simple form needs many tags, rules and browser-specific fixes |
| CSS styling | Time is spent fixing layouts and screen sizes instead of writing logic |
| Frontendβbackend wiring | Connecting Python to the screen means learning frameworks and handling HTTP requests |
| Deployment overhead | You must manage servers, domains, security and upkeep |
What begins as a "simple web page" often becomes weeks of work. That is exactly why rapid prototyping tools exist β they let a Python developer skip the whole frontend stack.
17.3 Introduction to Streamlit
Key features
- Python-only β if you can write Python, you can build a web app.
- Automatic reactivity β the script re-runs automatically whenever a user interacts; no event/callback management.
- Built-in professional design β clean, responsive UI by default.
Running a Streamlit app
Write a file app.py, then in the terminal run streamlit run app.py β a browser tab opens with your live app.
import streamlit as st
# Text hierarchy
st.title("Text Analyser")
st.header("Paste your text below")
# Input widget - returns the typed string
text = st.text_area("Enter text:")
# A button triggers an action when clicked
if st.button("Analyse"):
word_count = len(text.split())
st.metric("Word count", word_count)
st.success("Analysis complete!")
Common Streamlit elements
| Function | Creates |
|---|---|
st.title() / st.header() / st.subheader() / st.text() | Text in a size hierarchy |
st.text_input() / st.text_area() | Text boxes (return the typed string) |
st.button() | A button β returns True when clicked |
st.checkbox() / st.radio() / st.selectbox() | On/off, pick-one, dropdown |
st.success() / st.warning() / st.error() / st.info() | Coloured feedback boxes |
st.sidebar.<...> | Puts a widget in the left sidebar |
st.metric() | A big number display for key results |
.sidebar to any command (e.g. st.sidebar.header(...)) to place it in the left sidebar β perfect for controls, filters and navigation, keeping the main area clean.
17.4 Introduction to Gradio
The Gradio philosophy β function-first
Streamlit builds complete applications. Gradio wraps a single function: you provide a Python function plus its input and output types, and Gradio generates the interface. It handles images, text and numbers easily β built specifically for ML demos.
import gradio as gr
# Step 1: a normal Python function
def greet(name):
return f"Hello, {name}! Welcome to GenAI."
# Step 2: tell Gradio the inputs and outputs
demo = gr.Interface(
fn=greet,
inputs="text",
outputs="text"
)
# Step 3: launch - opens a local web app
demo.launch()
Three steps: (1) write a normal Python function, (2) describe its inputs/outputs to gr.Interface, (3) call .launch() β Gradio builds the UI for you.
17.5 Streamlit vs Gradio
| Streamlit | Gradio | |
|---|---|---|
| Philosophy | Builds complete applications | Wraps a single function |
| Best for | Data dashboards, multi-page apps, internal tools | Quick ML model demos, stakeholder demos |
| Code amount | More β you compose the layout | Minimal β UI is auto-generated |
| Strength | Custom layouts, many components, workflows | ML-native: handles images, predictions, confidence scores |
What you can build
Internal data tools, text-analysis apps (sentiment, readability), ML model demos, GenAI summarisers, shareable prototypes, business calculators β all in hours, in pure Python.
Streamlit/Gradio syntax and the choice between them are common questions.
The main purpose of rapid prototyping tools like Streamlit is to:
They let Python developers build clickable web apps in hours, skipping the entire frontend stack.
Which is a genuine limitation of building a UI with raw HTML/CSS?
Raw web development drains time on tags, responsive layouts, request handling and deployment β a "simple page" becomes weeks of work.
How do you run a Streamlit app stored in app.py?
streamlit run app.py launches the app and opens it in a browser tab.
Which Streamlit function creates a clickable button?
st.button() creates a button and returns True on the run where it was clicked.
In Streamlit, what happens when a user interacts with a widget?
Streamlit's automatic reactivity re-runs the entire script on each interaction, so you do not manage events or callbacks for basic apps.
Gradio's design philosophy is best described as:
Gradio is function-first: provide a function plus its input/output types and it auto-generates the interface β ideal for quick ML demos.
Which Gradio method starts the local web app?
demo.launch() starts the Gradio app and opens it in the browser.
You need a multi-component dashboard with custom layout and a sidebar of filters. Best tool?
Streamlit suits full applications with multiple components, custom layouts and sidebars. Gradio is better for wrapping a single function quickly.
Write a Streamlit app that takes a number from the user and displays its square when a button is clicked.
import streamlit as st
st.title("Square Calculator")
num = st.number_input("Enter a number:", value=0)
if st.button("Calculate"):
st.success(f"The square of {num} is {num ** 2}")
Run with streamlit run app.py. The script re-runs on each interaction, so when the button returns True the result is shown.
Write a Gradio app that reverses a string the user types in.
import gradio as gr
def reverse(text):
return text[::-1]
demo = gr.Interface(fn=reverse,
inputs="text",
outputs="text")
demo.launch()
The function is plain Python; gr.Interface + .launch() build and serve the UI automatically.
Give two reasons rapid prototyping tools are valuable for an ML engineer.
(1) Speed β they convert a working Python script into a clickable web app in hours instead of weeks, so ideas can be tested and feedback gathered fast. (2) Accessibility β they let non-technical stakeholders and teammates actually use a model through a friendly interface, without the engineer needing to learn HTML, CSS, JavaScript or manage servers.
When would you choose Gradio over Streamlit?
Choose Gradio when you just need to demo a single ML model or function quickly with minimal UI code β for example wrapping a trained classifier so stakeholders can test inputs and see predictions/confidence scores. Choose Streamlit for fuller data applications with dashboards, custom layouts, sidebars and multiple pages.
streamlit run app.py, auto-reactive, widgets st.button/text_input/selectbox, .sidebar. Gradio: wraps a single function, gr.Interface(fn, inputs, outputs) + .launch(), ML-native.