Update templates/index.html
Browse files- templates/index.html +157 -153
templates/index.html
CHANGED
|
@@ -1,154 +1,158 @@
|
|
| 1 |
-
<!DOCTYPE html>
|
| 2 |
-
<html lang="en">
|
| 3 |
-
|
| 4 |
-
<head>
|
| 5 |
-
<meta charset="UTF-8">
|
| 6 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 7 |
-
<title>์ฑ๋ถ๋ถ์ํ</title>
|
| 8 |
-
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
|
| 9 |
-
<style>
|
| 10 |
-
body {
|
| 11 |
-
font-family: 'Roboto', sans-serif;
|
| 12 |
-
background-color: #f0f2f5;
|
| 13 |
-
display: flex;
|
| 14 |
-
justify-content: center;
|
| 15 |
-
align-items: center;
|
| 16 |
-
height: 100vh;
|
| 17 |
-
margin: 0;
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
.container {
|
| 21 |
-
background: #fff;
|
| 22 |
-
padding: 20px;
|
| 23 |
-
border-radius: 8px;
|
| 24 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
| 25 |
-
text-align: center;
|
| 26 |
-
max-width: 700px;
|
| 27 |
-
width: 100%;
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
h1 {
|
| 31 |
-
color: #333;
|
| 32 |
-
margin-bottom: 20px;
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
video,
|
| 36 |
-
canvas,
|
| 37 |
-
img {
|
| 38 |
-
border-radius: 8px;
|
| 39 |
-
width: 100%;
|
| 40 |
-
max-width: 640px;
|
| 41 |
-
height: auto;
|
| 42 |
-
margin-bottom: 20px;
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
button {
|
| 46 |
-
background-color: #4CAF50;
|
| 47 |
-
color: white;
|
| 48 |
-
padding: 10px 20px;
|
| 49 |
-
border: none;
|
| 50 |
-
border-radius: 5px;
|
| 51 |
-
cursor: pointer;
|
| 52 |
-
font-size: 16px;
|
| 53 |
-
transition: background-color 0.3s, transform 0.3s;
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
button:hover {
|
| 57 |
-
background-color: #45a049;
|
| 58 |
-
transform: scale(1.05);
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
.result {
|
| 62 |
-
margin-top: 20px;
|
| 63 |
-
font-size: 18px;
|
| 64 |
-
font-weight: bold;
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
.good {
|
| 68 |
-
color: green;
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
.normal {
|
| 72 |
-
color: orange;
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
.dangerous {
|
| 76 |
-
color: red;
|
| 77 |
-
}
|
| 78 |
-
</style>
|
| 79 |
-
</head>
|
| 80 |
-
|
| 81 |
-
<body>
|
| 82 |
-
<div class="container">
|
| 83 |
-
<h1>์ฑ๋ถ๋ถ์ํ</h1>
|
| 84 |
-
<video id="video" autoplay></video>
|
| 85 |
-
<button id="snap">์ฌ์ง ์ฐ๊ธฐ</button>
|
| 86 |
-
<canvas id="canvas"></canvas>
|
| 87 |
-
<p id="analysisResult" class="result"></p>
|
| 88 |
-
</div>
|
| 89 |
-
|
| 90 |
-
<script>
|
| 91 |
-
const video = document.getElementById('video');
|
| 92 |
-
const canvas = document.getElementById('canvas');
|
| 93 |
-
const snap = document.getElementById('snap');
|
| 94 |
-
const context = canvas.getContext('2d');
|
| 95 |
-
const analysisResult = document.getElementById('analysisResult');
|
| 96 |
-
|
| 97 |
-
navigator.mediaDevices.getUserMedia({ video: true })
|
| 98 |
-
.then(stream => {
|
| 99 |
-
video.srcObject = stream;
|
| 100 |
-
})
|
| 101 |
-
.catch(err => {
|
| 102 |
-
console.error("Error accessing webcam: " + err);
|
| 103 |
-
});
|
| 104 |
-
|
| 105 |
-
function processAnalysisResult(result) {
|
| 106 |
-
const match = result.match(/\d+/);
|
| 107 |
-
if (match) {
|
| 108 |
-
const sugarContent = parseInt(match[0], 10);
|
| 109 |
-
let message = '';
|
| 110 |
-
let className = '';
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
analysisResult.
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
|
| 4 |
+
<head>
|
| 5 |
+
<meta charset="UTF-8">
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 7 |
+
<title>์ฑ๋ถ๋ถ์ํ</title>
|
| 8 |
+
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
|
| 9 |
+
<style>
|
| 10 |
+
body {
|
| 11 |
+
font-family: 'Roboto', sans-serif;
|
| 12 |
+
background-color: #f0f2f5;
|
| 13 |
+
display: flex;
|
| 14 |
+
justify-content: center;
|
| 15 |
+
align-items: center;
|
| 16 |
+
height: 100vh;
|
| 17 |
+
margin: 0;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
.container {
|
| 21 |
+
background: #fff;
|
| 22 |
+
padding: 20px;
|
| 23 |
+
border-radius: 8px;
|
| 24 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
| 25 |
+
text-align: center;
|
| 26 |
+
max-width: 700px;
|
| 27 |
+
width: 100%;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
h1 {
|
| 31 |
+
color: #333;
|
| 32 |
+
margin-bottom: 20px;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
video,
|
| 36 |
+
canvas,
|
| 37 |
+
img {
|
| 38 |
+
border-radius: 8px;
|
| 39 |
+
width: 100%;
|
| 40 |
+
max-width: 640px;
|
| 41 |
+
height: auto;
|
| 42 |
+
margin-bottom: 20px;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
button {
|
| 46 |
+
background-color: #4CAF50;
|
| 47 |
+
color: white;
|
| 48 |
+
padding: 10px 20px;
|
| 49 |
+
border: none;
|
| 50 |
+
border-radius: 5px;
|
| 51 |
+
cursor: pointer;
|
| 52 |
+
font-size: 16px;
|
| 53 |
+
transition: background-color 0.3s, transform 0.3s;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
button:hover {
|
| 57 |
+
background-color: #45a049;
|
| 58 |
+
transform: scale(1.05);
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
.result {
|
| 62 |
+
margin-top: 20px;
|
| 63 |
+
font-size: 18px;
|
| 64 |
+
font-weight: bold;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.good {
|
| 68 |
+
color: green;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
.normal {
|
| 72 |
+
color: orange;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.dangerous {
|
| 76 |
+
color: red;
|
| 77 |
+
}
|
| 78 |
+
</style>
|
| 79 |
+
</head>
|
| 80 |
+
|
| 81 |
+
<body>
|
| 82 |
+
<div class="container">
|
| 83 |
+
<h1>์ฑ๋ถ๋ถ์ํ</h1>
|
| 84 |
+
<video id="video" autoplay></video>
|
| 85 |
+
<button id="snap">์ฌ์ง ์ฐ๊ธฐ</button>
|
| 86 |
+
<canvas id="canvas"></canvas>
|
| 87 |
+
<p id="analysisResult" class="result"></p>
|
| 88 |
+
</div>
|
| 89 |
+
|
| 90 |
+
<script>
|
| 91 |
+
const video = document.getElementById('video');
|
| 92 |
+
const canvas = document.getElementById('canvas');
|
| 93 |
+
const snap = document.getElementById('snap');
|
| 94 |
+
const context = canvas.getContext('2d');
|
| 95 |
+
const analysisResult = document.getElementById('analysisResult');
|
| 96 |
+
|
| 97 |
+
navigator.mediaDevices.getUserMedia({ video: true })
|
| 98 |
+
.then(stream => {
|
| 99 |
+
video.srcObject = stream;
|
| 100 |
+
})
|
| 101 |
+
.catch(err => {
|
| 102 |
+
console.error("Error accessing webcam: " + err);
|
| 103 |
+
});
|
| 104 |
+
|
| 105 |
+
function processAnalysisResult(result) {
|
| 106 |
+
const match = result.match(/\d+/);
|
| 107 |
+
if (match) {
|
| 108 |
+
const sugarContent = parseInt(match[0], 10);
|
| 109 |
+
let message = '';
|
| 110 |
+
let className = '';
|
| 111 |
+
let count = '';
|
| 112 |
+
|
| 113 |
+
if (sugarContent >= 0 && sugarContent <= 20) {
|
| 114 |
+
message = 'good';
|
| 115 |
+
className = 'good';
|
| 116 |
+
count = match;
|
| 117 |
+
} else if (sugarContent >= 21 && sugarContent <= 50) {
|
| 118 |
+
message = 'normal';
|
| 119 |
+
className = 'normal';
|
| 120 |
+
count = match;
|
| 121 |
+
} else if (sugarContent >= 51) {
|
| 122 |
+
message = 'dangerous';
|
| 123 |
+
className = 'dangerous';
|
| 124 |
+
count = match;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
analysisResult.textContent = message + match;
|
| 128 |
+
analysisResult.className = className;
|
| 129 |
+
} else {
|
| 130 |
+
analysisResult.textContent = 'Error: Could not analyze image.' + match;
|
| 131 |
+
analysisResult.className = '';
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
snap.addEventListener('click', () => {
|
| 136 |
+
context.drawImage(video, 0, 0, canvas.width, canvas.height);
|
| 137 |
+
const dataURL = canvas.toDataURL('image/png');
|
| 138 |
+
fetch('/save_image', {
|
| 139 |
+
method: 'POST',
|
| 140 |
+
headers: {
|
| 141 |
+
'Content-Type': 'application/json',
|
| 142 |
+
},
|
| 143 |
+
body: JSON.stringify({ image: dataURL })
|
| 144 |
+
}).then(response => response.json())
|
| 145 |
+
.then(data => {
|
| 146 |
+
if (data.analysis_result) {
|
| 147 |
+
processAnalysisResult(data.analysis_result);
|
| 148 |
+
} else {
|
| 149 |
+
analysisResult.textContent = 'Error: ์ฑ๋ถ๋ถ์ํ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค.';
|
| 150 |
+
analysisResult.className = '';
|
| 151 |
+
}
|
| 152 |
+
alert(data.message);
|
| 153 |
+
});
|
| 154 |
+
});
|
| 155 |
+
</script>
|
| 156 |
+
</body>
|
| 157 |
+
|
| 158 |
</html>
|