Commit
•
77f6ae5
1
Parent(s):
e454685
Upload 13 files
Browse files- Crop_Recommendation.py +373 -0
- Crop_yield.py +270 -0
- Lasso Regression.pkl +3 -0
- Mail.py +19 -0
- crop_recommendation.pickle +3 -0
- crop_yield.csv +0 -0
- crop_yield_model.pkl +3 -0
- feedbacko.csv +2 -0
- feedbacko.py +28 -0
- gross_premimum.py +178 -0
- insurance(R).csv +0 -0
- insurance.csv +0 -0
- model.h5 +3 -0
Crop_Recommendation.py
ADDED
@@ -0,0 +1,373 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
|
4 |
+
import requests
|
5 |
+
import pandas as pd
|
6 |
+
import numpy as np
|
7 |
+
import pickle as pk
|
8 |
+
import streamlit as st
|
9 |
+
import time
|
10 |
+
import Weather_app as wa
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
import warnings
|
16 |
+
warnings.filterwarnings("ignore")
|
17 |
+
data = pd.read_csv("Crop_recommendation.csv")
|
18 |
+
data_new = data.copy(deep = True)
|
19 |
+
|
20 |
+
from sklearn.preprocessing import LabelEncoder
|
21 |
+
|
22 |
+
le = LabelEncoder()
|
23 |
+
data["Crop"] = le.fit_transform(data["label"])
|
24 |
+
|
25 |
+
data.drop(columns = ["label"], inplace = True)
|
26 |
+
|
27 |
+
@st.cache_resource
|
28 |
+
def recmod():
|
29 |
+
return pk.load(open('crop_recommendation.pickle','rb'))
|
30 |
+
recommendation_model = recmod()
|
31 |
+
|
32 |
+
def crop_encoding(Predicted_value):
|
33 |
+
Predicted_value = (data_new[data.Crop == Predicted_value]["label"]).to_list()[0]
|
34 |
+
return Predicted_value
|
35 |
+
|
36 |
+
def Crop_recommendation_function(crop_data_input):
|
37 |
+
crop_data_asarray = np.asarray(crop_data_input)
|
38 |
+
crop_data_reshaped = crop_data_asarray.reshape(1, -1)
|
39 |
+
crop_recommended = recommendation_model.predict(crop_data_reshaped)[0] # Extract the result
|
40 |
+
crop = crop_encoding(crop_recommended)
|
41 |
+
return crop
|
42 |
+
def Crop_recommendation_function2(input_data_speed):
|
43 |
+
# crop_data_asarray = np.array(input_data_speed).reshape(1, -1)
|
44 |
+
|
45 |
+
# Make predictions using the loaded model
|
46 |
+
# predictions = loaded_data.predict(crop_data_asarray)[0]
|
47 |
+
|
48 |
+
|
49 |
+
# modaa = pk.load(open('Soli_to_recommandation_model_Raghuu.pkl', 'rb'))
|
50 |
+
with open('Soli_to_recommandation_model_Raghuu.pkl', 'rb') as file:
|
51 |
+
loaded_model = pk.load(file)
|
52 |
+
# input_data = np.array(input_data_speed).reshape(1, -1)
|
53 |
+
mapp = {'Pomegranate': 10,
|
54 |
+
'Banana': 2,
|
55 |
+
'Mango': 6,
|
56 |
+
'Grapes': 4,
|
57 |
+
'Peach': 9,
|
58 |
+
'Black Berry': 3,
|
59 |
+
'Apple': 0,
|
60 |
+
'Orange': 7,
|
61 |
+
'Papaya': 8,
|
62 |
+
'Guava': 5,
|
63 |
+
'Apricot': 1}
|
64 |
+
|
65 |
+
criop =loaded_model.predict(input_data_speed)[0]
|
66 |
+
predicted_label = [key for key, value in mapp.items() if value == criop][0]
|
67 |
+
|
68 |
+
return predicted_label
|
69 |
+
|
70 |
+
|
71 |
+
# def get_weather_details(city_name):
|
72 |
+
# base_url = "https://api.openweathermap.org/data/2.5/weather"
|
73 |
+
# params = {
|
74 |
+
# 'q': city_name,
|
75 |
+
# 'appid': "d73ec4f18aca81c32b1836a8ac2506e0"
|
76 |
+
# }
|
77 |
+
|
78 |
+
# try:
|
79 |
+
# response = requests.get(base_url, params=params)
|
80 |
+
# data = response.json()
|
81 |
+
|
82 |
+
# # Check if the request was successful
|
83 |
+
# if response.status_code == 200:
|
84 |
+
# # Extract weather details
|
85 |
+
# weather_details = {
|
86 |
+
# 'temperature': data['main']['temp'],
|
87 |
+
# 'humidity': data['main']['humidity']
|
88 |
+
# }
|
89 |
+
# return weather_details
|
90 |
+
# else:
|
91 |
+
# st.write("Error {}: {}".format(response.status_code, data['message']))
|
92 |
+
# return None
|
93 |
+
# except Exception as e:
|
94 |
+
# st.write("An error occurred:", e)
|
95 |
+
# return None
|
96 |
+
|
97 |
+
def run_crop_recommendation():
|
98 |
+
st.title('Crop Recommendation')
|
99 |
+
background_image = 'https://c1.wallpaperflare.com/preview/436/828/940/clouds-summer-storm-clouds-form.jpg'
|
100 |
+
html_code = f"""
|
101 |
+
<style>
|
102 |
+
body {{
|
103 |
+
background-image: url('{background_image}');
|
104 |
+
background-size: cover;
|
105 |
+
background-position: center;
|
106 |
+
background-repeat: no-repeat;
|
107 |
+
height: 100vh; /* Set the height of the background to fill the viewport */
|
108 |
+
margin: 0; /* Remove default body margin */
|
109 |
+
display: flex;
|
110 |
+
flex-direction: column;
|
111 |
+
justify-content: center;
|
112 |
+
align-items: center;
|
113 |
+
}}
|
114 |
+
.stApp {{
|
115 |
+
background: none; /* Remove Streamlit app background */
|
116 |
+
}}
|
117 |
+
</style>
|
118 |
+
"""
|
119 |
+
tab1, tab2, tab3= st.tabs(['Based On Land And Water', 'Based On Fertilizers','Feedback'])
|
120 |
+
# st.title("Crop Recommendation System")
|
121 |
+
with tab1:
|
122 |
+
|
123 |
+
try:
|
124 |
+
weather_details = wa.get_weather_details(wa.city_name)
|
125 |
+
# Load the trained model
|
126 |
+
@st.cache_resource
|
127 |
+
def soli():
|
128 |
+
return pk.load(open('Soli_to_recommandation_model_Simha.pkl', 'rb'))
|
129 |
+
|
130 |
+
|
131 |
+
loaded_model = soli()
|
132 |
+
|
133 |
+
# Streamlit UI
|
134 |
+
# st.title("Crop Recommendation System")
|
135 |
+
|
136 |
+
# Input features for prediction
|
137 |
+
col1, col2 = st.columns(2)
|
138 |
+
with col1:
|
139 |
+
Soil_EC = st.selectbox(("Soil_EC Siemens per meter (S/m)"),(1,2,3,4),3)
|
140 |
+
with col2:
|
141 |
+
Water_TDS = st.selectbox(("Water_TDS"),(1,2,3,4,5,6),5)
|
142 |
+
if weather_details:
|
143 |
+
Temprature = weather_details['temperature']
|
144 |
+
Humidity = weather_details['humidity']
|
145 |
+
col3,col4 = st.columns(2)
|
146 |
+
with col3:
|
147 |
+
|
148 |
+
Ph = st.number_input("acidity or alkalinity",value=8.0, min_value= 0.0, max_value= 14.0, step=0.5)
|
149 |
+
with col4:
|
150 |
+
Rain_Fall = st.number_input("Rain_Fall in (mm) ", min_value=50.0,value=100.97,max_value=500.0)
|
151 |
+
|
152 |
+
# Reshape input data for prediction
|
153 |
+
input_data = np.array([Soil_EC, Water_TDS, Temprature, Humidity, Ph, Rain_Fall]).reshape(1, -1)
|
154 |
+
|
155 |
+
# Make prediction
|
156 |
+
mapp = {'Pomegranate': 10,
|
157 |
+
'Banana': 2,
|
158 |
+
'Mango': 6,
|
159 |
+
'Grapes': 4,
|
160 |
+
'Peach': 9,
|
161 |
+
'Black Berry': 3,
|
162 |
+
'Apple': 0,
|
163 |
+
'Orange': 7,
|
164 |
+
'Papaya': 8,
|
165 |
+
'Guava': 5,
|
166 |
+
'Apricot': 1}
|
167 |
+
crop_image_urls = {'Wheat': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRIp7ucodsB63giF1CvVjBtbHf14Px83ck2hcZRUJlMxA&s',
|
168 |
+
'Rice': 'https://media.istockphoto.com/id/153737841/photo/rice.webp?b=1&s=170667a&w=0&k=20&c=SF6Ks-8AYpbPTnZlGwNCbCFUh-0m3R5sM2hl-C5r_Xc=',
|
169 |
+
'Maize (Corn)': 'https://plus.unsplash.com/premium_photo-1667047165840-803e47970128?q=80&w=1000&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MXx8bWFpemV8ZW58MHx8MHx8fDA%3D',
|
170 |
+
'Bajra (Pearl millet)': 'https://media.istockphoto.com/id/1400438871/photo/pear-millet-background.jpg?s=612x612&w=0&k=20&c=0GlBeceuX9Q_AZ0-CH57_A5s7_tD769N2f_jrbNcbrw=',
|
171 |
+
'Jowar (Sorghum)': 'https://media.istockphoto.com/id/1262684430/photo/closeup-view-of-a-white-millet-jowar.jpg?s=612x612&w=0&k=20&c=HLyBy06EjbABKybUy1nIQTfxMLV1-s4xofGigOdd6dU=',
|
172 |
+
'Barley': 'https://www.poshtik.in/cdn/shop/products/com1807851487263barley_Poshtik_c1712f8e-6b63-4231-9596-a49ce84f26ba.png?v=1626004318',
|
173 |
+
'Gram (Chickpea)': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHtf9ivxD23Bp_-VOY4H2tCRMC0_znhzyAEt2jfzvUlskEZcv0',
|
174 |
+
'Tur (Pigeonpea)': 'https://rukminim2.flixcart.com/image/850/1000/xif0q/plant-seed/f/l/n/25-pigeon-pea-for-planting-home-garden-farming-vegetable-kitchen-original-imaghphgmepkjqfz.jpeg?q=90',
|
175 |
+
'Moong (Green Gram)': 'https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTyIa1Wq11MaHZ_cIdArPjZSR8cnr85STU83QsjKvkI9xNdVDjJ',
|
176 |
+
'Urad (Black gram)': 'https://encrypted-tbn0.gstatic.com/licensed-image?q=tbn:ANd9GcRl-eFmBSLAHxB7U_b_SQNptQoQpi585JWgpqU0LH0jmvmrp9mESzQrL3ieox6ICl_-v7rzl38Pi7faf-4',
|
177 |
+
'Masoor (Red lentil)': 'https://www.vegrecipesofindia.com/wp-content/uploads/2022/11/masoor-dal-red-lentils.jpg',
|
178 |
+
'Groundnut (Peanut)': 'https://www.netmeds.com/images/cms/wysiwyg/blog/2019/10/Groundnut_big_2.jpg',
|
179 |
+
'Sesamum (Sesame)': 'https://encrypted-tbn0.gstatic.com/licensed-image?q=tbn:ANd9GcThAjpal-k0urS19A2NEoVW35yqF9ljlvx1d-amDokoIiHZ9-RGyUsDaiVcr7SdfwsFjP-I6U1_VYeiEc0',
|
180 |
+
'Castor seed': 'https://5.imimg.com/data5/QV/VN/MY-3966004/caster-seeds.jpg',
|
181 |
+
'Sunflower': 'https://t0.gstatic.com/licensed-image?q=tbn:ANd9GcRuCcoGrqSVqOzxFU9rHPsWKxaHpm7i_srXQPMHaVfrrDmz4eXc5PGWpQFfpAr8qaH2',
|
182 |
+
'Safflower': 'https://upload.wikimedia.org/wikipedia/commons/7/7f/Safflower.jpg',
|
183 |
+
'Sugarcane': 'https://www.saveur.com/uploads/2022/03/05/sugarcane-linda-xiao.jpg?auto=webp',
|
184 |
+
'Cotton (lint)': 'https://img2.tradewheel.com/uploads/images/products/6/0/0048590001615360690-cotton-lint.jpeg.webp',
|
185 |
+
'Jute': 'https://rukminim2.flixcart.com/image/850/1000/kuk4u4w0/rope/d/k/f/2-jute-cord-for-craft-project-natural-jute-rope-jute-thread-original-imag7nrjbkrmgbpm.jpeg?q=20',
|
186 |
+
'Potato': 'https://cdn.mos.cms.futurecdn.net/iC7HBvohbJqExqvbKcV3pP.jpg',
|
187 |
+
'Onion': 'https://familyneeds.co.in/cdn/shop/products/2_445fc9bd-1bab-4bfb-8d5d-70b692745567_600x600.jpg?v=1600812246',
|
188 |
+
'Tomato': 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/89/Tomato_je.jpg/1200px-Tomato_je.jpg',
|
189 |
+
'Banana': 'https://fruitboxco.com/cdn/shop/products/asset_2_grande.jpg?v=1571839043',
|
190 |
+
'Coconut': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS_rZgOJry6Twt8urk4C1FTo6d6tEDyiIw39w&usqp=CAU',
|
191 |
+
'Mango': "https://i.pinimg.com/474x/70/bd/5f/70bd5f8fd50d30bfcab3ac0f27ff4202.jpg",
|
192 |
+
'Orange': "https://images.unsplash.com/photo-1611080626919-7cf5a9dbab5b?q=80&w=1000&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8b3Jhbmdlc3xlbnwwfHwwfHx8MA%3D%3D",
|
193 |
+
"Pomegranate": "https://thumbs.dreamstime.com/b/juicy-pomegranate-its-half-leaves-16537522.jpg",
|
194 |
+
"Banana": "https://media.istockphoto.com/id/173242750/photo/banana-bunch.jpg?s=612x612&w=0&k=20&c=MAc8AXVz5KxwWeEmh75WwH6j_HouRczBFAhulLAtRUU=",
|
195 |
+
"Grapes": "https://cf.ltkcdn.net/wine/images/std/165373-800x532r1-grapes.jpg",
|
196 |
+
"Peach": "https://www.shutterstock.com/image-photo/peaches-isolated-ripe-peach-half-260nw-2189388721.jpg",
|
197 |
+
"Black Berry": "https://example.com/blackberry.jpg",
|
198 |
+
"Apple": "https://images.unsplash.com/photo-1560806887-1e4cd0b6cbd6?q=80&w=1000&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxleHBsb3JlLWZlZWR8Nnx8fGVufDB8fHx8fA%3D%3D",
|
199 |
+
"Papaya": "https://media.istockphoto.com/id/864053288/photo/whole-and-half-of-ripe-papaya-fruit-with-seeds-isolated-on-white-background.jpg?s=612x612&w=0&k=20&c=hJ5DpNTt0oKjZMIHYV6gUHTntB2zIs_78dPKiuDUXgE=",
|
200 |
+
"Guava": "https://media.istockphoto.com/id/1224636159/photo/closeup-of-a-red-guava-cut-in-half-in-the-background-several-guavas-and-green-leaf.jpg?s=612x612&w=0&k=20&c=KJ9YilkRRuFh0bnw64Ol0IZDfoQF7UIxyC6dRVIjaoA=",
|
201 |
+
"Apricot": "https://www.shutterstock.com/image-photo/apricot-isolated-apricots-on-white-600nw-1963600408.jpg",
|
202 |
+
"Kidneybeans": "https://www.healthifyme.com/blog/wp-content/uploads/2022/01/807716893sst1641271427-scaled.jpg",
|
203 |
+
"Chickpea": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHtf9ivxD23Bp_-VOY4H2tCRMC0_znhzyAEt2jfzvUlskEZcv0"}
|
204 |
+
|
205 |
+
def get_crop_image_url(crop_name):
|
206 |
+
return crop_image_urls.get(crop_name, None)
|
207 |
+
|
208 |
+
if st.button("Submit", key=32):
|
209 |
+
prediction = loaded_model.predict(input_data)
|
210 |
+
predicted_label = [key for key, value in mapp.items() if value == prediction][0]
|
211 |
+
st.success(f"The predicted fruit is: {predicted_label}")
|
212 |
+
|
213 |
+
crop_image_url = get_crop_image_url(predicted_label.capitalize())
|
214 |
+
|
215 |
+
if crop_image_url is None:
|
216 |
+
st.warning("No image found for the predicted fruit.")
|
217 |
+
else:
|
218 |
+
try:
|
219 |
+
st.markdown(f'<img src="{crop_image_url}" alt="Image for {predicted_label}" style="width:300px; height:300px;">', unsafe_allow_html=True)
|
220 |
+
except Exception as e:
|
221 |
+
st.warning(f"Error displaying image: {e}")
|
222 |
+
|
223 |
+
|
224 |
+
|
225 |
+
except AttributeError:
|
226 |
+
st.warning("Please Select the city")
|
227 |
+
|
228 |
+
# col1, col2 = st.columns(2)
|
229 |
+
# with col1:
|
230 |
+
# Soil_EC = st.selectbox(('Soil conductivity'),(1,2,3,4),2,key = 3)
|
231 |
+
# with col2:
|
232 |
+
# Water_TDS = st.selectbox(('Water solvents'),(1,2,3,4,5,6),3,key = 4)
|
233 |
+
# col3,col4 = st.columns([3,1])
|
234 |
+
# with col3:
|
235 |
+
# Ph = st.slider("Enter ph",1,14,(1,7))
|
236 |
+
# with col4:
|
237 |
+
# Rain_Fall = st.number_input("Enter Annual Rainfall in mm", min_value=10.0, max_value=2000.0)
|
238 |
+
# weather_details = wa.get_weather_details(wa.city_name)
|
239 |
+
|
240 |
+
|
241 |
+
|
242 |
+
# if weather_details:
|
243 |
+
# Temperature = (weather_details['temperature'])
|
244 |
+
# Humidity =(weather_details['humidity'])
|
245 |
+
# st.write(Temperature)
|
246 |
+
# st.write(Humidity)
|
247 |
+
# input_data = [Soil_EC,Water_TDS,Temperature,Humidity,Ph,Rain_Fall]
|
248 |
+
# if st.button('Submit',key = 1):
|
249 |
+
# input_data = np.asarray(input_data).reshape(1, -1)
|
250 |
+
|
251 |
+
# crop_pred = Crop_recommendation_function2(input_data)
|
252 |
+
|
253 |
+
# progress = st.progress(0)
|
254 |
+
# for i in range(100):
|
255 |
+
# time.sleep(0.005)
|
256 |
+
# progress.progress(i+1)
|
257 |
+
# st.subheader(f"Crop Recommendation: {crop_pred.capitalize()}")
|
258 |
+
|
259 |
+
# crop_image_url = get_crop_image_url(crop_pred)
|
260 |
+
# try:
|
261 |
+
# st.image(crop_image_url, caption=f"Image for {crop_prediction.capitalize()}", use_column_width=True)
|
262 |
+
# except:
|
263 |
+
# pass
|
264 |
+
|
265 |
+
|
266 |
+
|
267 |
+
with tab2:
|
268 |
+
|
269 |
+
st.markdown(html_code, unsafe_allow_html=True)
|
270 |
+
|
271 |
+
col1, col2 = st.columns(2)
|
272 |
+
nitrogen = col1.selectbox('Enter Nitrogen (e.g., in kg/ha)',(0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140),key = 0)
|
273 |
+
phosphorus = col2.selectbox('Enter Phosphorus (e.g., in kg/ha)',(0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 120, 125, 130, 135, 140, 145),key = 13)
|
274 |
+
potassium = col1.selectbox('Enter Potassium (e.g., in kg/ha)',(0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 185, 190, 195, 200, 205),key = 2)
|
275 |
+
|
276 |
+
# Get weather details
|
277 |
+
# city_name = st.text_input("Enter City Name for Weather Details")
|
278 |
+
weather_details = wa.get_weather_details(wa.city_name)
|
279 |
+
ph = col2.slider('Enter pH value',value=6.502985,min_value=0.0,max_value=14.0,step=0.5)
|
280 |
+
rainfall = col1.number_input('Enter Rainfall (e.g., in mm)',value=202.935536,min_value=25.0,max_value=1000.0,step=5.0)
|
281 |
+
|
282 |
+
|
283 |
+
if weather_details:
|
284 |
+
temperature = weather_details['temperature']
|
285 |
+
humidity = weather_details['humidity']
|
286 |
+
|
287 |
+
|
288 |
+
crop_input = ''
|
289 |
+
|
290 |
+
def get_crop_image_url(crop_name):
|
291 |
+
# You need to replace the following with the actual URLs or paths of your crop images
|
292 |
+
crop_image_urls = {'Wheat': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRIp7ucodsB63giF1CvVjBtbHf14Px83ck2hcZRUJlMxA&s',
|
293 |
+
'Rice': 'https://media.istockphoto.com/id/153737841/photo/rice.webp?b=1&s=170667a&w=0&k=20&c=SF6Ks-8AYpbPTnZlGwNCbCFUh-0m3R5sM2hl-C5r_Xc=',
|
294 |
+
'Maize (Corn)': 'https://plus.unsplash.com/premium_photo-1667047165840-803e47970128?q=80&w=1000&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MXx8bWFpemV8ZW58MHx8MHx8fDA%3D',
|
295 |
+
'Bajra (Pearl millet)': 'https://media.istockphoto.com/id/1400438871/photo/pear-millet-background.jpg?s=612x612&w=0&k=20&c=0GlBeceuX9Q_AZ0-CH57_A5s7_tD769N2f_jrbNcbrw=',
|
296 |
+
'Jowar (Sorghum)': 'https://media.istockphoto.com/id/1262684430/photo/closeup-view-of-a-white-millet-jowar.jpg?s=612x612&w=0&k=20&c=HLyBy06EjbABKybUy1nIQTfxMLV1-s4xofGigOdd6dU=',
|
297 |
+
'Barley': 'https://www.poshtik.in/cdn/shop/products/com1807851487263barley_Poshtik_c1712f8e-6b63-4231-9596-a49ce84f26ba.png?v=1626004318',
|
298 |
+
'Gram (Chickpea)': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHtf9ivxD23Bp_-VOY4H2tCRMC0_znhzyAEt2jfzvUlskEZcv0',
|
299 |
+
'Tur (Pigeonpea)': 'https://rukminim2.flixcart.com/image/850/1000/xif0q/plant-seed/f/l/n/25-pigeon-pea-for-planting-home-garden-farming-vegetable-kitchen-original-imaghphgmepkjqfz.jpeg?q=90',
|
300 |
+
'Moong (Green Gram)': 'https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTyIa1Wq11MaHZ_cIdArPjZSR8cnr85STU83QsjKvkI9xNdVDjJ',
|
301 |
+
'Urad (Black gram)': 'https://encrypted-tbn0.gstatic.com/licensed-image?q=tbn:ANd9GcRl-eFmBSLAHxB7U_b_SQNptQoQpi585JWgpqU0LH0jmvmrp9mESzQrL3ieox6ICl_-v7rzl38Pi7faf-4',
|
302 |
+
'Masoor (Red lentil)': 'https://www.vegrecipesofindia.com/wp-content/uploads/2022/11/masoor-dal-red-lentils.jpg',
|
303 |
+
'Groundnut (Peanut)': 'https://www.netmeds.com/images/cms/wysiwyg/blog/2019/10/Groundnut_big_2.jpg',
|
304 |
+
'Sesamum (Sesame)': 'https://encrypted-tbn0.gstatic.com/licensed-image?q=tbn:ANd9GcThAjpal-k0urS19A2NEoVW35yqF9ljlvx1d-amDokoIiHZ9-RGyUsDaiVcr7SdfwsFjP-I6U1_VYeiEc0',
|
305 |
+
'Castor seed': 'https://5.imimg.com/data5/QV/VN/MY-3966004/caster-seeds.jpg',
|
306 |
+
'Sunflower': 'https://t0.gstatic.com/licensed-image?q=tbn:ANd9GcRuCcoGrqSVqOzxFU9rHPsWKxaHpm7i_srXQPMHaVfrrDmz4eXc5PGWpQFfpAr8qaH2',
|
307 |
+
'Safflower': 'https://upload.wikimedia.org/wikipedia/commons/7/7f/Safflower.jpg',
|
308 |
+
'Sugarcane': 'https://www.saveur.com/uploads/2022/03/05/sugarcane-linda-xiao.jpg?auto=webp',
|
309 |
+
'Cotton (lint)': 'https://img2.tradewheel.com/uploads/images/products/6/0/0048590001615360690-cotton-lint.jpeg.webp',
|
310 |
+
'Jute': 'https://rukminim2.flixcart.com/image/850/1000/kuk4u4w0/rope/d/k/f/2-jute-cord-for-craft-project-natural-jute-rope-jute-thread-original-imag7nrjbkrmgbpm.jpeg?q=20',
|
311 |
+
'Potato': 'https://cdn.mos.cms.futurecdn.net/iC7HBvohbJqExqvbKcV3pP.jpg',
|
312 |
+
'Onion': 'https://familyneeds.co.in/cdn/shop/products/2_445fc9bd-1bab-4bfb-8d5d-70b692745567_600x600.jpg?v=1600812246',
|
313 |
+
'Tomato': 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/89/Tomato_je.jpg/1200px-Tomato_je.jpg',
|
314 |
+
'Banana': 'https://fruitboxco.com/cdn/shop/products/asset_2_grande.jpg?v=1571839043',
|
315 |
+
'Coconut': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS_rZgOJry6Twt8urk4C1FTo6d6tEDyiIw39w&usqp=CAU',
|
316 |
+
'Mango': "https://i.pinimg.com/474x/70/bd/5f/70bd5f8fd50d30bfcab3ac0f27ff4202.jpg",
|
317 |
+
'Orange': "https://images.unsplash.com/photo-1611080626919-7cf5a9dbab5b?q=80&w=1000&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8b3Jhbmdlc3xlbnwwfHwwfHx8MA%3D%3D",
|
318 |
+
"Kidneybeans": "https://www.healthifyme.com/blog/wp-content/uploads/2022/01/807716893sst1641271427-scaled.jpg",
|
319 |
+
"Chickpea": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHtf9ivxD23Bp_-VOY4H2tCRMC0_znhzyAEt2jfzvUlskEZcv0",
|
320 |
+
"Grapes": "https://rukminim2.flixcart.com/image/850/1000/kt0enww0/plant-seed/h/h/n/25-dg-214-paudha-original-imag6fgvre6bmd5y.jpeg?q=90&crop=false",
|
321 |
+
"Coffee": "https://www.agrifarming.in/wp-content/uploads/2017/06/Coffee-Growing.-1.jpg"}
|
322 |
+
if crop_name not in crop_image_urls.keys():
|
323 |
+
return None
|
324 |
+
else:
|
325 |
+
return crop_image_urls[crop_name]
|
326 |
+
|
327 |
+
if st.button('Submit'):
|
328 |
+
crop_input = [nitrogen, phosphorus, potassium, temperature, humidity, ph, rainfall]
|
329 |
+
crop_prediction = Crop_recommendation_function(crop_input)
|
330 |
+
|
331 |
+
progress = st.progress(0)
|
332 |
+
for i in range(100):
|
333 |
+
time.sleep(0.005)
|
334 |
+
progress.progress(i+1)
|
335 |
+
st.subheader(f"Crop Recommendation: {crop_prediction.capitalize()}")
|
336 |
+
|
337 |
+
crop_image_url = get_crop_image_url(crop_prediction.capitalize())
|
338 |
+
try:
|
339 |
+
st.image(crop_image_url, caption=f"Image for {crop_prediction.capitalize()}", use_column_width=True)
|
340 |
+
except:
|
341 |
+
pass
|
342 |
+
|
343 |
+
with tab3:
|
344 |
+
df = pd.read_csv('Crop_recommendation.csv')
|
345 |
+
st.write('Current Dataset',df)
|
346 |
+
col1, col2 = st.columns(2)
|
347 |
+
nitrogen = col1.selectbox('Enter Nitrogen (e.g., in kg/ha)',(0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140),key = 20)
|
348 |
+
phosphorus = col2.selectbox('Enter Phosphorus (e.g., in kg/ha)',(0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 120, 125, 130, 135, 140, 145),key = 143)
|
349 |
+
potassium = col1.selectbox('Enter Potassium (e.g., in kg/ha)',(0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 185, 190, 195, 200, 205),key = 21)
|
350 |
+
temperature = col2.number_input('Enter temprature',max_value=45.0,min_value=8.0,value=32.0,step = 2.0,key = 232)
|
351 |
+
humidity = col1.number_input('Enter Humidity',value=80.47,max_value=99.98,min_value=14.25,step = 2.0,key = 103)
|
352 |
+
ph = col2.slider('Enter pH value',value=6.502985,min_value=0.0,max_value=14.0,step=0.5,key = 104)
|
353 |
+
rainfall = col1.number_input('Enter Rainfall (e.g., in mm)',value=202.935536,min_value=25.0,max_value=1000.0,step=5.0,key = 105)
|
354 |
+
label = col1.selectbox('Enter the crop',('rice', 'maize', 'chickpea', 'kidneybeans', 'pigeonpeas',
|
355 |
+
'mothbeans', 'mungbean', 'blackgram', 'lentil', 'pomegranate',
|
356 |
+
'banana', 'mango', 'grapes', 'watermelon', 'muskmelon', 'apple',
|
357 |
+
'orange', 'papaya', 'coconut', 'cotton', 'jute', 'coffee'),key =106)
|
358 |
+
|
359 |
+
if st.button('submit'):
|
360 |
+
new_row = {'N':nitrogen, 'P':phosphorus, 'K':potassium, 'temperature':temperature, 'humidity':humidity, 'ph':ph, 'rainfall':rainfall, 'label':label}
|
361 |
+
df = df.append(new_row,ignore_index= True)
|
362 |
+
df.to_csv('Crop_recommendation.csv')
|
363 |
+
st.success("Thanks for the feedback")
|
364 |
+
st.write("Updated Dataset",df)
|
365 |
+
|
366 |
+
|
367 |
+
|
368 |
+
|
369 |
+
|
370 |
+
|
371 |
+
|
372 |
+
if __name__ == "__main__":
|
373 |
+
run_crop_recommendation()
|
Crop_yield.py
ADDED
@@ -0,0 +1,270 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import pandas as pd
|
3 |
+
import streamlit as st
|
4 |
+
import numpy as np
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
import seaborn as sns
|
7 |
+
import pickle as pk
|
8 |
+
import time
|
9 |
+
import warnings
|
10 |
+
import requests
|
11 |
+
import requests
|
12 |
+
from PIL import Image, ImageDraw, ImageFont
|
13 |
+
from geopy.geocoders import Nominatim
|
14 |
+
import geocoder
|
15 |
+
warnings.filterwarnings('ignore')
|
16 |
+
|
17 |
+
data = pd.read_csv('crop_yield.csv')
|
18 |
+
|
19 |
+
## only for encoding purpose
|
20 |
+
data_new = data.copy(deep = True)
|
21 |
+
|
22 |
+
# Apply transformation to string values in the 'Crop', 'Season', and 'State' columns
|
23 |
+
columns_to_transform = ['Crop', 'Season', 'State']
|
24 |
+
|
25 |
+
for column in columns_to_transform:
|
26 |
+
data_new[column] = data_new[column].apply(
|
27 |
+
lambda x: x.lower().replace(" ", "").replace("/", "").replace("(", "").replace(")", "") if isinstance(x, str) else x)
|
28 |
+
|
29 |
+
columns = ['Crop', 'Season', 'State']
|
30 |
+
from sklearn.preprocessing import LabelEncoder
|
31 |
+
encoder = LabelEncoder()
|
32 |
+
for col in columns:
|
33 |
+
data[col] = encoder.fit_transform(data[col])
|
34 |
+
|
35 |
+
data.drop(columns = ["Crop_Year"], inplace = True)
|
36 |
+
# @st.cache_data
|
37 |
+
def get_user_ip():
|
38 |
+
try:
|
39 |
+
response = requests.get('https://api64.ipify.org?format=json')
|
40 |
+
data = response.json()
|
41 |
+
return data.get('ip')
|
42 |
+
except Exception as e:
|
43 |
+
print(f"Error getting user IP: {e}")
|
44 |
+
return None
|
45 |
+
|
46 |
+
def apiip_net_request():
|
47 |
+
user_ip = get_user_ip()
|
48 |
+
if user_ip:
|
49 |
+
access_key = '630523ff-348e-490e-b851-ab295b5ff3fd'
|
50 |
+
url = f'https://apiip.net/api/check?ip={user_ip}&accessKey={access_key}'
|
51 |
+
|
52 |
+
try:
|
53 |
+
response = requests.get(url)
|
54 |
+
result = response.json()
|
55 |
+
return result.get('regionName')
|
56 |
+
except Exception as e:
|
57 |
+
print(f"Error making API request: {e}")
|
58 |
+
else:
|
59 |
+
print("Unable to retrieve user IP.")
|
60 |
+
|
61 |
+
|
62 |
+
IP = get_user_ip()
|
63 |
+
state_name = apiip_net_request()
|
64 |
+
|
65 |
+
|
66 |
+
# Automatic location detection using st.location
|
67 |
+
def get_weather(city):
|
68 |
+
# Using the OpenWeatherMap API to get weather information based on city name
|
69 |
+
openweathermap_api_key = "d73ec4f18aca81c32b1836a8ac2506e0"
|
70 |
+
openweathermap_url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={openweathermap_api_key}"
|
71 |
+
|
72 |
+
response = requests.get(openweathermap_url)
|
73 |
+
data = response.json()
|
74 |
+
|
75 |
+
return data.get("weather")[0].get("main")
|
76 |
+
|
77 |
+
|
78 |
+
from datetime import datetime
|
79 |
+
|
80 |
+
def get_season(month):
|
81 |
+
# Mapping of months to seasons
|
82 |
+
month_to_season = {
|
83 |
+
1: 'Winter', 2: 'Winter', 3: 'Spring',
|
84 |
+
4: 'Spring', 5: 'Spring', 6: 'Summer',
|
85 |
+
7: 'Summer', 8: 'Summer', 9: 'Autumn',
|
86 |
+
10: 'Autumn', 11: 'Autumn', 12: 'Winter'
|
87 |
+
}
|
88 |
+
|
89 |
+
# Get the season based on the month
|
90 |
+
season = month_to_season.get(month, 'Invalid Month')
|
91 |
+
|
92 |
+
return season
|
93 |
+
|
94 |
+
# Example: Get the season for a specific month
|
95 |
+
current_month = datetime.now().month
|
96 |
+
current_season = get_season(current_month)
|
97 |
+
|
98 |
+
# Example: Get the season for a specific month
|
99 |
+
current_month = datetime.now().month
|
100 |
+
current_season = get_season(current_month)
|
101 |
+
|
102 |
+
|
103 |
+
|
104 |
+
|
105 |
+
def encoding(input_data):
|
106 |
+
try:
|
107 |
+
input_data[0] = (data[data_new.Crop == input_data[0].lower().replace(" ", "").replace(" ", "").replace(" ", "").replace("/", "").replace("(", "").replace(")", "")]["Crop"]).to_list()[0]
|
108 |
+
input_data[1] = (data[data_new.Season== input_data[1].lower().replace(" ", "").replace(" ", "").replace(" ", "").replace("/", "").replace("/", "").replace("(", "").replace(")", "")]["Season"]).to_list()[0]
|
109 |
+
input_data[2] = (data[data_new.State== input_data[2].lower().replace(" ", "").replace(" ", "").replace(" ", "").replace("/", "").replace("(", "").replace(")", "")]["State"]).to_list()[0]
|
110 |
+
return input_data
|
111 |
+
except:
|
112 |
+
return None
|
113 |
+
|
114 |
+
|
115 |
+
crop_yield_model = pk.load(open('crop_yield_model.pkl','rb'))
|
116 |
+
|
117 |
+
def crop_yield_prediction(input_data):
|
118 |
+
input_data_asarray = np.asarray(input_data)
|
119 |
+
input_data_reshaped = input_data_asarray.reshape(1,-1)
|
120 |
+
prediction = crop_yield_model.predict(input_data_reshaped)
|
121 |
+
return prediction
|
122 |
+
|
123 |
+
def Crop_yield():
|
124 |
+
tab1, tab2,tab3 = st.tabs(["Crop Labels", "Crop Yield","Feedback"])
|
125 |
+
with tab1:
|
126 |
+
def display_images_in_columns(dictionary, num_columns=2):
|
127 |
+
num_images = len(dictionary)
|
128 |
+
num_rows = -(-num_images // num_columns) # Ceiling division to calculate rows
|
129 |
+
|
130 |
+
for i in range(num_rows):
|
131 |
+
cols = st.columns(num_columns)
|
132 |
+
for j in range(num_columns):
|
133 |
+
index = i * num_columns + j
|
134 |
+
if index < num_images:
|
135 |
+
label, url = list(dictionary.items())[index]
|
136 |
+
cols[j].image(url, caption=label, use_column_width=True)
|
137 |
+
|
138 |
+
# Example dictionary (replace this with your actual dictionary)
|
139 |
+
image_dictionary = {'Wheat': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRIp7ucodsB63giF1CvVjBtbHf14Px83ck2hcZRUJlMxA&s',
|
140 |
+
'Rice': 'https://media.istockphoto.com/id/153737841/photo/rice.webp?b=1&s=170667a&w=0&k=20&c=SF6Ks-8AYpbPTnZlGwNCbCFUh-0m3R5sM2hl-C5r_Xc=',
|
141 |
+
'Maize (Corn)': 'https://plus.unsplash.com/premium_photo-1667047165840-803e47970128?q=80&w=1000&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MXx8bWFpemV8ZW58MHx8MHx8fDA%3D',
|
142 |
+
'Bajra (Pearl millet)': 'https://media.istockphoto.com/id/1400438871/photo/pear-millet-background.jpg?s=612x612&w=0&k=20&c=0GlBeceuX9Q_AZ0-CH57_A5s7_tD769N2f_jrbNcbrw=',
|
143 |
+
'Jowar (Sorghum)': 'https://media.istockphoto.com/id/1262684430/photo/closeup-view-of-a-white-millet-jowar.jpg?s=612x612&w=0&k=20&c=HLyBy06EjbABKybUy1nIQTfxMLV1-s4xofGigOdd6dU=',
|
144 |
+
'Barley': 'https://www.poshtik.in/cdn/shop/products/com1807851487263barley_Poshtik_c1712f8e-6b63-4231-9596-a49ce84f26ba.png?v=1626004318',
|
145 |
+
'Gram (Chickpea)': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHtf9ivxD23Bp_-VOY4H2tCRMC0_znhzyAEt2jfzvUlskEZcv0',
|
146 |
+
'Tur (Pigeonpea)': 'https://rukminim2.flixcart.com/image/850/1000/xif0q/plant-seed/f/l/n/25-pigeon-pea-for-planting-home-garden-farming-vegetable-kitchen-original-imaghphgmepkjqfz.jpeg?q=90',
|
147 |
+
'Moong (Green Gram)': 'https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTyIa1Wq11MaHZ_cIdArPjZSR8cnr85STU83QsjKvkI9xNdVDjJ',
|
148 |
+
'Urad (Black gram)': 'https://encrypted-tbn0.gstatic.com/licensed-image?q=tbn:ANd9GcRl-eFmBSLAHxB7U_b_SQNptQoQpi585JWgpqU0LH0jmvmrp9mESzQrL3ieox6ICl_-v7rzl38Pi7faf-4',
|
149 |
+
'Masoor (Red lentil)': 'https://www.vegrecipesofindia.com/wp-content/uploads/2022/11/masoor-dal-red-lentils.jpg',
|
150 |
+
'Groundnut (Peanut)': 'https://www.netmeds.com/images/cms/wysiwyg/blog/2019/10/Groundnut_big_2.jpg',
|
151 |
+
'Sesamum (Sesame)': 'https://encrypted-tbn0.gstatic.com/licensed-image?q=tbn:ANd9GcThAjpal-k0urS19A2NEoVW35yqF9ljlvx1d-amDokoIiHZ9-RGyUsDaiVcr7SdfwsFjP-I6U1_VYeiEc0',
|
152 |
+
'Castor seed': 'https://5.imimg.com/data5/QV/VN/MY-3966004/caster-seeds.jpg',
|
153 |
+
'Sunflower': 'https://t0.gstatic.com/licensed-image?q=tbn:ANd9GcRuCcoGrqSVqOzxFU9rHPsWKxaHpm7i_srXQPMHaVfrrDmz4eXc5PGWpQFfpAr8qaH2',
|
154 |
+
'Safflower': 'https://upload.wikimedia.org/wikipedia/commons/7/7f/Safflower.jpg',
|
155 |
+
'Sugarcane': 'https://www.saveur.com/uploads/2022/03/05/sugarcane-linda-xiao.jpg?auto=webp',
|
156 |
+
'Cotton (lint)': 'https://img2.tradewheel.com/uploads/images/products/6/0/0048590001615360690-cotton-lint.jpeg.webp',
|
157 |
+
'Jute': 'https://rukminim2.flixcart.com/image/850/1000/kuk4u4w0/rope/d/k/f/2-jute-cord-for-craft-project-natural-jute-rope-jute-thread-original-imag7nrjbkrmgbpm.jpeg?q=20',
|
158 |
+
'Potato': 'https://cdn.mos.cms.futurecdn.net/iC7HBvohbJqExqvbKcV3pP.jpg',
|
159 |
+
'Onion': 'https://familyneeds.co.in/cdn/shop/products/2_445fc9bd-1bab-4bfb-8d5d-70b692745567_600x600.jpg?v=1600812246',
|
160 |
+
'Tomato': 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/89/Tomato_je.jpg/1200px-Tomato_je.jpg',
|
161 |
+
'Banana': 'https://fruitboxco.com/cdn/shop/products/asset_2_grande.jpg?v=1571839043',
|
162 |
+
'Coconut': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS_rZgOJry6Twt8urk4C1FTo6d6tEDyiIw39w&usqp=CAU',
|
163 |
+
'Mango': "https://i.pinimg.com/474x/70/bd/5f/70bd5f8fd50d30bfcab3ac0f27ff4202.jpg",
|
164 |
+
'Orange': "https://images.unsplash.com/photo-1611080626919-7cf5a9dbab5b?q=80&w=1000&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8b3Jhbmdlc3xlbnwwfHwwfHx8MA%3D%3D"}
|
165 |
+
|
166 |
+
|
167 |
+
display_images_in_columns(image_dictionary)
|
168 |
+
with tab2:
|
169 |
+
st.title('Crop Yield Prediction')
|
170 |
+
background_image = ' https://us.123rf.com/450wm/vittuperkele/vittuperkele1804/vittuperkele180400186/100517230-growing-green-crop-fields-at-late-evening-blue-sky-with-clouds-in-countryside-fresh-air-clean.jpg?ver=6'
|
171 |
+
html_code = f"""
|
172 |
+
<style>
|
173 |
+
body {{
|
174 |
+
background-image: url('{background_image}');
|
175 |
+
background-size: cover;
|
176 |
+
background-position: center;
|
177 |
+
background-repeat: no-repeat;
|
178 |
+
height: 100vh; /* Set the height of the background to fill the viewport */
|
179 |
+
margin: 0; /* Remove default body margin */
|
180 |
+
display: flex;
|
181 |
+
flex-direction: column;
|
182 |
+
justify-content: center;
|
183 |
+
align-items: center;
|
184 |
+
}}
|
185 |
+
.stApp {{
|
186 |
+
background: none; /* Remove Streamlit app background */
|
187 |
+
}}
|
188 |
+
</style>
|
189 |
+
"""
|
190 |
+
st.markdown(html_code, unsafe_allow_html=True)
|
191 |
+
|
192 |
+
col1, col2 = st.columns(2)
|
193 |
+
# c1,c2,c3 = st.columns([3,0.5,0.5])
|
194 |
+
crop = col1.selectbox(':black[Enter crop type]',('Arecanut', 'Arhar/Tur', 'Castor seed', 'Coconut ', 'Cotton(lint)',
|
195 |
+
'Dry chillies', 'Gram', 'Jute', 'Linseed', 'Maize', 'Mesta',
|
196 |
+
'Niger seed', 'Onion', 'Other Rabi pulses', 'Potato',
|
197 |
+
'Rapeseed &Mustard', 'Rice', 'Sesamum', 'Small millets',
|
198 |
+
'Sugarcane', 'Sweet potato', 'Tapioca', 'Tobacco', 'Turmeric',
|
199 |
+
'Wheat', 'Bajra', 'Black pepper', 'Cardamom', 'Coriander',
|
200 |
+
'Garlic', 'Ginger', 'Groundnut', 'Horse-gram', 'Jowar', 'Ragi',
|
201 |
+
'Cashewnut', 'Banana', 'Soyabean', 'Barley', 'Khesari', 'Masoor',
|
202 |
+
'Moong(Green Gram)', 'Other Kharif pulses', 'Safflower',
|
203 |
+
'Sannhamp', 'Sunflower', 'Urad', 'Peas & beans (Pulses)',
|
204 |
+
'other oilseeds', 'Other Cereals', 'Cowpea(Lobia)',
|
205 |
+
'Oilseeds total', 'Guar seed', 'Other Summer Pulses', 'Moth'))
|
206 |
+
|
207 |
+
season = current_season
|
208 |
+
state = 'Karnataka'
|
209 |
+
try:
|
210 |
+
area = col2.number_input("Enter area (e.g., in ha)", min_value=1.0, max_value=10000000.0, value=6637.0, step=1.0, format="%f", help="Enter the area in Hacter")
|
211 |
+
minallowed = area * 0.03
|
212 |
+
maxallowed = area * 1.5
|
213 |
+
|
214 |
+
annual_rainfall = col2.number_input('Enter annual rainfall (e.g., in mm)',value=2051.4,min_value=200.0,max_value=2500.0,step=100.0)
|
215 |
+
fertilizer = col1.number_input('Enter fertilizer (e.g., in g)',value=631643.29,min_value=1.0,max_value=10000000.0,step=10.0)
|
216 |
+
pesticide = col2.number_input('Enter pesticide (e.g., in g)',value=2057.47,min_value=1.0,max_value=10000000.0,step=10.0)
|
217 |
+
# st.write(state)
|
218 |
+
# st.write(IP)
|
219 |
+
except:
|
220 |
+
st.warning("Max area is more than limits")
|
221 |
+
prediction = ''
|
222 |
+
production = col1.number_input('Enter production (e.g., in kg)', value=minallowed, min_value=minallowed, max_value=maxallowed, step=10.0)
|
223 |
+
if st.button('Submit'):
|
224 |
+
encode = encoding([crop, season, state, area, production, annual_rainfall, fertilizer, pesticide])
|
225 |
+
try:
|
226 |
+
prediction = crop_yield_prediction(list(encode))
|
227 |
+
progress = st.progress(0)
|
228 |
+
for i in range(100):
|
229 |
+
time.sleep(0.005)
|
230 |
+
progress.progress(i+1)
|
231 |
+
st.subheader(f"Crop Yied: {round(prediction[0],3)} kg/ha")
|
232 |
+
except:
|
233 |
+
st.error("Invalid Inputs")
|
234 |
+
|
235 |
+
with tab3:
|
236 |
+
df = pd.read_csv('crop_yield.csv')
|
237 |
+
st.write('Current Dataset',df)
|
238 |
+
col1,col2 = st.columns(2)
|
239 |
+
crop = col1.selectbox(':black[Enter crop type]',('Arecanut', 'Arhar/Tur', 'Castor seed', 'Coconut ', 'Cotton(lint)',
|
240 |
+
'Dry chillies', 'Gram', 'Jute', 'Linseed', 'Maize', 'Mesta',
|
241 |
+
'Niger seed', 'Onion', 'Other Rabi pulses', 'Potato',
|
242 |
+
'Rapeseed &Mustard', 'Rice', 'Sesamum', 'Small millets',
|
243 |
+
'Sugarcane', 'Sweet potato', 'Tapioca', 'Tobacco', 'Turmeric',
|
244 |
+
'Wheat', 'Bajra', 'Black pepper', 'Cardamom', 'Coriander',
|
245 |
+
'Garlic', 'Ginger', 'Groundnut', 'Horse-gram', 'Jowar', 'Ragi',
|
246 |
+
'Cashewnut', 'Banana', 'Soyabean', 'Barley', 'Khesari', 'Masoor',
|
247 |
+
'Moong(Green Gram)', 'Other Kharif pulses', 'Safflower',
|
248 |
+
'Sannhamp', 'Sunflower', 'Urad', 'Peas & beans (Pulses)',
|
249 |
+
'other oilseeds', 'Other Cereals', 'Cowpea(Lobia)',
|
250 |
+
'Oilseeds total', 'Guar seed', 'Other Summer Pulses', 'Moth'),key = 104)
|
251 |
+
area = col2.number_input("Enter area (e.g., in ha)", min_value=1.0, max_value=10000000.0, value=6637.0, step=1.0, format="%f", help="Enter the area in Hacter",key = 105)
|
252 |
+
minallowed = area * 0.03
|
253 |
+
maxallowed = area * 1.5
|
254 |
+
production = col1.number_input('Enter production (e.g., in kg)', value=minallowed, min_value=minallowed, max_value=maxallowed, step=10.0,key = 106)
|
255 |
+
annual_rainfall = col2.number_input('Enter annual rainfall (e.g., in mm)',value=2051.4,min_value=200.0,max_value=2500.0,step=100.0,key = 107)
|
256 |
+
fertilizer = col1.number_input('Enter fertilizer (e.g., in g)',value=631643.29,min_value=1.0,max_value=10000000.0,step=10.0,key = 108)
|
257 |
+
pesticide = col2.number_input('Enter pesticide (e.g., in g)',value=2057.47,min_value=1.0,max_value=10000000.0,step=10.0,key = 109)
|
258 |
+
Yield = col1.number_input('Enter the yield(kg per hectare)',value = 79.9,max_value=21105.0,min_value=0.0,step = 5.0,key = 101)
|
259 |
+
|
260 |
+
if st.button('submit',key = 102):
|
261 |
+
new_row = {'Crop':crop,'Area':area, 'Production':production,'Annual_Rainfall':annual_rainfall, 'Fertilizer':fertilizer, 'Pesticide':pesticide, 'Yield':Yield}
|
262 |
+
df = df.append(new_row,ignore_index= True)
|
263 |
+
df.to_csv('crop_yield.csv')
|
264 |
+
st.success("Thanks for the feedback")
|
265 |
+
st.write("Updated Dataset",df)
|
266 |
+
|
267 |
+
|
268 |
+
|
269 |
+
if __name__ == '__main__':
|
270 |
+
Crop_yield()
|
Lasso Regression.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b07b1d5479f558ac9a6494f837b04309561a988ab3bb93c8b39f37e5b9bb4099
|
3 |
+
size 129
|
Mail.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import smtplib
|
2 |
+
from email.mime.text import MIMEText
|
3 |
+
from email.mime.multipart import MIMEMultipart
|
4 |
+
|
5 |
+
def send_confirmation_email(recipient_email, username):
|
6 |
+
sender_email = "agritechserviceorg@gmail.com"
|
7 |
+
password = "yvoq mzmv qmjr ahoi"
|
8 |
+
subject = "Account Confirmation"
|
9 |
+
body = f"Hello {username},\n\nThank you for creating an account!\n\nBest regards,\nAgriTech Team"
|
10 |
+
message = MIMEMultipart()
|
11 |
+
message["From"] = sender_email
|
12 |
+
message["To"] = recipient_email
|
13 |
+
message["Subject"] = subject
|
14 |
+
message.attach(MIMEText(body, "plain"))
|
15 |
+
with smtplib.SMTP("smtp.gmail.com", 587) as server:
|
16 |
+
server.starttls()
|
17 |
+
server.login(sender_email, password)
|
18 |
+
server.sendmail(sender_email, recipient_email, message.as_string())
|
19 |
+
|
crop_recommendation.pickle
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:03352e857a8d9b32ccbef1407583cc24d27304e2cbc9b0d487f97a3bdc4b81f5
|
3 |
+
size 3907534
|
crop_yield.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
crop_yield_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8717df38ceca417a37d28cada5870349a1414d96852a410f8136973a36f48d4d
|
3 |
+
size 133829713
|
feedbacko.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
timestamp,briefit,feedbacko
|
2 |
+
2024-01-15 14:15:13,5,super
|
feedbacko.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from datetime import datetime
|
4 |
+
def run_feedback():
|
5 |
+
df = pd.read_csv('feedbacko.csv')
|
6 |
+
st.title('Feedback Form')
|
7 |
+
brief = st.slider('Rate your experience ⭐️', min_value=1, max_value=5, value=3)
|
8 |
+
feedback_text = st.text_area('Provide additional comments or feedback:')
|
9 |
+
|
10 |
+
if st.button('Submit Feedback'):
|
11 |
+
# Check if 'feedbacko' is empty and replace it with None
|
12 |
+
feedback_text = None if not feedback_text else feedback_text
|
13 |
+
|
14 |
+
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
15 |
+
|
16 |
+
new_data = {
|
17 |
+
'timestamp': timestamp,
|
18 |
+
'briefit': brief,
|
19 |
+
'feedbacko': feedback_text
|
20 |
+
}
|
21 |
+
new_df = pd.DataFrame([new_data])
|
22 |
+
combined_df = pd.concat([df, new_df], ignore_index=True, axis=0)
|
23 |
+
combined_df = combined_df.drop_duplicates(subset=['feedbacko'])
|
24 |
+
combined_df = combined_df.dropna(subset=['briefit'])
|
25 |
+
combined_df.to_csv('feedbacko.csv', index=False)
|
26 |
+
st.success('Thank You for your feedback')
|
27 |
+
|
28 |
+
|
gross_premimum.py
ADDED
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# coding: utf-8
|
3 |
+
|
4 |
+
# In[145]:
|
5 |
+
|
6 |
+
|
7 |
+
from sklearn.ensemble import ExtraTreesRegressor
|
8 |
+
from sklearn.model_selection import train_test_split
|
9 |
+
from sklearn.preprocessing import StandardScaler
|
10 |
+
from sklearn.pipeline import Pipeline
|
11 |
+
from sklearn.compose import ColumnTransformer
|
12 |
+
from sklearn.preprocessing import LabelEncoder
|
13 |
+
import pandas as pd
|
14 |
+
|
15 |
+
|
16 |
+
# In[146]:
|
17 |
+
|
18 |
+
|
19 |
+
data = pd.read_csv('insurance.csv')
|
20 |
+
data_new = data.copy(deep = True)
|
21 |
+
|
22 |
+
|
23 |
+
# In[147]:
|
24 |
+
|
25 |
+
|
26 |
+
data.head()
|
27 |
+
|
28 |
+
|
29 |
+
# In[148]:
|
30 |
+
|
31 |
+
|
32 |
+
data.isnull().sum()
|
33 |
+
|
34 |
+
|
35 |
+
# In[149]:
|
36 |
+
|
37 |
+
|
38 |
+
data.dropna(inplace = True)
|
39 |
+
|
40 |
+
|
41 |
+
# In[150]:
|
42 |
+
|
43 |
+
|
44 |
+
X = data.drop('gross_premium', axis = 1)
|
45 |
+
y = data['gross_premium']
|
46 |
+
|
47 |
+
|
48 |
+
# In[151]:
|
49 |
+
|
50 |
+
|
51 |
+
import re
|
52 |
+
|
53 |
+
obj_columns = list(data.select_dtypes("object").columns)
|
54 |
+
obj_columns
|
55 |
+
|
56 |
+
|
57 |
+
# In[152]:
|
58 |
+
|
59 |
+
|
60 |
+
import re
|
61 |
+
|
62 |
+
for col in obj_columns:
|
63 |
+
data[col] = data[col].astype("str")
|
64 |
+
data[col] = data[col].apply(lambda x: re.sub(r'[^a-zA-Z0-9]', '', x.lower())).astype("str")
|
65 |
+
|
66 |
+
|
67 |
+
# In[153]:
|
68 |
+
|
69 |
+
|
70 |
+
season_catogory = list(data.season.values)
|
71 |
+
scheme_catogory = list(data.scheme.values)
|
72 |
+
state_catogory = list(data.state_name.values)
|
73 |
+
district_catogory = list(data.district_name.values)
|
74 |
+
|
75 |
+
|
76 |
+
# In[154]:
|
77 |
+
|
78 |
+
|
79 |
+
columns = ['season','scheme','state_name','district_name']
|
80 |
+
from sklearn.preprocessing import LabelEncoder
|
81 |
+
encoder = LabelEncoder()
|
82 |
+
for col in columns:
|
83 |
+
data[col] = encoder.fit_transform(data[col])
|
84 |
+
|
85 |
+
|
86 |
+
# In[155]:
|
87 |
+
|
88 |
+
|
89 |
+
season_label = list(data.season.values)
|
90 |
+
scheme_label = list(data.scheme.values)
|
91 |
+
state_label = list(data.state_name.values)
|
92 |
+
district_label = list(data.district_name.values)
|
93 |
+
|
94 |
+
|
95 |
+
# In[156]:
|
96 |
+
|
97 |
+
|
98 |
+
season_category_label_dict = dict(zip(season_catogory, season_label))
|
99 |
+
|
100 |
+
scheme_category_label_dict = dict(zip(scheme_catogory, scheme_label))
|
101 |
+
|
102 |
+
state_category_label_dict = dict(zip(state_catogory, state_label))
|
103 |
+
|
104 |
+
district_category_label_dict = dict(zip(district_catogory, district_label))
|
105 |
+
|
106 |
+
|
107 |
+
# In[157]:
|
108 |
+
|
109 |
+
|
110 |
+
|
111 |
+
# In[163]:
|
112 |
+
|
113 |
+
|
114 |
+
# X = data.iloc[:,:-1]
|
115 |
+
# y = data.iloc[:,-1]
|
116 |
+
|
117 |
+
|
118 |
+
# In[164]:
|
119 |
+
|
120 |
+
|
121 |
+
# X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
122 |
+
|
123 |
+
|
124 |
+
# # In[165]:
|
125 |
+
|
126 |
+
|
127 |
+
# from sklearn.linear_model import LinearRegression
|
128 |
+
|
129 |
+
|
130 |
+
# In[166]:
|
131 |
+
|
132 |
+
|
133 |
+
# model = LinearRegression()
|
134 |
+
|
135 |
+
|
136 |
+
# # In[167]:
|
137 |
+
|
138 |
+
|
139 |
+
# model.fit(X, y)
|
140 |
+
|
141 |
+
|
142 |
+
# In[168]:
|
143 |
+
|
144 |
+
|
145 |
+
# import pickle as pk
|
146 |
+
# filename= 'crop_grosspremimum_Jp.pkl'
|
147 |
+
# pk.dump(model,open(filename,'wb'))
|
148 |
+
|
149 |
+
|
150 |
+
# In[169]:
|
151 |
+
|
152 |
+
|
153 |
+
def encoding(input_data):
|
154 |
+
input_data[0] = season_category_label_dict[input_data[0].lower().replace(" ","").replace(" ","").replace(" ","").replace(" ","")]
|
155 |
+
input_data[1] = scheme_category_label_dict[input_data[1].lower().replace(" ","").replace(" ","").replace(" ","").replace(" ","")]
|
156 |
+
input_data[2] = state_category_label_dict[input_data[2].lower().replace(" ","").replace(" ","").replace(" ","").replace(" ","")]
|
157 |
+
input_data[3] = district_category_label_dict[input_data[3].lower().replace(" ","").replace(" ","").replace(" ","").replace(" ","")]
|
158 |
+
return input_data
|
159 |
+
|
160 |
+
|
161 |
+
# In[170]:
|
162 |
+
|
163 |
+
|
164 |
+
# crop_grosspremimum = pk.load(open(filename, "rb"))
|
165 |
+
|
166 |
+
|
167 |
+
# # In[172]:
|
168 |
+
|
169 |
+
|
170 |
+
# data = ["kharif","PMFBY","Andhra Pradesh","Chittoor",18.82,22410.65,792.39,50.93,50.93,614]
|
171 |
+
# crop_grosspremimum.predict([encoding(data)])[0]
|
172 |
+
|
173 |
+
|
174 |
+
# In[ ]:
|
175 |
+
|
176 |
+
|
177 |
+
|
178 |
+
|
insurance(R).csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
insurance.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d46327688e9e60166e607920dc5875195c9131afbe6760c5be19335f0479331c
|
3 |
+
size 28043192
|