Spaces:
Sleeping
Sleeping
Download app.py from PyarasaniSrinivas/AgriYield_AI: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/spaces/PyarasaniSrinivas/AgriYield_AI/resolve/main/app.py
- Command line
-
hf download hf://spaces/PyarasaniSrinivas/AgriYield_AI/app.py
-
curl -L -o app.py https://huggingface.co/spaces/PyarasaniSrinivas/AgriYield_AI/resolve/main/app.py
1.4 kB
| import streamlit as st | |
| import pandas as pd | |
| import joblib | |
| # Load model | |
| model = joblib.load("model.pkl") | |
| st.title("🌾 Crop Yield Prediction") | |
| st.write("Enter the details below to predict crop yield.") | |
| # Load dataset (only for dropdown values) | |
| df = pd.read_csv("Indian_crop.csv") | |
| # Inputs | |
| year = st.number_input( | |
| "Year", | |
| min_value=int(df["Year"].min()), | |
| max_value=int(df["Year"].max()), | |
| value=int(df["Year"].max()), | |
| step=1 | |
| ) | |
| state = st.selectbox("State", sorted(df["State"].unique())) | |
| crop = st.selectbox("Crop", sorted(df["Crop"].unique())) | |
| season = st.selectbox("Season", sorted(df["Season"].unique())) | |
| area = st.number_input("Area (Hectares)", min_value=0.0, value=1.0) | |
| annual_rainfall = st.number_input("Annual Rainfall (mm)", min_value=0.0, value=1000.0) | |
| fertilizer = st.number_input("Fertilizer (kg)", min_value=0.0, value=100.0) | |
| pesticide = st.number_input("Pesticide (kg)", min_value=0.0, value=10.0) | |
| if st.button("Predict Yield"): | |
| input_df = pd.DataFrame({ | |
| "Year": [year], | |
| "State": [state], | |
| "Crop": [crop], | |
| "Season": [season], | |
| "Area": [area], | |
| "Annual_Rainfall": [annual_rainfall], | |
| "Fertilizer": [fertilizer], | |
| "Pesticide": [pesticide] | |
| }) | |
| prediction = model.predict(input_df) | |
| st.success(f"🌾 Predicted Yield: {prediction[0]}") |