March 17th, 2022

Setting Up Your Local Machine for H2O AI Cloud Wave App Development

RSS icon RSS Category: H2O AI Cloud, Wave

This article is for users who would like to build H2O Wave apps and publish them in the App Store within the H2O AI Cloud (HAIC). We will walk through how to set up your local machine for HAIC Wave App development.

Instructions

Developing with Wave

H2O Wave is a framework for building frontends using only python or R. In this article we will specifically focus on how to set up your Python development environment. To learn more about how to get started writing Wave apps, once your environment is set up, check out this blog.

  • Step 1 – Decide where you want to write your applications
    • Maybe you love vi or a GUI-based text editor, but we recommend using an interactive development environment (IDE) for Python like PyCharm (the community version is fine!) or VS Code.
  • Step 2 – Install the Wave python library into your python environment using ./venv/bin/pip install h2o-wave==0.20.0 or conda install -c h2oai h2o-wave==0.20.0
    • Note: When developing projects, we recommend using a different virtual environment for each project rather than installing python libraries in your main environment. This allows you to easily manage different versions of python and libraries for each project that you are working on. You can create a new virtual environment called venv using python3 -m venv venv or, if you manage python using conda you can use conda create --name venv.
  • Step 3 – Create a file called app.py and add the below code.

    • Let’s talk about how this code works:
      • Line 1: import the functionalities we need from the Wave library
      • Line 4: tell the app how users will access it, in this case, our app will be at http://<YOUR_DOMAIN>:10101/demo
      • Line 5: create the function that will handle all user requests including the first time someone comes to the app or any time any user clicks a button. Async just means we can have multiple users interact with our app at the same time without having to wait for each other
      • Line 7: On our page (demo) we will create a card called my_form_card which is a UI template from the Wave library called a Form Card – this card is ideal for showing objects like dropdown, buttons, and text to end-users. There are 50+ different types of cards for showing different information to your end-users
      • Line 8: Each card has a box attribute that tells the card where on the screen to go. Our form starts in the top (1 1 -1 -1), left-hand (1 1 -1 -1) corner and takes the full available vertical height (1 1 -1 -1) and the full available horizontal width (1 1 -1 -1)
      • Line 9: Each card as additional other attributes, form cards require a list of other UI elements to show on the screen
      • Line 10: We will use a text element from the Wave library to put some text in our form card
      • Line 14: We save all of our UI changes to the Wave server so that end users can see them. The await is related to this being a multi-user, interactive app
  • Step 4 – Run your Wave code using a terminal from your computer or your IDE: ./venv/bin/wave run app.py
    • Note: This article suggested you use version 0.20.0+ of H2O Wave. If you are using an older version of the Wave library, please see this guide for additional steps in running your app.
  • Step 5 – View the app by typing the following URL in your favorite web browser: localhost:10101/demo
Viewing the App at localhost:10101/demo

We have now set up our local environment for building and running H2O Wave apps. Next, we will configure our connection to the H2O AI Cloud where we will publish our applications.

The H2O Command Line Interface (CLI)

The H2O CLI allows you to interact with the H2O AI Cloud from your terminal. This is easiest way to upload and launch Apps, look at available App Secrets, and allow specific groups of users to access your Apps, among other things. To learn more about what is possible with this tool, check out the documentation.

  • Step 1 – Download the latest version of the CLI here
    • Note that the CLI is regularly updated with new features! You will want to get the latest version periodically. If the tool is ever behaving “weirdly” or a command does not run as expected the first step is to update your CLI.
  • Step 2 – Move the file to somewhere on your $PATH or add the file’s location to your $PATH. This ensures that you can interact with the platform from anywhere on your computer
  • Step 3 – Allow the binary to be executable by running chmod +x h2o
  • Step 4 – Configure the client to your platform by running h2o config setup. You will be asked for information which can be found in the CLI & API Access page when you click your name on the platform
    • Note: You can use h2o -h to get help on how to use the client. This will tell you what features are available and also what parameters to use for a specific command, for example, try h2o app list -h.
CLI & API Access

Uploading Apps

Now that we can build and run Wave apps locally and we can use the CLI to connect with the H2O AI Cloud, we are ready to publish our app. We need 3 files to publish our app into the App Store.

  • Step 1 – The source code – we have already created a file called app.py that has our app code
  • Step 2 – The python requirements – make a file called requirements.txt and add the line h2o-wave==0.20.0 to the file. This tells the App Store which packages and versions to install when running the app.
    • Note: Always pin your libraries in requirements.txt to ensure that your app does not break or get unexpected behavior when a new version of a library is available on PyPi.
      • Wrong: h2o-wave
      • Correct: h2o-wave==0.20.0
  • Step 3 – The configuration file – make a new file called app.toml and add the below text to the file. This will tell the App Store what metadata to show about the app to users in the App Store and also any special rules about running the app. For example, should there be GPUs? Does the end-user need to log in to the app to access the content? etc. You can view all options for this file here.
    • Note: The Module is the file name of our source code, note that we do not include the .py file extension, just the name of the file. If you have all your source code in a folder called src and your main app file called app.py, the value for Module would be src.app
Example app.toml

  •  Step 4 – Before publicly sharing our app with others, we will privately test that it works as expected. Upload the app into the App Store, and have the App Store run a version of this app for us using our terminal: h2o bundle deploy
h2o bundle deploy

  • Step 5 – Append /demo to the provided URL and visit it to see your running App
Your Wave App on H2O AI Cloud

  • Step 6 – We will now re-import the app without auto-running it, and make it available to other users in our App Store: h2o bundle import -v ALL_USERS. Visit your App Store to see your app!

Conclusions

This article walked us through

  1. How to set up and run python Wave apps on our local workstation
  2. How to use the h2o CLI to connect to an instance of the H2O AI Cloud
  3. The minimum requirements to upload our app from step 1 to the App Store

In a future article, we will discuss additional features for deployed apps to improve the user experience of running and using your app.

How to Get Started

Sign up for a free 90-day free trial and get hands-on experience with H2O AI Cloud today.

About the Author

Michelle Tanco

As the Head of Product at H2O.ai, Michelle Tanco’s primary focus lies in delivering a seamless user experience across machine learning applications. With a strong dedication to math and computer science, she is enthusiastic about leveraging these disciplines to address real-world challenges. Before joining H2O, she served as a Senior Data Science Consultant at Teradata, working on high-impact analytics projects to tackle business issues across various industries. Michelle holds a B.A. in Mathematics and Computer Science from Ursinus College. In her downtime, she enjoys spending quality time with her family and expressing her creativity by playing the bass and ukulele.

Leave a Reply

+
Enhancing H2O Model Validation App with h2oGPT Integration

As machine learning practitioners, we’re always on the lookout for innovative ways to streamline and

May 17, 2023 - by Parul Pandey
+
Building a Manufacturing Product Defect Classification Model and Application using H2O Hydrogen Torch, H2O MLOps, and H2O Wave

Primary Authors: Nishaanthini Gnanavel and Genevieve Richards Effective product quality control is of utmost importance in

May 15, 2023 - by Shivam Bansal
AI for Good hackathon
+
Insights from AI for Good Hackathon: Using Machine Learning to Tackle Pollution

At H2O.ai, we believe technology can be a force for good, and we're committed to

May 10, 2023 - by Parul Pandey and Shivam Bansal
H2O democratizing LLMs
+
Democratization of LLMs

Every organization needs to own its GPT as simply as we need to own our

May 8, 2023 - by Sri Ambati
h2oGPT blog header
+
Building the World’s Best Open-Source Large Language Model: H2O.ai’s Journey

At H2O.ai, we pride ourselves on developing world-class Machine Learning, Deep Learning, and AI platforms.

May 3, 2023 - by Arno Candel
LLM blog header
+
Effortless Fine-Tuning of Large Language Models with Open-Source H2O LLM Studio

While the pace at which Large Language Models (LLMs) have been driving breakthroughs is remarkable,

May 1, 2023 - by Parul Pandey

Request a Demo

Explore how to Make, Operate and Innovate with the H2O AI Cloud today

Learn More