GenAI Exam Prep
Home Mock Exam
⚑ LECTURE 17

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.

Syllabus topics 66–70 ⏱ ~22 min read 12 practice questions

17.1 GenAI Rapid Prototyping

πŸ”‘ The core problem Your Python ML code works in the terminal β€” but a script is useless to non-technical users. Stakeholders want a clickable demo; teams want an interface. Rapid prototyping tools turn Python logic into professional, shareable web apps in hours β€” with no HTML, CSS or JavaScript.

Why rapid prototyping matters:

17.2 HTML/CSS Limitations

Why does traditional web development slow you down?

StepThe friction
HTML structureEven a simple form needs many tags, rules and browser-specific fixes
CSS stylingTime is spent fixing layouts and screen sizes instead of writing logic
Frontend–backend wiringConnecting Python to the screen means learning frameworks and handling HTTP requests
Deployment overheadYou 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

Streamlit β€” a Python library that turns plain Python scripts into interactive web apps. UI and logic live together in one Python file; each UI element is just a function call. No HTML, CSS or JavaScript needed.

Key features

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.

Python Β· a Streamlit app (app.py)
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!")
Terminal$ streamlit run app.py You can now view your Streamlit app in your browser. Local URL: http://localhost:8501

Common Streamlit elements

FunctionCreates
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
πŸ’‘ Tip β€” the sidebar Add .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

Gradio β€” a Python library that turns a single function into a web UI automatically. You define the inputs, outputs and the function; Gradio builds the interface. It is ML-native and ideal for quick model demos.

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.

Python Β· a Gradio app
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()
TerminalRunning on local URL: http://127.0.0.1:7860

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

StreamlitGradio
PhilosophyBuilds complete applicationsWraps a single function
Best forData dashboards, multi-page apps, internal toolsQuick ML model demos, stakeholder demos
Code amountMore β€” you compose the layoutMinimal β€” UI is auto-generated
StrengthCustom layouts, many components, workflowsML-native: handles images, predictions, confidence scores
πŸ”‘ Which tool to pick? Use Streamlit for data-exploration tools, dashboards with many components, custom layouts and multi-page internal business apps. Use Gradio when you just need to demo a single ML model/function quickly with minimal UI code.

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.

? Practice Questions

Streamlit/Gradio syntax and the choice between them are common questions.

MCQQ1Purpose

The main purpose of rapid prototyping tools like Streamlit is to:

  • A Replace Python entirely
  • B Turn Python logic into shareable web apps without HTML/CSS/JavaScript
  • C Train large neural networks faster
  • D Manage cloud servers
Answer: B

They let Python developers build clickable web apps in hours, skipping the entire frontend stack.

MCQQ2HTML/CSS

Which is a genuine limitation of building a UI with raw HTML/CSS?

  • A HTML cannot display text
  • B Time goes into layout/styling and frontend-backend wiring instead of logic
  • C CSS cannot change colours
  • D HTML cannot run in a browser
Answer: B

Raw web development drains time on tags, responsive layouts, request handling and deployment β€” a "simple page" becomes weeks of work.

MCQQ3Streamlit

How do you run a Streamlit app stored in app.py?

  • A python app.py
  • B streamlit run app.py
  • C run streamlit app.py
  • D app.py --streamlit
Answer: B

streamlit run app.py launches the app and opens it in a browser tab.

MCQQ4Streamlit widgets

Which Streamlit function creates a clickable button?

  • A st.title()
  • B st.text()
  • C st.button()
  • D st.metric()
Answer: C

st.button() creates a button and returns True on the run where it was clicked.

MCQQ5Reactivity

In Streamlit, what happens when a user interacts with a widget?

  • A Nothing until you manually refresh
  • B The whole script re-runs automatically
  • C The app crashes
  • D You must write a callback function
Answer: B

Streamlit's automatic reactivity re-runs the entire script on each interaction, so you do not manage events or callbacks for basic apps.

MCQQ6Gradio

Gradio's design philosophy is best described as:

  • A Building full multi-page applications
  • B Wrapping a single Python function into a web UI
  • C Managing databases
  • D Training models from scratch
Answer: B

Gradio is function-first: provide a function plus its input/output types and it auto-generates the interface β€” ideal for quick ML demos.

MCQQ7Gradio launch

Which Gradio method starts the local web app?

  • A .run()
  • B .start()
  • C .launch()
  • D .serve()
Answer: C

demo.launch() starts the Gradio app and opens it in the browser.

MCQQ8Choosing

You need a multi-component dashboard with custom layout and a sidebar of filters. Best tool?

  • A Streamlit
  • B Gradio
  • C Raw HTML/CSS
  • D A Jupyter notebook
Answer: A

Streamlit suits full applications with multiple components, custom layouts and sidebars. Gradio is better for wrapping a single function quickly.

CodingQ9Streamlit app

Write a Streamlit app that takes a number from the user and displays its square when a button is clicked.

Solution
Python Β· app.py
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.

CodingQ10Gradio app

Write a Gradio app that reverses a string the user types in.

Solution
Python
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.

Short AnswerQ11Concept

Give two reasons rapid prototyping tools are valuable for an ML engineer.

Model answer

(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.

Short AnswerQ12Streamlit vs Gradio

When would you choose Gradio over Streamlit?

Model answer

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.

🎯 Lecture 17 β€” must-remember Rapid prototyping = Python logic β†’ web app in hours, no HTML/CSS/JS. HTML/CSS friction: tags, styling, frontend-backend wiring, deployment. Streamlit: full apps, run with 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.