This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Image / Stream | |
# Display an image and continuously update it in real time. | |
# --- | |
import io | |
import time | |
import uuid | |
import cv2 | |
from h2o_wave import app, Q, ui, main | |
import numpy as np |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import concurrent.futures | |
from h2o_wave import main, app, Q, ui | |
import boto3 | |
import asyncio | |
def download(q: Q, loop: asyncio.AbstractEventLoop): | |
bucket = 'h2o-wave' | |
file_key = 'releases/h2o_wave-0.22.0-py3-none-win_amd64.whl' | |
# Get the total size of the file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the current event loop to update UI later. | |
loop = asyncio.get_event_loop() | |
with concurrent.futures.ThreadPoolExecutor() as pool: | |
await q.exec(pool, download, q, loop) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the current event loop to update UI later. | |
loop = asyncio.get_event_loop() | |
with concurrent.futures.ThreadPoolExecutor() as pool: | |
await q.exec(pool, download, q, loop) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def download(q: Q, loop: asyncio.AbstractEventLoop): | |
bucket = 'h2o-wave' | |
file_key = 'releases/h2o_wave-0.22.0-py3-none-win_amd64.whl' | |
# Get the total size of the file. | |
total = boto3.client('s3').head_object(Bucket=bucket, Key=file_key)['ContentLength'] | |
already_downloaded = 0 | |
# Nested update function that is called periodically from within boto. | |
def update(val): | |
nonlocal already_downloaded |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from threading import Event | |
import httpx | |
from h2o_wave import Q, app, main, ui | |
async def download_file(q: Q): | |
# Create a tmp file to store the downloaded contents. | |
with open('my_download', 'wb') as tmp_file: | |
# Random URL to download a 100MB file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if q.args.cancel: | |
q.client.event.set() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
q.client.event = Event() | |
await download_file(q) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async def download_file(q: Q): | |
# Create a tmp file to store the downloaded contents. | |
with open('my_download', 'wb') as tmp_file: | |
# Random URL to download a 100MB file. | |
url = 'https://speed.hetzner.de/100MB.bin' | |
# Get async HTTP client. | |
async with httpx.AsyncClient() as client: | |
# Stream the response to get periodic download updates. | |
async with client.stream('GET', url) as response: | |
total = int(response.headers['Content-Length']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import concurrent.futures | |
from threading import Event | |
import time | |
from h2o_wave import main, app, Q, ui | |
# This takes a lot of time (compute heavy). | |
async def blocking_function(q: Q): | |
count = 0 | |
total = 10 |
NewerOlder