Spaces:
Sleeping
Sleeping
| 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 | |
| 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") | |