import streamlit as st
import pickle
import numpy as np
# Set Page Configuration
st.set_page_config(page_title="What to Plant? Let the Soil Decide!", layout="centered")
# Function to set background image and styles
def set_bg():
bg_style = """
"""
st.markdown(bg_style, unsafe_allow_html=True)
# Apply the background styling
set_bg()
# Load Model
with open("model.pkl", "rb") as file:
model = pickle.load(file)
# **Fixing Title Color**
st.markdown(
"""
What to Plant? Let the Soil Decide!
""",
unsafe_allow_html=True
)
# Display range details for input fields
st.markdown(
"""
🌿 Input Guidelines 🌿
- NITROGEN: 0 - 300
- PHOSPHOROUS: 0 - 200
- POTASSIUM: 0 - 200
- TEMPERATURE: 0.0 - 100.0 °C
- HUMIDITY: 0.0 - 100.0 %
- PH: 0.0 - 14.0
- RAINFALL: 0.0 - 500.0 mm
""",
unsafe_allow_html=True
)
# Input Fields
with st.container():
nitrogen = st.number_input("NITROGEN", min_value=0, max_value=300, value=104, step=1)
phosphorus = st.number_input("PHOSPHOROUS", min_value=0, max_value=200, value=18, step=1)
potassium = st.number_input("POTASSIUM", min_value=0, max_value=200, value=30, step=1)
temperature = st.number_input("TEMPERATURE", min_value=0.0, max_value=100.0, value=23.6, step=0.1)
humidity = st.number_input("HUMIDITY", min_value=0.0, max_value=100.0, value=60.3, step=0.1)
ph = st.number_input("PH", min_value=0.0, max_value=14.0, value=6.7, step=0.1)
rainfall = st.number_input("RAINFALL", min_value=0.0, max_value=500.0, value=140.91, step=0.1)
# Predict and Display Output
if st.button("Submit"):
try:
# Prepare input data for prediction
input_data = np.array([[nitrogen, phosphorus, potassium, temperature, humidity, ph, rainfall]])
predicted_crop = model.predict(input_data)[0]
# Display result in larger, bold text
st.markdown(
f"""
🌾 Recommended Crop: {predicted_crop} 🌱
""",
unsafe_allow_html=True
)
except ValueError:
st.markdown(
"⚠️ Error: Please enter valid numerical values.
",
unsafe_allow_html=True
)