-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the Web Worker extension to the examples
- Loading branch information
Darius Morawiec
committed
Nov 1, 2017
1 parent
a17c77c
commit 187efac
Showing
16 changed files
with
296 additions
and
222 deletions.
There are no files selected for viewing
Empty file.
39 changes: 11 additions & 28 deletions
39
examples/estimator/classifier/MLPClassifier/js/basics.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>sklearn-porter</title> | ||
<style> | ||
p { line-height: 16px; font-size: 16px; } | ||
input { height: 16px; margin: 0 2em; } | ||
</style> | ||
</head> | ||
<body> | ||
<main> | ||
<section> | ||
Used data: <a href="https://github.com/nok/sklearn-porter/blob/master/examples/estimator/classifier/MLPClassifier/js/basics.py">examples/estimator/classifier/MLPClassifier/js/basics.py</a> | ||
</section> | ||
<section class="input"> | ||
<form> | ||
<p> | ||
Feature 1: <input class="js_slider" type="range" min="-5" max="5" value="0" step="0.01"><span>0</span> | ||
</p> | ||
<p> | ||
Feature 2: <input class="js_slider" type="range" min="-5" max="5" value="0" step="0.01"><span>0</span> | ||
</p> | ||
<p> | ||
Feature 3: <input class="js_slider" type="range" min="-5" max="5" value="0" step="0.01"><span>0</span> | ||
</p> | ||
<p> | ||
Feature 4: <input class="js_slider" type="range" min="-5" max="5" value="0" step="0.01"><span>0</span> | ||
</p> | ||
</form> | ||
</section> | ||
<section class="output"> | ||
Prediction: <strong id="js_prediction">-</strong> | ||
</section> | ||
</main> | ||
<script type="text/javascript"> | ||
if (typeof window !== 'undefined' && window.Worker) { | ||
|
||
var $sliders = document.getElementsByClassName('js_slider'); | ||
var $label = document.getElementById("js_prediction"); | ||
|
||
var worker = new Worker('worker.js'); | ||
worker.onmessage = function(e) { | ||
$label.innerHTML = e.data; | ||
}; | ||
|
||
var run = function() { | ||
var features = Array(); | ||
Array.prototype.forEach.call($sliders, function($slider, i){ | ||
var val = (typeof($slider.value) === 'undefined') ? 0 : $slider.value; | ||
val = parseFloat(val); | ||
features.push(val); | ||
}); | ||
worker.postMessage(features); | ||
}; | ||
|
||
Array.prototype.forEach.call($sliders, function($slider, i){ | ||
$slider.addEventListener('change', function(e) { | ||
this.nextElementSibling.innerHTML = this.value; | ||
run(); | ||
}); | ||
}); | ||
|
||
} | ||
</script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
python -m $(python -c 'import sys; print("http.server" if sys.version_info[:2] > (2,7) else "SimpleHTTPServer")') |
Oops, something went wrong.