2024-01-16 15:30:46 +01:00
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
2024-01-18 23:28:35 +01:00
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
2024-01-16 15:30:46 +01:00
|
|
|
<title>TomAIto</title>
|
|
|
|
<style>
|
2024-01-18 23:28:35 +01:00
|
|
|
body {
|
|
|
|
font-family: 'Arial', sans-serif;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
background-color: #f5f5f5;
|
|
|
|
color: #333;
|
|
|
|
transition: background-color 0.3s, color 0.3s;
|
|
|
|
}
|
|
|
|
|
|
|
|
body.dark-mode {
|
|
|
|
background-color: #333;
|
|
|
|
color: #fff !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
header {
|
|
|
|
background-color: #4CAF50;
|
|
|
|
color: white;
|
|
|
|
text-align: center;
|
|
|
|
padding: 15px;
|
|
|
|
font-size: 24px;
|
|
|
|
width: 100%;
|
|
|
|
position: relative;
|
2024-01-16 15:30:46 +01:00
|
|
|
display: flex;
|
2024-01-18 23:28:35 +01:00
|
|
|
justify-content: center;
|
2024-01-16 15:30:46 +01:00
|
|
|
}
|
|
|
|
|
2024-01-18 23:28:35 +01:00
|
|
|
header span {
|
|
|
|
color: #ff6600;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
#darkModeToggle {
|
|
|
|
width: 90px;
|
|
|
|
height: 30px;
|
|
|
|
background-color: #333;
|
|
|
|
color: white;
|
|
|
|
border: none;
|
|
|
|
border-radius: 5px;
|
2024-01-16 15:30:46 +01:00
|
|
|
display: flex;
|
2024-01-18 23:28:35 +01:00
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
padding: 5px;
|
|
|
|
cursor: pointer;
|
|
|
|
transition: background-color 0.3s;
|
|
|
|
position: absolute;
|
|
|
|
top: 50%;
|
|
|
|
right: 20px;
|
|
|
|
transform: translateY(-50%);
|
|
|
|
}
|
|
|
|
|
|
|
|
#darkModeToggle:hover {
|
|
|
|
background-color: #001a33;
|
|
|
|
}
|
2024-01-16 15:30:46 +01:00
|
|
|
|
2024-01-18 23:28:35 +01:00
|
|
|
canvas {
|
|
|
|
border: 1px solid #ddd;
|
|
|
|
max-width: 100%;
|
|
|
|
display: block;
|
|
|
|
margin: auto;
|
|
|
|
margin-top: 20px;
|
|
|
|
background-color: white;
|
|
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
|
|
|
border-radius: 5px;
|
|
|
|
}
|
|
|
|
|
|
|
|
#weatherInfo {
|
|
|
|
max-width: 100%;
|
|
|
|
margin: auto;
|
|
|
|
margin-top: 20px;
|
|
|
|
padding: 15px;
|
|
|
|
background-color: #fff;
|
|
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
|
|
|
border-radius: 5px;
|
|
|
|
color: #333;
|
|
|
|
}
|
2024-01-16 15:30:46 +01:00
|
|
|
|
|
|
|
form {
|
2024-01-18 23:28:35 +01:00
|
|
|
max-width: 600px;
|
|
|
|
width: 100%;
|
|
|
|
margin: auto;
|
|
|
|
padding: 20px;
|
2024-01-16 15:30:46 +01:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2024-01-18 23:28:35 +01:00
|
|
|
align-items: center;
|
|
|
|
background-color: #f9f9f9;
|
|
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
|
|
|
border-radius: 5px;
|
|
|
|
color: #333;
|
|
|
|
transition: background-color 0.3s, color 0.3s;
|
|
|
|
}
|
|
|
|
|
|
|
|
body.dark-mode form {
|
|
|
|
background-color: #333;
|
|
|
|
color: #fff;
|
2024-01-16 15:30:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
label {
|
|
|
|
margin-top: 10px;
|
2024-01-18 23:28:35 +01:00
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
input,
|
|
|
|
select {
|
|
|
|
width: 100%;
|
|
|
|
box-sizing: border-box;
|
|
|
|
margin-bottom: 15px;
|
|
|
|
padding: 10px;
|
|
|
|
border: 1px solid #ddd;
|
|
|
|
border-radius: 4px;
|
|
|
|
background-color: #fff;
|
|
|
|
transition: border-color 0.3s;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
@media (min-width: 768px) {
|
|
|
|
form {
|
|
|
|
max-width: 50%;
|
|
|
|
}
|
|
|
|
|
|
|
|
input,
|
|
|
|
select {
|
|
|
|
width: auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
input:focus,
|
|
|
|
select:focus {
|
|
|
|
outline: none;
|
|
|
|
border-color: #4CAF50;
|
|
|
|
}
|
|
|
|
|
|
|
|
input[type="file"] {
|
|
|
|
background-color: #4CAF50;
|
|
|
|
color: white;
|
|
|
|
}
|
|
|
|
|
|
|
|
input[type="file"]:focus {
|
|
|
|
outline: none;
|
|
|
|
border-color: #001a33;
|
2024-01-16 15:30:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
button {
|
2024-01-18 23:28:35 +01:00
|
|
|
width: 100%;
|
|
|
|
padding: 15px;
|
|
|
|
border: none;
|
|
|
|
border-radius: 4px;
|
|
|
|
background-color: #4CAF50;
|
|
|
|
color: white;
|
|
|
|
cursor: pointer;
|
|
|
|
transition: background-color 0.3s;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
button:hover {
|
|
|
|
background-color: #001a33;
|
2024-01-16 15:30:46 +01:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
2024-01-18 23:28:35 +01:00
|
|
|
|
2024-01-16 15:30:46 +01:00
|
|
|
<body>
|
2024-01-18 23:28:35 +01:00
|
|
|
<header>
|
|
|
|
Tom<span style="color: #ff6600;">AI</span>to
|
|
|
|
<button id="darkModeToggle" onclick="toggleDarkMode()">Dark Mode</button>
|
|
|
|
</header>
|
|
|
|
|
2024-01-16 15:30:46 +01:00
|
|
|
<form id="uploadForm">
|
|
|
|
|
|
|
|
<label for="cropType">Crop Type:</label>
|
|
|
|
<select id="cropType" name="cropType">
|
|
|
|
<option value="external">External</option>
|
|
|
|
<option value="internal">Internal</option>
|
|
|
|
<option value="greenhouse">Greenhouse</option>
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<label for="location">Location:</label>
|
|
|
|
<input type="text" id="location" name="location" required/>
|
|
|
|
|
|
|
|
<label for="variety">Variety:</label>
|
|
|
|
<input type="text" id="variety" name="variety" required/>
|
|
|
|
|
|
|
|
<label for="uploadInput">Choose an image:</label>
|
|
|
|
<input id="uploadInput" type="file" required/>
|
|
|
|
|
2024-01-18 23:28:35 +01:00
|
|
|
<button type="Sprawdz">Check the ripeness</button>
|
2024-01-16 15:30:46 +01:00
|
|
|
</form>
|
|
|
|
|
|
|
|
<canvas></canvas>
|
|
|
|
<div id="weatherInfo"></div>
|
|
|
|
<script>
|
|
|
|
const form = document.getElementById("uploadForm");
|
|
|
|
|
|
|
|
form.addEventListener("submit", async (event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
const fileInput = document.getElementById("uploadInput");
|
|
|
|
const cropTypeInput = document.getElementById("cropType");
|
|
|
|
const locationInput = document.getElementById("location");
|
|
|
|
const varietyInput = document.getElementById("variety");
|
|
|
|
|
|
|
|
const file = fileInput.files[0];
|
|
|
|
|
|
|
|
const data = new FormData();
|
|
|
|
data.append("image_file", file);
|
|
|
|
data.append("cropType", cropTypeInput.value);
|
|
|
|
data.append("location", locationInput.value);
|
|
|
|
data.append("variety", varietyInput.value);
|
|
|
|
|
|
|
|
const response = await fetch("/detect", {
|
|
|
|
method: "post",
|
|
|
|
body: data
|
|
|
|
});
|
|
|
|
|
|
|
|
const boxes = await response.json();
|
|
|
|
draw_image_and_boxes(file, boxes);
|
|
|
|
|
|
|
|
const location = locationInput.value;
|
2024-01-16 16:02:04 +01:00
|
|
|
|
|
|
|
if (cropTypeInput.value == "external") {
|
|
|
|
getWeather(location);
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
const randomTips = [
|
|
|
|
"water your tomatoes every day.",
|
|
|
|
"keep the temperature between 20-25 degrees Celsius.",
|
|
|
|
"place the tomatoes in sunlight."];
|
|
|
|
|
|
|
|
const randomTip = randomTips[Math.floor(Math.random() * randomTips.length)];
|
|
|
|
document.getElementById("weatherInfo").innerText = "TIP! To maximalize your yields " + randomTip;
|
|
|
|
}
|
2024-01-16 15:30:46 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
function draw_image_and_boxes(file, boxes) {
|
|
|
|
const img = new Image()
|
|
|
|
img.src = URL.createObjectURL(file);
|
|
|
|
img.onload = () => {
|
|
|
|
const canvas = document.querySelector("canvas");
|
|
|
|
canvas.width = img.width;
|
|
|
|
canvas.height = img.height;
|
|
|
|
const ctx = canvas.getContext("2d");
|
|
|
|
ctx.drawImage(img, 0, 0);
|
|
|
|
ctx.strokeStyle = "#00FF00";
|
|
|
|
ctx.lineWidth = 5;
|
|
|
|
ctx.font = "20px serif";
|
|
|
|
boxes.forEach(([x1, y1, x2, y2, object_type, prob]) => {
|
2024-01-18 23:39:23 +01:00
|
|
|
const label = `${object_type}`;
|
2024-01-16 15:30:46 +01:00
|
|
|
ctx.strokeRect(x1, y1, x2 - x1, y2 - y1);
|
|
|
|
ctx.fillStyle = "#00ff00";
|
|
|
|
const width = ctx.measureText(label).width;
|
|
|
|
ctx.fillRect(x1, y1, width + 10, 25);
|
|
|
|
ctx.fillStyle = "#000000";
|
|
|
|
ctx.fillText(label, x1, y1 + 18);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getWeather(location) {
|
|
|
|
const apiKey = "1fc6a52c96331d035a828cc0c1606241";
|
|
|
|
const apiUrl = `https://api.openweathermap.org/data/2.5/weather?q=${location}&appid=${apiKey}`;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const weatherResponse = await fetch(apiUrl);
|
|
|
|
const weatherData = await weatherResponse.json();
|
|
|
|
|
|
|
|
if (weatherData.main && weatherData.main.temp) {
|
|
|
|
const temperatureKelvin = weatherData.main.temp;
|
|
|
|
const temperatureCelsius = temperatureKelvin - 273.15;
|
|
|
|
const tempRound = Math.round(temperatureCelsius);
|
|
|
|
|
|
|
|
const weatherCondition = weatherData.weather[0].main;
|
|
|
|
const isRaining = weatherCondition === 'Rain';
|
|
|
|
|
|
|
|
let additionalInfo = `${isRaining ? 'Rain is expected in your town today, so you dont have to water your tomatoes' :
|
|
|
|
'No rainfall is expected in the city today, so you need to water your tomatoes!'} Temperature in ${location} is ${tempRound} °C.`;
|
|
|
|
|
|
|
|
if (tempRound < 15) {
|
|
|
|
additionalInfo += ' So you need to cover your tomatoes!';
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById("weatherInfo").innerText = additionalInfo;
|
|
|
|
} else {
|
|
|
|
document.getElementById("weatherInfo").innerText = "Unable to fetch weather data.";
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error fetching weather data:", error);
|
|
|
|
document.getElementById("weatherInfo").innerText = "Error fetching weather data.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
2024-01-18 23:28:35 +01:00
|
|
|
<script>
|
|
|
|
// Dark mode toggle functionality
|
|
|
|
function toggleDarkMode() {
|
|
|
|
const body = document.body;
|
|
|
|
body.classList.toggle('dark-mode');
|
|
|
|
|
|
|
|
// Change the text content of the toggle icon
|
|
|
|
const toggleIcon = document.getElementById('darkModeToggle');
|
|
|
|
toggleIcon.textContent = body.classList.contains('dark-mode') ? 'Light Mode' : 'Dark Mode';
|
|
|
|
}
|
|
|
|
</script>
|
2024-01-16 15:30:46 +01:00
|
|
|
</body>
|
2023-12-28 22:09:32 +01:00
|
|
|
</html>
|