Rajkhanke007's picture
Update templates/index.html
3513d37 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Smart Irrigation Water Predictor</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
background-color: #f0fff0;
}
.container {
border: 1px solid #28a745;
padding: 20px;
margin: 40px auto;
background-color: white;
border-radius: 10px;
}
#weather_info {
background-color: #f8f9fa;
border: 2px solid #000;
padding: 15px;
border-radius: 5px;
}
h1 {
color: #28a745;
text-align: center;
font-weight: bold;
}
.input-container {
display: flex;
justify-content: space-between;
height: 100%;
}
.left-input {
width: 53%;
border-right: 2px solid #28a745;
padding-right: 20px;
}
.right-image {
width: 45%;
display: flex;
justify-content: center;
align-items: center;
height: 200%;
margin-top: 50px;
}
.right-image img {
width: 100%;
height: 100%;
object-fit: contain;
}
.form-control {
border-color: #28a745;
background-color: #f0fff0;
}
.btn-green {
background-color: #28a745;
color: white;
font-weight: bold;
width: 100%;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>Irrigation Water Requirement Prediction</h1>
<form action="/predict" method="POST">
<div class="input-container">
<div class="left-input">
<div class="form-group">
<label for="crop_type">Crop Type</label>
<select class="form-control" id="crop_type" name="crop_type" required>
<option value="BANANA">Banana</option>
<option value="BEAN">BEAN</option>
<option value="CABBAGE">CABBAGE</option>
<option value="CITRUS">CITRUS</option>
<option value="COTTON">COTTON</option>
<option value="MAIZE">MAIZE</option>
<option value="MELON">MELON</option>
<option value="MUSTARD">MUSTARD</option>
<option value="ONION">ONION</option>
<option value="OTHER">OTHER</option>
<option value="POTATO">POTATO</option>
<option value="RICE">RICE</option>
<option value="SOYABEAN">SOYABEAN</option>
<option value="SUGARCANE">SUGARCANE</option>
<option value="TOMATO">TOMATO</option>
<option value="WHEAT">WHEAT</option>
</select>
</div>
<div class="form-group">
<label for="soil_type">Soil Type</label>
<select class="form-control" id="soil_type" name="soil_type" required>
<option value="DRY">Dry</option>
<option value="HUMID">Humid</option>
<option value="WET">Wet</option>
</select>
</div>
<div class="form-group">
<label for="city">City</label>
<input type="text" class="form-control" id="city" name="city" placeholder="Enter city for weather" required>
</div>
<button type="button" class="btn btn-green" onclick="fetchWeather()">Fetch Weather Data</button>
<div id="weather_info" class="mt-3" style="display: none;">
<p><strong>Weather Info:</strong></p>
<div id="weather_data"></div>
</div>
<div class="form-group mt-3">
<label for="motor_capacity">Motor Capacity (liters/sec)</label>
<input type="text" class="form-control" id="motor_capacity" name="motor_capacity" required>
</div>
<button type="submit" class="btn btn-green">Predict Water Requirement</button>
</div>
<div class="right-image">
<img src="/static/images/img.png" alt="Decorative Image">
</div>
</div>
</form>
</div>
<script>
function fetchWeather() {
const city = document.getElementById('city').value;
if (city) {
fetch(`/fetch_weather?city=${city}`)
.then(response => response.json())
.then(data => {
if (data) {
document.getElementById('weather_data').innerHTML = `
Weather: ${data.description}<br>
Temperature: ${data.temperature}°C<br>
Humidity: ${data.humidity}%<br>
Pressure: ${data.pressure} hPa
`;
document.getElementById('weather_info').style.display = 'block';
} else {
document.getElementById('weather_data').innerHTML = 'Weather data not available';
document.getElementById('weather_info').style.display = 'block';
}
})
.catch(error => {
console.error('Error fetching weather:', error);
document.getElementById('weather_data').innerHTML = 'Error fetching weather data';
document.getElementById('weather_info').style.display = 'block';
});
}
}
</script>
</body>
</html>