Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from sklearn.naive_bayes import GaussianNB
|
4 |
+
import joblib
|
5 |
+
|
6 |
+
# Load the trained model
|
7 |
+
model = joblib.load('naive_bayes_model.pkl')
|
8 |
+
|
9 |
+
# Define the Streamlit app
|
10 |
+
def main():
|
11 |
+
st.title("Crop Recommendation Model")
|
12 |
+
st.write("This is a simple web app to make predictions using a Naive Bayes model.")
|
13 |
+
|
14 |
+
st.sidebar.header("Enter Features")
|
15 |
+
|
16 |
+
# Input fields for each feature
|
17 |
+
N = st.sidebar.number_input("N ratio in soil")
|
18 |
+
P = st.sidebar.number_input("P ratio in soil")
|
19 |
+
K = st.sidebar.number_input("K ratio in soil")
|
20 |
+
temperature = st.sidebar.number_input("Temperature (°C)")
|
21 |
+
humidity = st.sidebar.number_input("Humidity (%)")
|
22 |
+
ph = st.sidebar.number_input("pH value of soil")
|
23 |
+
rainfall = st.sidebar.number_input("Rainfall (mm)")
|
24 |
+
|
25 |
+
# Make prediction
|
26 |
+
if st.sidebar.button("Predict"):
|
27 |
+
# Preprocess the input features
|
28 |
+
input_data = pd.DataFrame({'N': [N], 'P': [P], 'K': [K], 'temperature': [temperature],
|
29 |
+
'humidity': [humidity], 'ph': [ph], 'rainfall': [rainfall]})
|
30 |
+
|
31 |
+
# Make prediction
|
32 |
+
prediction = model.predict(input_data)
|
33 |
+
|
34 |
+
# Display prediction
|
35 |
+
st.header("Prediction")
|
36 |
+
st.write("Predicted crop:", prediction[0])
|
37 |
+
|
38 |
+
if __name__ == '__main__':
|
39 |
+
main()
|