File size: 1,676 Bytes
847dcf5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import joblib
import pandas as pd

model = joblib.load('selector.h5')

prices = pd.read_csv("crop_prices.csv")

st.title("Crop Selection App")

st.header("Input Soil Data:")
nitrogen = st.number_input("Nitrogen", min_value=0, max_value=100, value=50)
phosphorus = st.number_input("Phosphorus", min_value=0, max_value=100, value=50)
potassium = st.number_input("Potassium", min_value=0, max_value=100, value=50)
temperature = st.number_input("Temperature", min_value=0.0, max_value=100.0, value=25.0,step=1.,format="%.4f")
humidity = st.number_input("Humidity", min_value=0.0, max_value=100.0, value=50.0,step=1.,format="%.4f")
ph = st.number_input("pH", min_value=0.0, max_value=14.0, value=7.0,step=1.,format="%.4f")
rainfall = st.number_input("Rainfall", min_value=0.0, max_value=1000.0, value=500.0,step=1.,format="%.4f")

user_input = [[nitrogen, phosphorus, potassium, temperature, humidity, ph, rainfall]]

if st.button("Predict"):
    predicted_crop = model.predict_proba(user_input)

    crop_probabilities = list(zip(model.classes_, predicted_crop[0]))

    # Sort crops based on probability estimates
    sorted_crops = sorted(crop_probabilities, key=lambda x: x[1], reverse=True)

    # Display the sorted crops
    st.header("Top 3 Crops to grow:")
    for i, (crop, probability) in enumerate(sorted_crops[:3]):
        prob_percent = probability*100
        #st.write(f"{i+1}. {crop}: {prob_percent:.2f}%")
        average_price = prices.loc[prices['CROP'] == crop, 'AVG PRICES'].values[0]
        
        st.write(f"{i+1}. {crop}: {prob_percent:.2f}% || Average Price: Rs.{average_price} / Quintal")

st.text("Created by Analytical Aces")