⭐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. Gradio for .NET – 基于 Gradio 的 .NET 移植,Gradio 是一个开源 Python 包,允许你为机器学习模型、API 或任何任意 Python 函数快速构建演示或 Web 应用程序。
static async Task<Output> change_models(Input input)
{
var models = Utils.config?.Models?.Select(x => x.Name).ToList();
if (models == null)
{
throw new Exception("Failed to fetch models from the server.");
}
string server = Textbox.Payload(input.Data[0]);
string model = Dropdown.Payload(input.Data[1]).Single();
if (server == "")
{
throw new Exception("Server URL cannot be empty.");
}
// 取得模型是第几个
var index = models.IndexOf(model);
if (index == -1)
{
throw new Exception("Model not found in the list of available models.");
}
if (Utils.config.Current == index)
{
// 没有切换模型
return gr.Output(gr.Dropdown(choices: models, value: model, interactive: true));
}
var res = await Utils.client.PutAsync($"{server}/models/{index}/switch", null);
// 请求失败
if (!res.IsSuccessStatusCode)
{
// 错误信息未返回
gr.Warning("Failed to switch model.");
//await Task.Delay(2000);
return gr.Output(gr.Dropdown(choices: models, value: models[Utils.config.Current], interactive: true));
}
Utils.config.Current = index;
return gr.Output(gr.Dropdown(choices: models, value: model, interactive: true));
}
执行消息框提示后,如果不加入
await Task.Delay(2000);
将直接不显示消息框,如下: