Skip to content

Rapid Prototyping for AI: How to Demo and Validate Early

One of the most powerful aspects of working in AI today is the ability to go from idea to prototype in hours—not weeks. But ideas and prototypes don’t gain traction in isolation. They need to be tested, shared, and improved based on real feedback. If you’ve been following the 100 Days of AI series, you’ll notice a recurring theme: most posts include a hands-on experiment or a simple proof-of-concept demo. These experiments help validate what’s technically possible. But the natural next step is this: how do you turn these into demos you can share, without spinning up a full product stack?

In this post, we’ll walk through how to wrap a simple AI experiment into a shareable demo using Gradio, a Python library that takes care of the UI layer so you can focus on what matters—your model.

Why You Need Fast Demos

Imagine you’ve built an AI app that takes in long-form text and returns a summary. You want to test it with real users, get feedback, and iterate. Traditionally, this would require:

  • Coding a user interface from scratch
  • Choosing and integrating a web stack (frontend, backend, hosting)
  • Managing deployment and scalability

Even with starter templates and no-code tools, it’s overkill for early testing. This is where Gradio comes in. It lets you generate a web-based interface around your AI logic with just a few lines of code—no frontend knowledge needed.

What is Gradio?

Gradio is a Python library that allows you to build and share demos of machine learning models via simple web interfaces. It abstracts away the complexity of web development so that AI developers can focus on model behavior rather than frontend mechanics.

You can define input/output components, wire them up to your model logic, and launch a demo—all in a single script. Best of all, Gradio provides a public shareable URL so others can try your app without any setup.

Let’s walk through an example. We’ll build a demo that takes long-form text as input and returns a summary using Hugging Face’s distilbart-cnn-12-6 summarization model.

Step 1: Setup

Along with Gradio, we will use hugging face app so to follow along make sure you keep your hugging face api key handy. To get started lets load up the API key from .env file and add required python modules.

import os
import io
from IPython.display import Image, display, HTML
#from PIL import Image
import base64 
import openai

env_path = '../.env'
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv(env_path)) # read local .env file

hf_api_key = os.environ['HF_API_KEY']

Step 2: Define Summarization Function

The core logic of what we want to achieve is to send a long text to a model and get a summary of the text. We will define a function that takes in the long text as an input and calls a model on hugging face called distilbart. Here is the function to do this.

def get_completion(inputs, parameters=None, ENDPOINT_URL=os.environ['HF_API_SUMMARY_BASE']): 
    headers = {
      "Authorization": f"Bearer {hf_api_key}",
      "Content-Type": "application/json"
    }
    data = { "inputs": inputs }
    if parameters is not None:
        data.update({"parameters": parameters})
    response = requests.request("POST",
                                ENDPOINT_URL, headers=headers,
                                data=json.dumps(data)
                               )
    return json.loads(response.content.decode("utf-8"))

Step 3: Use Gradio to Demo Summarization App

The main way to interact with Gradio is through interface function. We need to pass a function and its corresponding inputs and outputs. Note that we defined a new function called summarize for this purpose. This function takes an input, which will be the long text which is to be summarized and the function will call the get_completion function from step 2 to get the summary of the input text and return that as the output. In the final line we are asking gradio to launch the demo of this app. By providing share=True we are telling gradio to create a public link that can be shared to others and also giving the server_port on which the local webhost should run on. In the below code we also customize the title, description and labels of input and output fields which you will notice in the out put.

import gradio as gr
def summarize(input):
    output = get_completion(input)
    return output[0]['summary_text']
    
gr.close_all()
demo = gr.Interface(fn=summarize, 
                    inputs=[gr.Textbox(label="Text to summarize", lines=6)],
                    outputs=[gr.Textbox(label="Result", lines=3)],
                    title="Text summarization with distilbart-cnn",
                    description="Summarize any text using the `shleifer/distilbart-cnn-12-6` model under the hood!"
                   )
demo.launch(share=True, server_port=int(os.environ['PORT1']))

Once you run this, here is what the output now looks like in your browser at http://127.0.0.1:<your port number>.

It is that easy to demo a project with Gradio. The beauty here is you as a developer didn’t have to come up with UI stack and go through with the complexity of learning that stack and taking it to production. Gradio does it for you.

Gradio offers different input and output types using which you can create more complex and interesting demos that can be easily shared. We will explore more demos with Gradio and other tools in the coming posts.

Why This Matters

With Gradio, you sidestep the need to build and deploy a full web application just to test an idea. That lowers the barrier to iteration, lets you test with real users faster, and keeps your focus on the model’s behavior—not the deployment mechanics.

Gradio supports a variety of input and output components (e.g., images, sliders, dropdowns) that allow you to prototype more sophisticated use cases. This makes it a powerful tool not just for personal experimentation but also for team demos, stakeholder reviews, and user testing.


Nataraj is a Senior Product Manager at Microsoft Azure and the Author at Startup Project, featuring insights about building the next generation of enterprise technology products & businesses.


Listen to the latest insights from leaders building the next generation products on Spotify, Apple, Substack and YouTube.