Spaces:
Sleeping
Sleeping
File size: 2,707 Bytes
00751c0 6d51ff5 03e0ab0 558ada5 00751c0 03e0ab0 5c49502 03e0ab0 d305188 03e0ab0 698e304 03e0ab0 698e304 00751c0 125baa9 00751c0 f974f44 8c1fc8e 00751c0 d7f8bf9 00751c0 03e0ab0 5c49502 03e0ab0 5c49502 03e0ab0 5c49502 00751c0 03e0ab0 00751c0 03e0ab0 5c49502 00751c0 03e0ab0 00751c0 03e0ab0 5c49502 00751c0 8c1fc8e 8518300 00751c0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
import numpy as np
import pandas as pd
import streamlit as st
import pickle
from PIL import Image
st.set_page_config(
page_title="Recommendation System for Agriculture",
page_icon=":random:",
layout="centered",
initial_sidebar_state="expanded",
menu_items={
'About': "# This application will help provide crop recommendations!"
}
)
model = pickle.load(open('crop_model.pkl','rb'))
ss = pickle.load(open('standardscaler.pkl','rb'))
ms = pickle.load(open('minmaxscaler.pkl','rb'))
check_crops = {1: 'rice',
2: 'maize',
3: 'jute',
4: 'cotton',
5: 'coconut',
6: 'papaya',
7: 'orange',
8: 'apple',
9: 'muskmelon',
10: 'watermelon',
11: 'grapes',
12: 'mango',
13: 'banana',
14: 'pomegranate',
15: 'lentil',
16: 'blackgram',
17: 'mungbean',
18: 'mothbeans',
19: 'pigeonpeas',
20: 'kidneybeans',
21: 'chickpea',
22: 'coffee'}
def recommend(N, P, K, temperature, humidity, ph, rainfall):
features = np.array([[N, P, K, temperature, humidity, ph, rainfall]]).reshape(1,-1)
features = ms.transform(features)
features = ss.transform(features)
prediction = model.predict(features)
return prediction[0]
def output(N, P, K, temperature, humidity, ph, rainfall):
predict = recommend(N, P, K, temperature, humidity, ph, rainfall)
if predict in check_crops:
crop = check_crops[predict]
st.write("""# Our crop recommendation is """, crop)
else:
st.write("""# No recommendation""")
image = Image.open('./crop_details.jpg')
st.image(image)
st.write("The mean values of input variables are provided in the above table. Refer the above table to set the input variables and see the accuracy of the recommendation!")
with st.sidebar:
image = Image.open('./sidebar_image.jpg')
st.image(image)
st.markdown("<h2 style='text-align: center; color: red;'>Settings Tab</h2>", unsafe_allow_html=True)
st.write("Input Settings:")
#define the N for the model
n_value = st.slider('N :', 0.0, 150.0, 20.0)
#define the P for the model
p_value = st.slider('P :', 0.0, 150.0, 20.0)
#define the K for the model
k_value = st.slider('K :', 0.0, 200.0, 40.0)
#define the temperature for the model
temperature = st.slider('Temperature :', 0.0, 50.0, 10.0)
#define the humidity for the model
humidity = st.slider('Humidity :', 0.0, 100.0, 40.0)
#define the ph for the model
ph_value = st.slider('ph :', 0.0, 10.0, 2.0)
#define the rainfall for the model
rainfall = st.slider('Rainfall :', 10.0, 300.0, 40.0)
with st.container():
if st.button("Recommend"):
output(n_value, p_value, k_value, temperature, humidity, ph_value, rainfall)
|