Walkthrough: Add a Custom Application#
The base environments for NVIDIA AI Workbench come with a selection of applications already built-in, such as JupyterLab IDE and Tensorboard. For more information, see AI Workbench Applications.
AI Workbench enables you to add your own custom applications to your projects to use as part of your development workflows. This documentation walks you through the process to add a simple, custom Gradio application to a new project in AI Workbench. The application is similar to the quickstart example provided by Gradio.
In this quickstart, you perform the following tasks:
Prerequisites#
Before you complete the steps in this walkthrough, you need the following:
NVIDIA AI Workbench is installed on your local system. For more information, see Install AI Workbench.
A basic test project. If you don’t have one, see Basic Quickstart.
Configure the Environment#
Use the following procedure to add the gradio
package to your project.
In AI Workbench, navigate to Environment > Packages > Add.
Select pip as the package manager, type
gradio
for the package name, and then click Add.Click Submit.
AI Workbench auto-detects that the container environment has changed and prompts you to rebuild your project. Click Start Build.
The project starts rebuilding. To view progress in real time, click Output in the status bar.
Develop the Application#
After you add Gradio to your project, you can build a simple Gradio application.
Near the top of the AI Workbench window, click Open JupyterLab.
JupyterLab opens in your default browser ready for you to start working.
Navigate to the
code
directory, click Python File, and create a python file namedapp.py
.In the
app.py
file, write the following code to create a gradio application to run on port 8080.1import gradio as gr 2import os 3 4def greet(name, intensity): 5 return "Hello, " + name + "!" * int(intensity) 6 7demo = gr.Interface( 8 fn=greet, 9 inputs=["text", "slider"], 10 outputs=["text"], 11) 12 13proxy_prefix = os.environ.get("PROXY_PREFIX") 14demo.launch(server_name="0.0.0.0", server_port=8080, root_path=proxy_prefix)
Note
This code snippet uses the AI Workbench
PROXY_PREFIX
environment variable. This environment variable is automatically injected by AI Workbench when starting an app. The variable indicates the prefix on which the app is hosted. For some web applications that do not use relative routing for requests and assets, you often need to set some configuration to tell the application the prefix (other than just /).
Add the Application to Your Project#
Use the following procedure to add the Gradio application to AI Workbench.
In AI Workbench, navigate to Environment > Applications > Add. The Add Applications window appears.
In the Add Applications window, click Create a custom app. The Add Application window appears.
In the Add Application window, specify the following information, and then click Next.
Name —
simple-gradio
Class —
Web Application
Icon URL — Leave blank
Start Command —
cd /project/code && PROXY_PREFIX=$PROXY_PREFIX python3 app.py
Health Check Command —
curl -f "http://localhost:8080/"
Stop Command —
pkill -f '^python3 app.py'
Auto Launch — Select the checkbox
Port —
8080
URL —
http://localhost:8080/
URL Command — Leave blank
User Message — Leave blank
AI Workbench adds the application and prompts you to restart your environment. Click Restart.
Launch the Application#
The application is now built into the project automation and is ready to be launched.
In AI Workbench, navigate to Environment > Applications.
In the Applications pane click the new simple-gradio application to launch it.
The new application opens automatically in a new browser window.
Close the application by toggling the application off in the Applications pane, or by clicking Stop Environment.
Next Steps#
Do another walkthrough
See how to work with example projects on Github
Explore the NVIDIA Developer Forum