Skip to content

Instantly share code, notes, and snippets.

@mtanco
mtanco / clickable_wave_table.py
Created December 3, 2021 17:48
How to make a table from a pandas data frame and do something when one of the rows is clicked in H2O Wave.
from h2o_wave import main, app, Q, ui
import pandas as pd
import numpy as np
@app('/')
async def serve(q: Q):
print(q.args)
if not q.client.initialized:
@mtanco
mtanco / stream_text.py
Last active July 12, 2022 22:53
Display fake-streamed text data using H2O Wave. Pause and resume the real-time updates.
"""
Demo of Updating App Data in one card of an app
"""
from random import randint
from h2o_wave import Q, app, handle_on, main, on, ui
@app("/")
async def serve(q: Q):
@mtanco
mtanco / mlops_deployment_app.py
Created March 7, 2022 23:52
Set a nice name and an MLOps deployment, get a nice app
import json
import requests
from h2o_wave import main, app, Q, ui, expando_to_dict
ENDPOINT = "https://model.DOMAIN.h2o.ai/MODELID/model"
APP_TITLE = "My Use Case"
@mtanco
mtanco / wave_home_header_image.py
Created June 3, 2022 15:50
The app shows how you can route to a different hash page, and then go to the home of the app by clicking an image in the header card.
from h2o_wave import main, app, Q, ui, on, handle_on
@app('/')
async def serve(q: Q):
print(q.args)
# First time a browser comes to the app
if not q.client.initialized:
await init(q)
@mtanco
mtanco / dai_unsupervised.ipynb
Created July 13, 2022 04:09
Running all unsupervised model types on a dataset with Driverless AI.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mtanco
mtanco / download_file_progress.py
Created July 19, 2022 21:59
H2O Wave tutorial for how to download a "big" file and update the user on the progress. Download from URL is used as a specific example but you should be able to modify this for any data pull that is asynchronous or done in bytes.
import os
import certifi
import pandas as pd
import urllib3 # urllib3==1.26.10
from h2o_wave import Q, app, handle_on, main, on, ui # h2o_wave==0.22.0
@app("/")
async def serve(q: Q):
@mtanco
mtanco / app.py
Created September 12, 2022 19:24
This Wave app for H2O's AI App Store will show app content to users in the specific authorization role and will give an access denied page to anyone else.
from h2o_wave import main, app, Q, ui
import jwt
@app('/')
async def serve(q: Q):
if not q.app.initialized:
q.app.authorization_role = "my_important_group"
@mtanco
mtanco / wave_to_sql_table.py
Created October 5, 2022 20:11
Connect to a WaveDB table: allow the user to explore all rows and edit the data
# Connect to a WaveDB table: allow the user to explore all rows and edit the data
# To run this app you need to run `./wavedb` first
# The UI and SQL calls in this demo are hardcoded to a specific UI and would need to be updated as the data changes
# There was no attempt to "automatically" create the UI based on a generic SQL table
# This example does not include sorting, filtering, or downloading the dataset
from h2o_wave import main, app, Q, ui, connect
@app('/')
async def serve(q: Q):
@mtanco
mtanco / wave_edit_table_from_ui.py
Created October 18, 2022 22:35
Let users edit a table's data directly from the UI. Uses pandas in the background to save the dataset per browser tab. You may want this to be shared across users, or to save with an external database instead.
from h2o_wave import main, app, Q, ui
import pandas as pd
@app('/')
async def serve(q: Q):
if not q.client.initialized:
q.page["meta"] = ui.meta_card(box="")
@mtanco
mtanco / stream_h2o_llms.py
Last active January 10, 2024 00:52
This script serves as a foundation for creating interactive chatbot applications with streaming responses powered by H2O.ai's language models within the H2O Wave framework.
import os
import asyncio
from h2o_wave import main, app, Q, ui, data, run_on, on
from h2ogpte import H2OGPTE
from h2ogpte.types import ChatMessage, PartialChatMessage
SYSTEM_PROMPT = "Hello, I am a bot that only talks about dogs!"