mirror of
https://github.com/pyscript/pyscript.git
synced 2026-02-13 07:01:00 -05:00
* Execute pys-on* events when triggered, not at load Mimicing the behavior of Javascripts 'onLoad' event, we should not be executing the use code at page-load time, only when the event is triggered. * Update examples to new syntax * Fix merge issue * Await running event handler code * Restore pys-on* events with original behavior, deprecation warning * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * xfail toga example * Add missing { (typo) * Adjust callback chandling to make linter happy * Change alpha to latest (#760) * Don't create custom elements in main and fix various small issues on tests (#747) * Create custom elements when the runtime finishes loading * Remove xfails and fix repl integration test * Fix commented ignore * Address Antonio's comments * Fix bad rebase * Make ure to wait for repl to be in attached state before asserting content * Move createCustomeElement up so it runs before we close the loader, xfail flaky d3 test * Fix xfail * [pre-commit.ci] pre-commit autoupdate (#762) updates: - [github.com/pre-commit/mirrors-eslint: v8.23.0 → v8.23.1](https://github.com/pre-commit/mirrors-eslint/compare/v8.23.0...v8.23.1) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * change documentation to point to latest instead of frozen alpha (#764) * Toga example is xpass * Correct 'xpass' to 'xfail' mark Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Peter W <34256109+pww217@users.noreply.github.com> Co-authored-by: Fábio Rosado <fabiorosado@outlook.com>
123 lines
3.4 KiB
HTML
123 lines
3.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
|
|
<title>Svelte app</title>
|
|
|
|
<link rel="icon" type="image/png" href="../favicon.png" />
|
|
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
|
|
|
|
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
|
|
</head>
|
|
|
|
<body>
|
|
<py-script>
|
|
from js import handTrack, requestAnimationFrame
|
|
from pyodide import create_once_callable
|
|
import asyncio
|
|
|
|
context = canvas.element.getContext("2d")
|
|
|
|
isVideo = False
|
|
model = None
|
|
|
|
modelParams = {
|
|
"flipHorizontal": True, # flip e.g for video
|
|
"maxNumBoxes": 20, # maximum number of boxes to detect
|
|
"iouThreshold": 0.5, # ioU threshold for non-max suppression
|
|
"scoreThreshold": 0.6, # confidence threshold for predictions.
|
|
}
|
|
|
|
def toggle_video(evt):
|
|
global isVideo
|
|
if (not isVideo):
|
|
update_note.write("Starting video")
|
|
pyscript.run_until_complete(start_video())
|
|
else:
|
|
update_note.write("Stopping video")
|
|
handTrack.stopVideo(video.element)
|
|
isVideo = False
|
|
update_note.write("Video stopped")
|
|
|
|
async def start_video():
|
|
global isVideo
|
|
update_note.write("Inside sstart video")
|
|
status = await handTrack.startVideo(video.element)
|
|
console.log("video started", status)
|
|
if status:
|
|
update_note.write("Video started. Now tracking")
|
|
isVideo = True
|
|
console.log( "Calling RUN DETECTION")
|
|
y = await run_detection()
|
|
else:
|
|
update_note.write( "Please enable video")
|
|
|
|
def sync_run_detection(evt):
|
|
pyscript.run_until_complete(run_detection())
|
|
|
|
async def run_detection():
|
|
console.log("in RUN DETECTION: ");
|
|
global model
|
|
global isVideo
|
|
|
|
console.log("...1")
|
|
|
|
predictions = await model.detect(video.element)
|
|
console.log("done...1")
|
|
console.log("Predictions: ", predictions);
|
|
model.renderPredictions(predictions, canvas.element, context, video.element);
|
|
console.log("is Video?", isVideo)
|
|
if (isVideo):
|
|
console.log("requestingAnimation!")
|
|
await requestAnimationFrame(create_once_callable(sync_run_detection));
|
|
console.log("...2")
|
|
|
|
def run_detection_image(img):
|
|
console.log("in RUN DETECTION IMAGE", predictions);
|
|
global model
|
|
def detect(predition):
|
|
console.log("Predictions: ", predictions);
|
|
model.renderPredictions(predictions, canvas, context, img);
|
|
console.log("...3")
|
|
model.detect(img).then(detect)
|
|
console.log("...4")
|
|
|
|
def handle_model(lmodel):
|
|
global model
|
|
model = lmodel
|
|
update_note.write("Loaded Model!")
|
|
|
|
async def start():
|
|
console.log("creating x")
|
|
console.log("calling x")
|
|
model = await handTrack.load(modelParams)#.then(handle_model)
|
|
console.log("loaded model!")
|
|
console.log(model)
|
|
handle_model(model)
|
|
print(dir(x))
|
|
print(x)
|
|
|
|
pyscript.run_until_complete(start())
|
|
|
|
#});
|
|
|
|
</py-script>
|
|
|
|
<div class="mb10">
|
|
<button id="trackbutton" class="bx--btn bx--btn--secondary" type="button" py-onClick="toggle_video()">
|
|
Toggle Video
|
|
</button>
|
|
<button id="nextimagebutton" class="mt10 bx--btn bx--btn--secondary" type="button" disabled>
|
|
Next Image
|
|
</button>
|
|
<div id="update-note" py-mount class="updatenote mt10">loading model ..</div>
|
|
</div>
|
|
<div>
|
|
<video autoplay="autoplay" id="myvideo" py-mount="video"></video>
|
|
<canvas id="canvas" py-mount class="border canvasbox"></canvas>
|
|
</div>
|
|
<script src="lib/handtrack.min.js"> </script>
|
|
</html>
|