File size: 1,511 Bytes
3791d18
 
e549286
3791d18
e549286
 
 
3791d18
 
 
 
42ba863
0ec22d4
42ba863
 
 
 
3791d18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42ba863
0ec22d4
3791d18
 
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
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()