Gradio.Net 开发指南 -- 提示与警告
目录提示与警告上一篇Gradio.Net (https://github.com/feiyun0112/Gradio.Net)是一个开源的 .NET 库它是 Gradio 的 .NET 移植版本允许你为机器学习模型、API 或任何 C# 函数快速构建演示或 Web 应用程序无需任何 JavaScript、CSS 或 Web 开发经验提示与警告您可能希望向用户显示提示或警告信息。在 Gradio.Net 中有三种方式可以实现‎‎throw new Gradio.Net.Core.Exceptions.Error(自定义消息)停止函数执行并向用户显示错误弹窗。‎‎gr.Warning(自定义消息)在函数继续执行的同时立即显示警告弹窗。‎‎gr.Info(自定义消息)在函数继续执行的同时立即显示信息弹窗。gr.Info()和gr.Warning()的唯一区别是弹窗的颜色。using Gradio.Net; using GradioError Gradio.Net.Core.Exceptions.Error; string StartProcess(string name) { gr.Info(Starting process); if (string.IsNullOrEmpty(name)) { gr.Warning(Name is empty, using default.); name World; } // 模拟处理 Thread.Sleep(500); bool success name.Length 20; if (!success) { throw gr.Error(Process failed: name is too long (max 20 characters).); } return $Hello, {name}!; } using var demo gr.Interface( fn: StartProcess, inputs: gr.Textbox(label: Name), outputs: gr.Textbox(label: Result)); await demo.Launch();注意Gradio.Net.Core.Exceptions.Error是一个必须throw的异常而gr.Warning()和gr.Info()是直接调用的方法。引入地址