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