forked from sayofthelor/sz-games.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IMAGEAI.html
89 lines (75 loc) · 3.28 KB
/
IMAGEAI.html
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="./tools.css">
<meta charset="UTF-8">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-C78TXR0XFK"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-C78TXR0XFK');
</script>
<script src="./GobalSettings.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
</style>
<title>Image Classification | Sz Games</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.0.0/p5.min.js"></script>
<script src="https://unpkg.com/ml5@latest/dist/ml5.min.js"></script>
</head>
<body>
<div id="TOPNAV" class="NAV" >
<a href="https://sz-games.github.io" aria-label="Home"> <img alt="Icon" fetchpriority="low" src="https://github.com/sz-games/home/blob/main/G.png?raw=true" style=" z-index: 7; position: relative; left: 10px; top: 5px; height: 40px; width: 40px;"> </a>
<div style="position: absolute; top: 0; width: fit-content;">
<h3 class="NAVTXT">Image Classification</h3>
<p class="tag">AI</p>
</div>
</div>
<a style="text-decoration: none;" href="https://sz-games.github.io/">
<span onclick="" class="material-icons" style="background-color: #1d1d1dcf; padding: 2px; border-radius: 15px; z-index: 30; cursor: pointer; font-size: 25px; left: 10px; top: 10px; color: white; position: relative;">
arrow_back
</span>
</a>
<br>
<br>
<button class="UPBTN" onclick="classifyimg()">Classify Image</button>
<input type="file" id="imageupload" accept="image/*">
<img id="uploadedimage" style="background-color: gray; border-radius: 15px; left: 50%; top: 20px; position: relative; transform: translate(-50%);" width="70%">
<div id="results" style="border-radius: 15px; text-align: center; position: fixed; left: 50%; transform: translate(-50%); bottom: 15px; width: 90%; height: 60px; font-size: 15px; background-color: rgba(62, 62, 62, 0.741); "></div>
<script>
const classif = ml5.imageClassifier('MobileNet', modelLoad);
function modelLoad() {
console.log('loadedTheThing')
}
function classifyimg() {
const uploadedimage = document.getElementById('uploadedimage');
const resultsDiv = document.getElementById('results');
const imageupload = document.getElementById('imageupload');
const file = imageupload.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(event) {
uploadedimage.src = event.target.result;
classif.classify(uploadedimage, (err, results) => {
if (err) {
console.error(err);
} else {
resultsDiv.innerHTML = '<h2>Classification Results:</h2>';
for (let i = 0; i < results.length; i++) {
let num = results[0].confidence * 100;
resultsDiv.innerHTML = results[0].label + "<br>Confidence: " + num.toFixed(2) + "%";
}
}
});
};
reader.readAsDataURL(file);
} else {
alert('Please select an image before classifying.');
}
}
</script>
</body>
</html>