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("

Settings Tab

", 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)