Upload 5 files
Browse files- .gitattributes +1 -0
- app.py +75 -0
- final_crop_data.csv +3 -0
- lgb_model_cropseason.pkl +3 -0
- static/img1.jpg +0 -0
- templates/index.html +159 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
final_crop_data.csv filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, render_template, jsonify
|
| 2 |
+
import joblib
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
|
| 7 |
+
# Load the trained LightGBM model
|
| 8 |
+
lgb_model = joblib.load('lgb_model_cropseason.pkl')
|
| 9 |
+
|
| 10 |
+
url='https://drive.google.com/file/d/1_vd4HISZB2h2--CiXKezeWDXHHo2fY23/view?usp=sharing'
|
| 11 |
+
data = pd.read_csv('https://drive.usercontent.google.com/download?id={}&export=download&authuser=0&confirm=t'.format(url.split('/')[-2]))
|
| 12 |
+
|
| 13 |
+
# Extract unique values for states, districts, crops, and seasons
|
| 14 |
+
unique_states = data['State'].unique()
|
| 15 |
+
unique_crops = data['Crop'].unique()
|
| 16 |
+
|
| 17 |
+
# Descriptions for each cropping season
|
| 18 |
+
season_descriptions = {
|
| 19 |
+
'Kharif': 'Kharif season occurs from June to October, associated with the monsoon. Crops are usually sown at the start of the rainy season.',
|
| 20 |
+
'Rabi': 'Rabi season spans from October to March, during the winter cropping season, with crops like wheat and barley.',
|
| 21 |
+
'Summer': 'Summer season is from April to June, suitable for crops that need warmer temperatures.',
|
| 22 |
+
'Winter': 'Winter cropping season occurs from November to February, including cold-weather crops.',
|
| 23 |
+
'Whole Year': 'Crops can be grown throughout the year, without seasonal limitations.',
|
| 24 |
+
'Autumn': 'Autumn season, from September to November, accommodates crops suited to a post-monsoon environment.'
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
@app.route('/')
|
| 28 |
+
def home():
|
| 29 |
+
return render_template('index.html', states=unique_states, crops=unique_crops, seasons=season_descriptions.keys())
|
| 30 |
+
|
| 31 |
+
@app.route('/filter_districts', methods=['POST'])
|
| 32 |
+
def filter_districts():
|
| 33 |
+
state = request.form.get('state')
|
| 34 |
+
filtered_districts = data[data['State'] == state]['District'].unique()
|
| 35 |
+
return jsonify({'districts': list(filtered_districts)})
|
| 36 |
+
|
| 37 |
+
@app.route('/predict', methods=['POST'])
|
| 38 |
+
def predict():
|
| 39 |
+
state = request.form.get('state')
|
| 40 |
+
district = request.form.get('district')
|
| 41 |
+
crop_year = int(request.form.get('crop_year'))
|
| 42 |
+
crop = request.form.get('crop')
|
| 43 |
+
area = float(request.form.get('area'))
|
| 44 |
+
|
| 45 |
+
input_data = pd.DataFrame({
|
| 46 |
+
'State': [state],
|
| 47 |
+
'District': [district],
|
| 48 |
+
'Crop_Year': [crop_year],
|
| 49 |
+
'Crop': [crop],
|
| 50 |
+
'Area': [area]
|
| 51 |
+
})
|
| 52 |
+
|
| 53 |
+
input_data['State'] = input_data['State'].astype('category')
|
| 54 |
+
input_data['District'] = input_data['District'].astype('category')
|
| 55 |
+
input_data['Crop'] = input_data['Crop'].astype('category')
|
| 56 |
+
|
| 57 |
+
predicted_season = lgb_model.predict(input_data)[0]
|
| 58 |
+
|
| 59 |
+
# Debug: print the predicted season to console
|
| 60 |
+
print(f"Predicted Season: {predicted_season}")
|
| 61 |
+
|
| 62 |
+
# Ensure the predicted season is treated as a string for matching
|
| 63 |
+
predicted_season_str = str(predicted_season) # Ensure it's a stri
|
| 64 |
+
|
| 65 |
+
# Check if the predicted season is in the descriptions
|
| 66 |
+
if predicted_season in season_descriptions:
|
| 67 |
+
season_description = season_descriptions[predicted_season]
|
| 68 |
+
else:
|
| 69 |
+
season_description = 'No description available'
|
| 70 |
+
|
| 71 |
+
return render_template('index.html', states=unique_states, crops=unique_crops, seasons=season_descriptions.keys(),
|
| 72 |
+
predicted_season=predicted_season, season_description=season_description)
|
| 73 |
+
|
| 74 |
+
if __name__ == '__main__':
|
| 75 |
+
app.run(debug=True)
|
final_crop_data.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:83c54ae9f15d0d1aa3ddc838f73545f5cacad2f11013c3a011f4c0e72427c882
|
| 3 |
+
size 22400747
|
lgb_model_cropseason.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ec9b8113287f7e66b67af3f2674c85db73d6129adf0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|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Optimal Croping Season Prediction</title>
|
| 7 |
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
| 8 |
+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
| 9 |
+
<style>
|
| 10 |
+
body {
|
| 11 |
+
background-color: #e6f5e6; /* Light green background */
|
| 12 |
+
font-family: Arial, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
.container {
|
| 15 |
+
margin: 30px auto;
|
| 16 |
+
padding: 20px;
|
| 17 |
+
background-color: #f9f9f9; /* Slightly off-white background */
|
| 18 |
+
border-radius: 10px;
|
| 19 |
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
|
| 20 |
+
border: 2px solid #2c662d; /* Dark green border */
|
| 21 |
+
}
|
| 22 |
+
h1 {
|
| 23 |
+
color: #2c662d; /* Dark green for headings */
|
| 24 |
+
text-align: center;
|
| 25 |
+
margin-bottom: 30px;
|
| 26 |
+
font-weight: bold;
|
| 27 |
+
}
|
| 28 |
+
.form-group {
|
| 29 |
+
margin-bottom: 15px;
|
| 30 |
+
}
|
| 31 |
+
.form-control {
|
| 32 |
+
border: 2px solid #2c662d; /* Dark green border */
|
| 33 |
+
border-radius: 5px;
|
| 34 |
+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
| 35 |
+
transition: border-color 0.3s;
|
| 36 |
+
}
|
| 37 |
+
.form-control:focus {
|
| 38 |
+
border-color: #4CAF50; /* Lighter green on focus */
|
| 39 |
+
box-shadow: 0 0 5px rgba(76, 175, 80, 0.5);
|
| 40 |
+
}
|
| 41 |
+
.btn-success {
|
| 42 |
+
background-color: #2c662d; /* Dark green */
|
| 43 |
+
border: none;
|
| 44 |
+
transition: background-color 0.3s, transform 0.3s;
|
| 45 |
+
}
|
| 46 |
+
.btn-success:hover {
|
| 47 |
+
background-color: #4CAF50; /* Lighter green on hover */
|
| 48 |
+
transform: scale(1.05);
|
| 49 |
+
}
|
| 50 |
+
.btn-success:active {
|
| 51 |
+
transform: scale(0.95);
|
| 52 |
+
}
|
| 53 |
+
.image-preview {
|
| 54 |
+
margin-bottom: 30px;
|
| 55 |
+
width: 100%;
|
| 56 |
+
height: auto;
|
| 57 |
+
border-radius: 10px;
|
| 58 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
|
| 59 |
+
}
|
| 60 |
+
.result-box {
|
| 61 |
+
margin-top: 30px;
|
| 62 |
+
padding: 20px;
|
| 63 |
+
background-color: #e8f5e9;
|
| 64 |
+
border: 2px solid #2c662d;
|
| 65 |
+
border-radius: 10px;
|
| 66 |
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
|
| 67 |
+
}
|
| 68 |
+
</style>
|
| 69 |
+
</head>
|
| 70 |
+
<body>
|
| 71 |
+
|
| 72 |
+
<div class="container">
|
| 73 |
+
<h1>Optimal Croping Season Prediction</h1>
|
| 74 |
+
<div class="row">
|
| 75 |
+
<div class="col-md-7">
|
| 76 |
+
<form id="prediction-form" method="POST" action="/predict">
|
| 77 |
+
<div class="form-group">
|
| 78 |
+
<label for="state">State</label>
|
| 79 |
+
<select id="state" name="state" class="form-control" required>
|
| 80 |
+
<option value="">Select State</option>
|
| 81 |
+
{% for state in states %}
|
| 82 |
+
<option value="{{ state }}">{{ state }}</option>
|
| 83 |
+
{% endfor %}
|
| 84 |
+
</select>
|
| 85 |
+
</div>
|
| 86 |
+
<div class="form-group">
|
| 87 |
+
<label for="district">Select District</label>
|
| 88 |
+
<select id="district" name="district" class="form-control" required>
|
| 89 |
+
<option value="">Select District</option>
|
| 90 |
+
</select>
|
| 91 |
+
</div>
|
| 92 |
+
<div class="form-group">
|
| 93 |
+
<label for="crop_year">Enter the Croping Year (2024 & onwards)</label>
|
| 94 |
+
<input type="number" id="crop_year" name="crop_year" class="form-control" min="2000" required>
|
| 95 |
+
</div>
|
| 96 |
+
<div class="form-group">
|
| 97 |
+
<label for="crop">Select Crop Type</label>
|
| 98 |
+
<select id="crop" name="crop" class="form-control" required>
|
| 99 |
+
{% for crop in crops %}
|
| 100 |
+
<option value="{{ crop }}">{{ crop }}</option>
|
| 101 |
+
{% endfor %}
|
| 102 |
+
</select>
|
| 103 |
+
</div>
|
| 104 |
+
<div class="form-group">
|
| 105 |
+
<label for="area">Enter Area (in hectares)</label>
|
| 106 |
+
<input type="number" id="area" name="area" class="form-control" step="0.01" required>
|
| 107 |
+
</div>
|
| 108 |
+
<button type="submit" class="btn btn-success btn-block">Predict Season</button>
|
| 109 |
+
</form>
|
| 110 |
+
{% if predicted_season %}
|
| 111 |
+
<div class="result-box">
|
| 112 |
+
<h4>Predicted Optimal Croping Season: <span id="predicted-season">{{ predicted_season }}</span></h4>
|
| 113 |
+
<p id="season-description">{{ season_description }}</p>
|
| 114 |
+
</div>
|
| 115 |
+
{% endif %}
|
| 116 |
+
</div>
|
| 117 |
+
<div class="col-md-5">
|
| 118 |
+
<img src="/static/img1.jpg" alt="Crop Image" class="image-preview">
|
| 119 |
+
</div>
|
| 120 |
+
</div>
|
| 121 |
+
</div>
|
| 122 |
+
|
| 123 |
+
<script>
|
| 124 |
+
$(document).ready(function(){
|
| 125 |
+
$('#state').change(function(){
|
| 126 |
+
const state = $(this).val();
|
| 127 |
+
$.ajax({
|
| 128 |
+
url: '/filter_districts',
|
| 129 |
+
method: 'POST',
|
| 130 |
+
data: { state: state },
|
| 131 |
+
success: function(response) {
|
| 132 |
+
$('#district').empty().append('<option value="">Select District</option>');
|
| 133 |
+
response.districts.forEach(function(district) {
|
| 134 |
+
$('#district').append('<option value="'+district+'">'+district+'</option>');
|
| 135 |
+
});
|
| 136 |
+
}
|
| 137 |
+
});
|
| 138 |
+
});
|
| 139 |
+
|
| 140 |
+
// Hardcoded descriptions for each season
|
| 141 |
+
const seasonDescriptions = {
|
| 142 |
+
'Kharif': 'Kharif season occurs from June to October, associated with the monsoon. Crops are usually sown at the start of the rainy season.',
|
| 143 |
+
'Rabi': 'Rabi season spans from October to March, during the winter cropping season, with crops like wheat and barley.',
|
| 144 |
+
'Summer': 'Summer season is from April to June, suitable for crops that need warmer temperatures.',
|
| 145 |
+
'Winter': 'Winter cropping season occurs from November to February, including cold-weather crops.',
|
| 146 |
+
'Whole Year': 'Crops can be grown throughout the year, without seasonal limitations.',
|
| 147 |
+
'Autumn': 'Autumn season, from September to November, accommodates crops suited to a post-monsoon environment.'
|
| 148 |
+
};
|
| 149 |
+
|
| 150 |
+
// Show description based on predicted season
|
| 151 |
+
const predictedSeason = document.getElementById('predicted-season').innerText;
|
| 152 |
+
if (predictedSeason) {
|
| 153 |
+
document.getElementById('season-description').innerText = seasonDescriptions[predictedSeason] || 'No description available';
|
| 154 |
+
}
|
| 155 |
+
});
|
| 156 |
+
</script>
|
| 157 |
+
|
| 158 |
+
</body>
|
| 159 |
+
</html>
|