For more information, see the Guides.
Gradio for .NET – a port of Gradio, an open-source Python package that allows you to quickly build a demo or web application for your machine learning model, API, or any arbitrary Python function. No JavaScript, CSS, or web hosting experience needed!
It just takes a few lines of .NET code to create a beautiful demo like the one above, so let's get started 💫
-
- Create an ASP.NET Core Web API project.
-
- Install NuGet package Gradio.Net.
-
- Enter the sample code in
Program.cs:
- Enter the sample code in
using Gradio.Net;
string Greet(string name, double intensity)
{
return "Hello, " + name + "!" + new string('!', (int)intensity - 1);
}
var demo = gr.Interface(
fn: Greet,
inputs: new object[] { "text", gr.Slider(value: 2, minimum: 1, maximum: 10, step: 1) },
outputs: new[] { "text" }
);
await demo.Launch();gr.Interface wraps any C# function into a UI in seconds — no layout code required.
using Gradio.Net;
await (await CreateBlocks()).Launch();
async Task<Blocks> CreateBlocks()
{
using (var blocks = gr.Blocks())
{
gr.Markdown("Start typing below and then click **Run** to see the output.");
Textbox input, output;
using (gr.Row())
{
input = gr.Textbox(placeholder: "What is your name?");
output = gr.Textbox();
}
var btn = gr.Button("Run");
btn.Click(
fn: new Func<string, (string, string)>(name => ($"Welcome to Gradio.Net, {name}!", "")),
inputs: new[] { input },
outputs: new[] { output, input });
return blocks;
}
}That's All 🎉🎉🎉
Use the AddGradio and UseGradio extension methods:
using Gradio.Net;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddGradio();
var app = builder.Build();
app.UseGradio(await CreateBlocks());
app.Run();
async Task<Blocks> CreateBlocks()
{
using (var blocks = gr.Blocks())
{
gr.Markdown("# My Gradio App");
Textbox input, output;
using (gr.Row())
{
input = gr.Textbox(placeholder: "What is your name?");
output = gr.Textbox();
}
var btn = gr.Button("Run");
btn.Click(
fn: new Func<string, (string, string)>(name => ($"Welcome to Gradio.Net, {name}!", "")),
inputs: new[] { input },
outputs: new[] { output, input });
return blocks;
}
}You can also use gr.Interface with app.UseGradio:
using Gradio.Net;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddGradio();
var app = builder.Build();
string Greet(string name, double intensity)
{
return "Hello, " + name + "!" + new string('!', (int)intensity - 1);
}
var demo = gr.Interface(
fn: Greet,
inputs: new object[] { "text", gr.Slider(value: 2, minimum: 1, maximum: 10, step: 1) },
outputs: new[] { "text" }
);
app.UseGradio(await demo.BuildBlocks());
app.Run();| Source Code | Demo Image |
|---|---|
| Layout | ![]() |
| Form | ![]() |
| Media | ![]() |
| Chatbot | ![]() |
| Progress | ![]() |
| Theme | ![]() |






