Skip to content

Instantly share code, notes, and snippets.

@mtanco
mtanco / pdf.py
Created March 15, 2024 21:18
How to render PDFs in Apps
from h2o_wave import main, app, Q, ui
@app('/')
async def serve(q: Q):
q.page["meta"] = ui.meta_card(
box="",
layouts=[
ui.layout(
@mtanco
mtanco / h2ogpte_history.py
Created March 6, 2024 19:33
Example of an h2oGPTe chatbot wave app that keeps user history and shares this with the LLM
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, SessionError
from h2ogpte.errors import UnauthorizedError
from loguru import logger
@mtanco
mtanco / llm_python_code_generator.py
Created March 5, 2024 19:02
Testing system prompts, models, and specific ways of asking questions to understand how to get Python Executable code from an LLM
"""
Code Executing Testing from LLMs
Michelle Tanco - michelle.tanco@h2o.ai
March 4, 2024
We are attempting to get executable Python code from an LLM. This testing suite helps us with that process.
"""
import os
from h2ogpte import H2OGPTE
from h2ogpte.types import SessionError
@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!"
@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 / 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 / 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 / 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 / dai_unsupervised.ipynb
Created July 13, 2022 04:09
Running all unsupervised model types on a dataset with Driverless AI.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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)