User Guide (Latest)
User Guide (Latest)

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.

Before you complete the steps in this walkthrough, you need the following:

Use the following procedure to add the gradio package to your project.

  1. In AI Workbench, navigate to Environment > Packages > Add.

    quickstart-app-5.png

  2. Select pip as the package manager, type gradio for the package name, and then click Add.

  3. Click Submit.

  4. 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.

After you add Gradio to your project, you can build a simple Gradio application.

  1. Near the top of the AI Workbench window, click Open JupyterLab.

    JupyterLab opens in your default browser ready for you to start working.

  2. Navigate to the code directory, click Python File, and create a python file named app.py.

    quickstart-app-11.png

  3. In the app.py file, write the following code to create a gradio application to run on port 8080.

    Copy
    Copied!
                

    import gradio as gr import os def greet(name, intensity): return "Hello, " + name + "!" * int(intensity) demo = gr.Interface( fn=greet, inputs=["text", "slider"], outputs=["text"], ) proxy_prefix = os.environ.get("PROXY_PREFIX") demo.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 /).

Use the following procedure to add the Gradio application to AI Workbench.

  1. In AI Workbench, navigate to Environment > Applications > Add. The Add Applications window appears.

    quickstart-app-13.png

  2. In the Add Applications window, click Create a custom app. The Add Application window appears.

    custom_app.png

  3. In the Add Application window, specify the following information, and then click Next.

    1. Namesimple-gradio

    2. ClassWeb Application

    3. Icon URL — Leave blank

    4. Start Commandcd /project/code && PROXY_PREFIX=$PROXY_PREFIX python3 app.py

    5. Health Check Commandcurl -f "http://localhost:8080/"

    6. Stop Commandpkill -f '^python3 app.py'

    7. Auto Launch — Select the checkbox

    8. Port8080

    9. URLhttp://localhost:8080/

    10. URL Command — Leave blank

    11. User Message — Leave blank

  4. AI Workbench adds the application and prompts you to restart your environment. Click Restart.

The application is now built into the project automation and is ready to be launched.

  1. In AI Workbench, navigate to Environment > Applications.

  2. In the Applications pane click the new simple-gradio application to launch it.

    The new application opens automatically in a new browser window.

    quickstart-app-17.png

  3. Close the application by toggling the application off in the Applications pane, or by clicking Stop Environment.

Previous Walkthrough: Customize Your Environment (CLI)
Next Advanced Walkthrough: Hybrid RAG
© Copyright © 2024, NVIDIA Corporation. Last updated on Jul 26, 2024.