-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
55 lines (44 loc) · 1.42 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
let prediction_1 = ""; // Ensure prediction_2 is also defined if needed
function take_snapshot() {
Webcam.snap(function(data_uri) {
document.getElementById("result").innerHTML = '<img id="captured_image" src="' + data_uri + '">';
});
}
console.log("ml5 version", ml5.version);
const classifier = ml5.imageClassifier("https://teachablemachine.withgoogle.com/models/QHbESmae-/model.json", modelLoaded);
function modelLoaded() {
console.log("Model Loaded");
}
function speak() {
const synth = window.speechSynthesis;
const speak_data_1 = "The prediction is " + prediction_1;
const utterThis = new SpeechSynthesisUtterance(speak_data_1); // Removed speak_data_2
synth.speak(utterThis);
}
function predict() {
const img = document.getElementById("captured_image");
classifier.classify(img, gotResults);
}
function gotResults(error, results) {
if (error) {
console.error(error);
} else {
console.log(results);
document.getElementById("result_hand_name").innerHTML = results[0].label;
prediction_1 = results[0].label;
speak();
}
}
// Navigation functions
function diagnose() {
window.location.href = "index.html";
}
function support() {
window.location.href = "support.html";
}
function back() {
window.location.href = "main.html";
}
function q(){
window.location.href = "q.html";
}