Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import pickle | |
# Load the trained model using pickle | |
with open('naive_bayes_model.pkl', 'rb') as file: | |
model = pickle.load(file) | |
# Define the Streamlit app | |
def main(): | |
st.title("Crop Recommendation Model") | |
st.image("logo.png", width=200) | |
st.write("Developed by: Adil") | |
st.write("This is an AI powered app for Crop Recommendations") | |
# Display the labels in a well-formatted box | |
st.info("Labels the model can predict:") | |
st.write(model.classes_) | |
st.sidebar.header("Enter Features") | |
# Input fields for each feature | |
N = st.sidebar.number_input("N ratio in soil") | |
P = st.sidebar.number_input("P ratio in soil") | |
K = st.sidebar.number_input("K ratio in soil") | |
temperature = st.sidebar.number_input("Temperature (°C)") | |
humidity = st.sidebar.number_input("Humidity (%)") | |
ph = st.sidebar.number_input("pH value of soil") | |
rainfall = st.sidebar.number_input("Rainfall (mm)") | |
# Make prediction | |
if st.sidebar.button("Predict"): | |
# Preprocess the input features | |
input_data = pd.DataFrame({'N': [N], 'P': [P], 'K': [K], 'temperature': [temperature], | |
'humidity': [humidity], 'ph': [ph], 'rainfall': [rainfall]}) | |
# Make prediction | |
prediction = model.predict(input_data) | |
# Display prediction | |
st.header("Prediction") | |
st.write("Predicted crop:", prediction[0]) | |
if __name__ == '__main__': | |
main() | |