Prajwal3009 commited on
Commit
fbc2095
·
verified ·
1 Parent(s): 1f42382

Upload 6 files

Browse files
Crop_Recommendation.py ADDED
@@ -0,0 +1,450 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # #!/usr/bin/env python
2
+ # # coding: utf-8
3
+
4
+ # import pandas as pd
5
+ # import numpy as np
6
+ # import matplotlib.pyplot as plt
7
+ # import seaborn as sns
8
+ # import pickle as pk
9
+ # import streamlit as st
10
+ # import time
11
+ # import warnings
12
+ # warnings.filterwarnings("ignore")
13
+
14
+
15
+ # data = pd.read_csv("Crop_recommendation.csv")
16
+ # data_new = data.copy(deep = True)
17
+
18
+ # from sklearn.preprocessing import LabelEncoder
19
+
20
+ # le = LabelEncoder()
21
+ # data["Crop"] = le.fit_transform(data["label"])
22
+
23
+ # data.drop(columns = ["label"], inplace = True)
24
+
25
+ # def crop_encoding(Predicted_value):
26
+ # Predicted_value = (data_new[data.Crop == Predicted_value]["label"]).to_list()[0]
27
+ # return Predicted_value
28
+
29
+ # # print(crop_encoding(20).capitalize())
30
+
31
+ # recommendation_model = pk.load(open('crop_recommendation.pkl','rb'))
32
+
33
+ # def Crop_recommendation_function(crop_data_input):
34
+ # crop_data_asarray = np.asarray(crop_data_input)
35
+ # crop_data_reshaped = crop_data_asarray.reshape(1, -1)
36
+ # crop_recommended = recommendation_model.predict(crop_data_reshaped)[0] # Extract the result
37
+ # crop = crop_encoding(crop_recommended)
38
+ # return crop
39
+
40
+ # def run_crop_recommendation():
41
+ # st.title('Crop Recommendation')
42
+ # background_image = 'https://c1.wallpaperflare.com/preview/436/828/940/clouds-summer-storm-clouds-form.jpg'
43
+ # html_code = f"""
44
+ # <style>
45
+ # body {{
46
+ # background-image: url('{background_image}');
47
+ # background-size: cover;
48
+ # background-position: center;
49
+ # background-repeat: no-repeat;
50
+ # height: 100vh; /* Set the height of the background to fill the viewport */
51
+ # margin: 0; /* Remove default body margin */
52
+ # display: flex;
53
+ # flex-direction: column;
54
+ # justify-content: center;
55
+ # align-items: center;
56
+ # }}
57
+ # .stApp {{
58
+ # background: none; /* Remove Streamlit app background */
59
+ # }}
60
+ # </style>
61
+ # """
62
+ # st.markdown(html_code, unsafe_allow_html=True)
63
+
64
+ # col1, col2 = st.columns(2)
65
+ # nitrogen = col1.number_input('Enter Nitrogen (e.g., in kg/ha)',value=90.0,min_value=0.0,max_value=10000.0,step=1.0)
66
+ # phosphorus = col2.number_input('Enter Phosphorus (e.g., in kg/ha)',value=42.0,min_value=0.0,max_value=10000.0,step=1.0)
67
+ # potassium = col1.number_input('Enter Potassium (e.g., in kg/ha)',value=43.0,min_value=0.0,max_value=10000.0,step=1.0)
68
+ # temperature = col2.number_input('Enter Temperature in celsius (e.g., in °C)',value=20.87,min_value=-1000.0,max_value=1000.0,step=0.1)
69
+ # humidity = col1.number_input('Enter Humidity (e.g., in %)',value=82.002744,min_value=0.0,max_value=100.0,step=0.1)
70
+ # ph = col2.number_input('Enter pH value',value=6.502985,min_value=0.0,max_value=14.0,step=0.1)
71
+ # rainfall = col1.number_input('Enter Rainfall (e.g., in mm)',value=202.935536,min_value=0.0,max_value=100000.0,step=1.0)
72
+
73
+ # crop_input = ''
74
+
75
+ # if st.button('Submit'):
76
+ # crop_input = [nitrogen, phosphorus, potassium, temperature, humidity, ph, rainfall]
77
+ # crop_prediction = Crop_recommendation_function(crop_input)
78
+
79
+ # progress = st.progress(0)
80
+ # for i in range(100):
81
+ # time.sleep(0.005)
82
+ # progress.progress(i+1)
83
+ # st.subheader(f"Crop Recommendation: {crop_prediction.capitalize()}")
84
+
85
+
86
+
87
+ import requests
88
+ import pandas as pd
89
+ import numpy as np
90
+ import pickle as pk
91
+ import streamlit as st
92
+ import time
93
+ import Weather_app as wa
94
+
95
+
96
+
97
+
98
+ import warnings
99
+ warnings.filterwarnings("ignore")
100
+ data = pd.read_csv("Crop_recommendation.csv")
101
+ data_new = data.copy(deep = True)
102
+
103
+ from sklearn.preprocessing import LabelEncoder
104
+
105
+ le = LabelEncoder()
106
+ data["Crop"] = le.fit_transform(data["label"])
107
+
108
+ data.drop(columns = ["label"], inplace = True)
109
+
110
+ @st.cache_resource
111
+ def recmod():
112
+ return pk.load(open('crop_recommendation.pickle','rb'))
113
+ recommendation_model = recmod()
114
+
115
+ def crop_encoding(Predicted_value):
116
+ Predicted_value = (data_new[data.Crop == Predicted_value]["label"]).to_list()[0]
117
+ return Predicted_value
118
+
119
+ def Crop_recommendation_function(crop_data_input):
120
+ crop_data_asarray = np.asarray(crop_data_input)
121
+ crop_data_reshaped = crop_data_asarray.reshape(1, -1)
122
+ crop_recommended = recommendation_model.predict(crop_data_reshaped)[0] # Extract the result
123
+ crop = crop_encoding(crop_recommended)
124
+ return crop
125
+ def Crop_recommendation_function2(input_data_speed):
126
+ # crop_data_asarray = np.array(input_data_speed).reshape(1, -1)
127
+
128
+ # Make predictions using the loaded model
129
+ # predictions = loaded_data.predict(crop_data_asarray)[0]
130
+
131
+
132
+ # modaa = pk.load(open('Soli_to_recommandation_model_Raghuu.pkl', 'rb'))
133
+ with open('Soli_to_recommandation_model_Raghuu.pkl', 'rb') as file:
134
+ loaded_model = pk.load(file)
135
+ # input_data = np.array(input_data_speed).reshape(1, -1)
136
+ mapp = {'Pomegranate': 10,
137
+ 'Banana': 2,
138
+ 'Mango': 6,
139
+ 'Grapes': 4,
140
+ 'Peach': 9,
141
+ 'Black Berry': 3,
142
+ 'Apple': 0,
143
+ 'Orange': 7,
144
+ 'Papaya': 8,
145
+ 'Guava': 5,
146
+ 'Apricot': 1}
147
+
148
+ criop =loaded_model.predict(input_data_speed)[0]
149
+ predicted_label = [key for key, value in mapp.items() if value == criop][0]
150
+
151
+ return predicted_label
152
+
153
+
154
+ # def get_weather_details(city_name):
155
+ # base_url = "https://api.openweathermap.org/data/2.5/weather"
156
+ # params = {
157
+ # 'q': city_name,
158
+ # 'appid': "d73ec4f18aca81c32b1836a8ac2506e0"
159
+ # }
160
+
161
+ # try:
162
+ # response = requests.get(base_url, params=params)
163
+ # data = response.json()
164
+
165
+ # # Check if the request was successful
166
+ # if response.status_code == 200:
167
+ # # Extract weather details
168
+ # weather_details = {
169
+ # 'temperature': data['main']['temp'],
170
+ # 'humidity': data['main']['humidity']
171
+ # }
172
+ # return weather_details
173
+ # else:
174
+ # st.write("Error {}: {}".format(response.status_code, data['message']))
175
+ # return None
176
+ # except Exception as e:
177
+ # st.write("An error occurred:", e)
178
+ # return None
179
+
180
+ def run_crop_recommendation():
181
+ st.title('Crop Recommendation')
182
+ background_image = 'https://c1.wallpaperflare.com/preview/436/828/940/clouds-summer-storm-clouds-form.jpg'
183
+ html_code = f"""
184
+ <style>
185
+ body {{
186
+ background-image: url('{background_image}');
187
+ background-size: cover;
188
+ background-position: center;
189
+ background-repeat: no-repeat;
190
+ height: 100vh; /* Set the height of the background to fill the viewport */
191
+ margin: 0; /* Remove default body margin */
192
+ display: flex;
193
+ flex-direction: column;
194
+ justify-content: center;
195
+ align-items: center;
196
+ }}
197
+ .stApp {{
198
+ background: none; /* Remove Streamlit app background */
199
+ }}
200
+ </style>
201
+ """
202
+ tab1, tab2, tab3= st.tabs(['Based On Land And Water', 'Based On Fertilizers','Feedback'])
203
+ # st.title("Crop Recommendation System")
204
+ with tab1:
205
+
206
+ try:
207
+ weather_details = wa.get_weather_details(wa.city_name)
208
+ # Load the trained model
209
+ @st.cache_resource
210
+ def soli():
211
+ return pk.load(open('Soli_to_recommandation_model_Simha.pkl', 'rb'))
212
+
213
+
214
+ loaded_model = soli()
215
+
216
+ # Streamlit UI
217
+ # st.title("Crop Recommendation System")
218
+
219
+ # Input features for prediction
220
+ col1, col2 = st.columns(2)
221
+ with col1:
222
+ Soil_EC = st.selectbox(("Soil_EC Siemens per meter (S/m)"),(1,2,3,4),3)
223
+ with col2:
224
+ Water_TDS = st.selectbox(("Water_TDS"),(1,2,3,4,5,6),5)
225
+ if weather_details:
226
+ Temprature = weather_details['temperature']
227
+ Humidity = weather_details['humidity']
228
+ col3,col4 = st.columns(2)
229
+ with col3:
230
+
231
+ Ph = st.number_input("acidity or alkalinity",value=8.0, min_value= 0.0, max_value= 14.0, step=0.5)
232
+ with col4:
233
+ Rain_Fall = st.number_input("Rain_Fall in (mm) ", min_value=50.0,value=100.97,max_value=500.0)
234
+
235
+ # Reshape input data for prediction
236
+ input_data = np.array([Soil_EC, Water_TDS, Temprature, Humidity, Ph, Rain_Fall]).reshape(1, -1)
237
+
238
+ # Make prediction
239
+ mapp = {'Pomegranate': 10,
240
+ 'Banana': 2,
241
+ 'Mango': 6,
242
+ 'Grapes': 4,
243
+ 'Peach': 9,
244
+ 'Black Berry': 3,
245
+ 'Apple': 0,
246
+ 'Orange': 7,
247
+ 'Papaya': 8,
248
+ 'Guava': 5,
249
+ 'Apricot': 1}
250
+ crop_image_urls = {'Wheat': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRIp7ucodsB63giF1CvVjBtbHf14Px83ck2hcZRUJlMxA&s',
251
+ 'Rice': 'https://media.istockphoto.com/id/153737841/photo/rice.webp?b=1&s=170667a&w=0&k=20&c=SF6Ks-8AYpbPTnZlGwNCbCFUh-0m3R5sM2hl-C5r_Xc=',
252
+ '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',
253
+ '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=',
254
+ '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=',
255
+ 'Barley': 'https://www.poshtik.in/cdn/shop/products/com1807851487263barley_Poshtik_c1712f8e-6b63-4231-9596-a49ce84f26ba.png?v=1626004318',
256
+ 'Gram (Chickpea)': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHtf9ivxD23Bp_-VOY4H2tCRMC0_znhzyAEt2jfzvUlskEZcv0',
257
+ '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',
258
+ 'Moong (Green Gram)': 'https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTyIa1Wq11MaHZ_cIdArPjZSR8cnr85STU83QsjKvkI9xNdVDjJ',
259
+ 'Urad (Black gram)': 'https://encrypted-tbn0.gstatic.com/licensed-image?q=tbn:ANd9GcRl-eFmBSLAHxB7U_b_SQNptQoQpi585JWgpqU0LH0jmvmrp9mESzQrL3ieox6ICl_-v7rzl38Pi7faf-4',
260
+ 'Masoor (Red lentil)': 'https://www.vegrecipesofindia.com/wp-content/uploads/2022/11/masoor-dal-red-lentils.jpg',
261
+ 'Groundnut (Peanut)': 'https://www.netmeds.com/images/cms/wysiwyg/blog/2019/10/Groundnut_big_2.jpg',
262
+ 'Sesamum (Sesame)': 'https://encrypted-tbn0.gstatic.com/licensed-image?q=tbn:ANd9GcThAjpal-k0urS19A2NEoVW35yqF9ljlvx1d-amDokoIiHZ9-RGyUsDaiVcr7SdfwsFjP-I6U1_VYeiEc0',
263
+ 'Castor seed': 'https://5.imimg.com/data5/QV/VN/MY-3966004/caster-seeds.jpg',
264
+ 'Sunflower': 'https://t0.gstatic.com/licensed-image?q=tbn:ANd9GcRuCcoGrqSVqOzxFU9rHPsWKxaHpm7i_srXQPMHaVfrrDmz4eXc5PGWpQFfpAr8qaH2',
265
+ 'Safflower': 'https://upload.wikimedia.org/wikipedia/commons/7/7f/Safflower.jpg',
266
+ 'Sugarcane': 'https://www.saveur.com/uploads/2022/03/05/sugarcane-linda-xiao.jpg?auto=webp',
267
+ 'Cotton (lint)': 'https://img2.tradewheel.com/uploads/images/products/6/0/0048590001615360690-cotton-lint.jpeg.webp',
268
+ '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',
269
+ 'Potato': 'https://cdn.mos.cms.futurecdn.net/iC7HBvohbJqExqvbKcV3pP.jpg',
270
+ 'Onion': 'https://familyneeds.co.in/cdn/shop/products/2_445fc9bd-1bab-4bfb-8d5d-70b692745567_600x600.jpg?v=1600812246',
271
+ 'Tomato': 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/89/Tomato_je.jpg/1200px-Tomato_je.jpg',
272
+ 'Banana': 'https://fruitboxco.com/cdn/shop/products/asset_2_grande.jpg?v=1571839043',
273
+ 'Coconut': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS_rZgOJry6Twt8urk4C1FTo6d6tEDyiIw39w&usqp=CAU',
274
+ 'Mango': "https://i.pinimg.com/474x/70/bd/5f/70bd5f8fd50d30bfcab3ac0f27ff4202.jpg",
275
+ '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",
276
+ "Pomegranate": "https://thumbs.dreamstime.com/b/juicy-pomegranate-its-half-leaves-16537522.jpg",
277
+ "Banana": "https://media.istockphoto.com/id/173242750/photo/banana-bunch.jpg?s=612x612&w=0&k=20&c=MAc8AXVz5KxwWeEmh75WwH6j_HouRczBFAhulLAtRUU=",
278
+ "Grapes": "https://cf.ltkcdn.net/wine/images/std/165373-800x532r1-grapes.jpg",
279
+ "Peach": "https://www.shutterstock.com/image-photo/peaches-isolated-ripe-peach-half-260nw-2189388721.jpg",
280
+ "Black Berry": "https://example.com/blackberry.jpg",
281
+ "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",
282
+ "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=",
283
+ "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=",
284
+ "Apricot": "https://www.shutterstock.com/image-photo/apricot-isolated-apricots-on-white-600nw-1963600408.jpg"}
285
+
286
+ def get_crop_image_url(crop_name):
287
+ return crop_image_urls.get(crop_name, None)
288
+
289
+ if st.button("Submit", key=32):
290
+ prediction = loaded_model.predict(input_data)
291
+ predicted_label = [key for key, value in mapp.items() if value == prediction][0]
292
+ st.success(f"The predicted fruit is: {predicted_label}")
293
+
294
+ crop_image_url = get_crop_image_url(predicted_label.capitalize())
295
+
296
+ if crop_image_url is None:
297
+ st.warning("No image found for the predicted fruit.")
298
+ else:
299
+ try:
300
+ st.markdown(f'<img src="{crop_image_url}" alt="Image for {predicted_label}" style="width:300px; height:300px;">', unsafe_allow_html=True)
301
+ except Exception as e:
302
+ st.warning(f"Error displaying image: {e}")
303
+
304
+
305
+
306
+ except AttributeError:
307
+ st.warning("Please Select the city")
308
+
309
+ # col1, col2 = st.columns(2)
310
+ # with col1:
311
+ # Soil_EC = st.selectbox(('Soil conductivity'),(1,2,3,4),2,key = 3)
312
+ # with col2:
313
+ # Water_TDS = st.selectbox(('Water solvents'),(1,2,3,4,5,6),3,key = 4)
314
+ # col3,col4 = st.columns([3,1])
315
+ # with col3:
316
+ # Ph = st.slider("Enter ph",1,14,(1,7))
317
+ # with col4:
318
+ # Rain_Fall = st.number_input("Enter Annual Rainfall in mm", min_value=10.0, max_value=2000.0)
319
+ # weather_details = wa.get_weather_details(wa.city_name)
320
+
321
+
322
+
323
+ # if weather_details:
324
+ # Temperature = (weather_details['temperature'])
325
+ # Humidity =(weather_details['humidity'])
326
+ # st.write(Temperature)
327
+ # st.write(Humidity)
328
+ # input_data = [Soil_EC,Water_TDS,Temperature,Humidity,Ph,Rain_Fall]
329
+ # if st.button('Submit',key = 1):
330
+ # input_data = np.asarray(input_data).reshape(1, -1)
331
+
332
+ # crop_pred = Crop_recommendation_function2(input_data)
333
+
334
+ # progress = st.progress(0)
335
+ # for i in range(100):
336
+ # time.sleep(0.005)
337
+ # progress.progress(i+1)
338
+ # st.subheader(f"Crop Recommendation: {crop_pred.capitalize()}")
339
+
340
+ # crop_image_url = get_crop_image_url(crop_pred)
341
+ # try:
342
+ # st.image(crop_image_url, caption=f"Image for {crop_prediction.capitalize()}", use_column_width=True)
343
+ # except:
344
+ # pass
345
+
346
+
347
+
348
+ with tab2:
349
+
350
+ st.markdown(html_code, unsafe_allow_html=True)
351
+
352
+ col1, col2 = st.columns(2)
353
+ 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)
354
+ 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)
355
+ 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)
356
+
357
+ # Get weather details
358
+ # city_name = st.text_input("Enter City Name for Weather Details")
359
+ weather_details = wa.get_weather_details(wa.city_name)
360
+ ph = col2.slider('Enter pH value',value=6.502985,min_value=0.0,max_value=14.0,step=0.5)
361
+ rainfall = col1.number_input('Enter Rainfall (e.g., in mm)',value=202.935536,min_value=25.0,max_value=1000.0,step=5.0)
362
+
363
+
364
+ if weather_details:
365
+ temperature = weather_details['temperature']
366
+ humidity = weather_details['humidity']
367
+
368
+
369
+ crop_input = ''
370
+
371
+ def get_crop_image_url(crop_name):
372
+ # You need to replace the following with the actual URLs or paths of your crop images
373
+ crop_image_urls = {'Wheat': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRIp7ucodsB63giF1CvVjBtbHf14Px83ck2hcZRUJlMxA&s',
374
+ 'Rice': 'https://media.istockphoto.com/id/153737841/photo/rice.webp?b=1&s=170667a&w=0&k=20&c=SF6Ks-8AYpbPTnZlGwNCbCFUh-0m3R5sM2hl-C5r_Xc=',
375
+ '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',
376
+ '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=',
377
+ '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=',
378
+ 'Barley': 'https://www.poshtik.in/cdn/shop/products/com1807851487263barley_Poshtik_c1712f8e-6b63-4231-9596-a49ce84f26ba.png?v=1626004318',
379
+ 'Gram (Chickpea)': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHtf9ivxD23Bp_-VOY4H2tCRMC0_znhzyAEt2jfzvUlskEZcv0',
380
+ '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',
381
+ 'Moong (Green Gram)': 'https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTyIa1Wq11MaHZ_cIdArPjZSR8cnr85STU83QsjKvkI9xNdVDjJ',
382
+ 'Urad (Black gram)': 'https://encrypted-tbn0.gstatic.com/licensed-image?q=tbn:ANd9GcRl-eFmBSLAHxB7U_b_SQNptQoQpi585JWgpqU0LH0jmvmrp9mESzQrL3ieox6ICl_-v7rzl38Pi7faf-4',
383
+ 'Masoor (Red lentil)': 'https://www.vegrecipesofindia.com/wp-content/uploads/2022/11/masoor-dal-red-lentils.jpg',
384
+ 'Groundnut (Peanut)': 'https://www.netmeds.com/images/cms/wysiwyg/blog/2019/10/Groundnut_big_2.jpg',
385
+ 'Sesamum (Sesame)': 'https://encrypted-tbn0.gstatic.com/licensed-image?q=tbn:ANd9GcThAjpal-k0urS19A2NEoVW35yqF9ljlvx1d-amDokoIiHZ9-RGyUsDaiVcr7SdfwsFjP-I6U1_VYeiEc0',
386
+ 'Castor seed': 'https://5.imimg.com/data5/QV/VN/MY-3966004/caster-seeds.jpg',
387
+ 'Sunflower': 'https://t0.gstatic.com/licensed-image?q=tbn:ANd9GcRuCcoGrqSVqOzxFU9rHPsWKxaHpm7i_srXQPMHaVfrrDmz4eXc5PGWpQFfpAr8qaH2',
388
+ 'Safflower': 'https://upload.wikimedia.org/wikipedia/commons/7/7f/Safflower.jpg',
389
+ 'Sugarcane': 'https://www.saveur.com/uploads/2022/03/05/sugarcane-linda-xiao.jpg?auto=webp',
390
+ 'Cotton (lint)': 'https://img2.tradewheel.com/uploads/images/products/6/0/0048590001615360690-cotton-lint.jpeg.webp',
391
+ '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',
392
+ 'Potato': 'https://cdn.mos.cms.futurecdn.net/iC7HBvohbJqExqvbKcV3pP.jpg',
393
+ 'Onion': 'https://familyneeds.co.in/cdn/shop/products/2_445fc9bd-1bab-4bfb-8d5d-70b692745567_600x600.jpg?v=1600812246',
394
+ 'Tomato': 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/89/Tomato_je.jpg/1200px-Tomato_je.jpg',
395
+ 'Banana': 'https://fruitboxco.com/cdn/shop/products/asset_2_grande.jpg?v=1571839043',
396
+ 'Coconut': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS_rZgOJry6Twt8urk4C1FTo6d6tEDyiIw39w&usqp=CAU',
397
+ 'Mango': "https://i.pinimg.com/474x/70/bd/5f/70bd5f8fd50d30bfcab3ac0f27ff4202.jpg",
398
+ '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"}
399
+ if crop_name not in crop_image_urls.keys():
400
+ return None
401
+ else:
402
+ return crop_image_urls[crop_name]
403
+
404
+ if st.button('Submit'):
405
+ crop_input = [nitrogen, phosphorus, potassium, temperature, humidity, ph, rainfall]
406
+ crop_prediction = Crop_recommendation_function(crop_input)
407
+
408
+ progress = st.progress(0)
409
+ for i in range(100):
410
+ time.sleep(0.005)
411
+ progress.progress(i+1)
412
+ st.subheader(f"Crop Recommendation: {crop_prediction.capitalize()}")
413
+
414
+ crop_image_url = get_crop_image_url(crop_prediction.capitalize())
415
+ try:
416
+ st.image(crop_image_url, caption=f"Image for {crop_prediction.capitalize()}", use_column_width=True)
417
+ except:
418
+ pass
419
+
420
+ with tab3:
421
+ df = pd.read_csv('Crop_recommendation.csv')
422
+ st.write('Current Dataset',df)
423
+ col1, col2 = st.columns(2)
424
+ 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)
425
+ 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)
426
+ 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)
427
+ temperature = col2.number_input('Enter temprature',max_value=45.0,min_value=8.0,value=32.0,step = 2.0,key = 232)
428
+ humidity = col1.number_input('Enter Humidity',value=80.47,max_value=99.98,min_value=14.25,step = 2.0,key = 103)
429
+ ph = col2.slider('Enter pH value',value=6.502985,min_value=0.0,max_value=14.0,step=0.5,key = 104)
430
+ 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)
431
+ label = col1.selectbox('Enter the crop',('rice', 'maize', 'chickpea', 'kidneybeans', 'pigeonpeas',
432
+ 'mothbeans', 'mungbean', 'blackgram', 'lentil', 'pomegranate',
433
+ 'banana', 'mango', 'grapes', 'watermelon', 'muskmelon', 'apple',
434
+ 'orange', 'papaya', 'coconut', 'cotton', 'jute', 'coffee'),key =106)
435
+
436
+ if st.button('submit'):
437
+ new_row = {'N':nitrogen, 'P':phosphorus, 'K':potassium, 'temperature':temperature, 'humidity':humidity, 'ph':ph, 'rainfall':rainfall, 'label':label}
438
+ df = df.append(new_row,ignore_index= True)
439
+ df.to_csv('Crop_recommendation.csv')
440
+ st.success("Thanks for the feedback")
441
+ st.write("Updated Dataset",df)
442
+
443
+
444
+
445
+
446
+
447
+
448
+
449
+ if __name__ == "__main__":
450
+ run_crop_recommendation()
Crop_recommendation.csv ADDED
The diff for this file is too large to render. See raw diff
 
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()
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