Spaces:
Sleeping
Sleeping
File size: 3,199 Bytes
40a5d08 e4d452a 40a5d08 455c7e3 40a5d08 4fbedcd 40a5d08 1594194 40a5d08 4581712 29bff84 40a5d08 29bff84 455c7e3 40a5d08 832cc1e 40a5d08 29bff84 40a5d08 4581712 40a5d08 832cc1e 40a5d08 4581712 455c7e3 29bff84 | 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
import streamlit as st
import pandas as pd
import joblib
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# Load the trained model
@st.cache_resource
def load_model():
return joblib.load("Agriculture_Yield_Prediction_model_v1_0.joblib")
model = load_model()
# Streamlit UI for Price Prediction
st.title("πΎ Crop Yield Prediction")
st.write("Please Provide your crop details below to estimate yield (t/ha).")
st.subheader("Enter the listing details:")
# Collect user input
# Dropdowns
# --- Farmer-friendly Inputs ---
state = st.selectbox("π State", [
"West Bengal","Nagaland","Chhattisgarh","Himachal Pradesh","Bihar",
"Karnataka","Jammu and Kashmir","Andhra Pradesh","Tripura","Haryana",
"Uttarakhand","Assam","Manipur","Odisha","Punjab","Madhya Pradesh",
"Tamil Nadu","Mizoram","Uttar Pradesh","Telangana","Puducherry","Sikkim",
"Maharashtra","Delhi","Gujarat","Arunachal Pradesh","Kerala","Jharkhand",
"Meghalaya","Goa"
])
crop = st.selectbox("π± Crop", [
"Sesamum","Urad","Moong(Green Gram)","Groundnut","Other Kharif pulses",
"Small millets","Sunflower","Peas & beans (Pulses)","Arhar/Tur","Bajra",
"Rapeseed &Mustard","Maize","Horse-gram","Other Rabi pulses","Jowar","Ragi",
"Gram","Masoor","Dry chillies","Castor seed","Soyabean","Linseed",
"Cotton(lint)","Turmeric","Wheat","Barley","Coriander","Sannhamp","Rice",
"Garlic","Ginger","Tobacco","Other Cereals","Safflower","Cowpea(Lobia)",
"Niger seed","other oilseeds","Mesta","Onion","Moth","Black pepper",
"Arecanut","Jute","Cardamom","Sugarcane","Cashewnut","Sweet potato",
"Guar seed","Potato","Other Summer Pulses","Khesari","Banana"
])
season = st.selectbox("ποΈ Season", [
"Kharif","Rabi","Whole Year","Summer","Autumn","Winter"
])
crop_year = st.number_input("π
Crop Year", min_value=1990, max_value=2025, value=2024)
area_acres = st.number_input("πΎ Area (in acres)", min_value=0.1, step=0.1)
production_bags = st.number_input("π¦ Production (in bags previous year data)", min_value=1, step=1)
bag_weight = st.number_input("βοΈ Bag Weight (kg)", min_value=50, max_value=100, value=75)
rainfall = st.number_input("π§οΈ Annual Rainfall (mm)", min_value=0.0, step=1.0)
fertilizer = st.number_input("π Fertilizer Used (kg)", min_value=0.0, step=1.0)
pesticide = st.number_input("π§΄ Pesticide Used (kg)", min_value=0.0, step=1.0)
area_ha = area_acres / 2.47 # convert acres β hectares
production_tonnes = (production_bags * bag_weight) / 1000 # convert bags β tonnes
input_data = pd.DataFrame({
"Crop": [crop],
"Crop_Year": [crop_year],
"Season": [season],
"State": [state],
"Area": [area_ha],
"Production": [production_tonnes],
"Annual_Rainfall": [rainfall],
"Fertilizer": [fertilizer],
"Pesticide": [pesticide],
})
# --- Prediction ---
if st.button("π Predict Yield"):
prediction = model.predict(input_data)[0] # model outputs yield in t/ha
st.success(f"πΎ Estimated Yield: {prediction:.2f} t/ha")
prediction_bags_per_acre = (prediction * 2.47 * 1000) / bag_weight
st.info(f"Equivalent: {prediction_bags_per_acre:.2f} bags per acre")
|