Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -25,30 +25,35 @@ crop = st.selectbox("π± Crop", ["Rice", "Wheat", "Cotton", "Maize", "Pulses"])
|
|
| 25 |
season = st.selectbox("ποΈ Season", ["Kharif", "Rabi", "Whole Year"])
|
| 26 |
crop_year = st.number_input("π
Crop Year", min_value=1990, max_value=2025, value=2024)
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
bag_weight = st.number_input("βοΈ Bag Weight (kg)", min_value=50, max_value=100, value=75)
|
| 31 |
|
| 32 |
rainfall = st.number_input("π§οΈ Annual Rainfall (mm)", min_value=0.0, step=1.0)
|
| 33 |
fertilizer = st.number_input("π Fertilizer Used (kg)", min_value=0.0, step=1.0)
|
| 34 |
pesticide = st.number_input("π§΄ Pesticide Used (kg)", min_value=0.0, step=1.0)
|
| 35 |
|
|
|
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
-
# --- Input DataFrame (aligned with training data) ---
|
| 39 |
input_data = pd.DataFrame({
|
| 40 |
"Crop": [crop],
|
| 41 |
"Crop_Year": [crop_year],
|
| 42 |
"Season": [season],
|
| 43 |
"State": [state],
|
| 44 |
-
"Area": [
|
| 45 |
-
"Production": [
|
| 46 |
"Annual_Rainfall": [rainfall],
|
| 47 |
"Fertilizer": [fertilizer],
|
| 48 |
"Pesticide": [pesticide],
|
| 49 |
})
|
| 50 |
|
|
|
|
| 51 |
# --- Prediction ---
|
| 52 |
if st.button("π Predict Yield"):
|
| 53 |
prediction = model.predict(input_data)[0] # model outputs yield in t/ha
|
| 54 |
st.success(f"πΎ Estimated Yield: {prediction:.2f} t/ha")
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
season = st.selectbox("ποΈ Season", ["Kharif", "Rabi", "Whole Year"])
|
| 26 |
crop_year = st.number_input("π
Crop Year", min_value=1990, max_value=2025, value=2024)
|
| 27 |
|
| 28 |
+
area_acres = st.number_input("πΎ Area (in acres)", min_value=0.1, step=0.1)
|
| 29 |
+
production_bags = st.number_input("π¦ Production (in bags)", min_value=1, step=1)
|
| 30 |
bag_weight = st.number_input("βοΈ Bag Weight (kg)", min_value=50, max_value=100, value=75)
|
| 31 |
|
| 32 |
rainfall = st.number_input("π§οΈ Annual Rainfall (mm)", min_value=0.0, step=1.0)
|
| 33 |
fertilizer = st.number_input("π Fertilizer Used (kg)", min_value=0.0, step=1.0)
|
| 34 |
pesticide = st.number_input("π§΄ Pesticide Used (kg)", min_value=0.0, step=1.0)
|
| 35 |
|
| 36 |
+
area_ha = area_acres / 2.47 # convert acres β hectares
|
| 37 |
+
production_tonnes = (production_bags * bag_weight) / 1000 # convert bags β tonnes
|
| 38 |
|
| 39 |
|
|
|
|
| 40 |
input_data = pd.DataFrame({
|
| 41 |
"Crop": [crop],
|
| 42 |
"Crop_Year": [crop_year],
|
| 43 |
"Season": [season],
|
| 44 |
"State": [state],
|
| 45 |
+
"Area": [area_ha],
|
| 46 |
+
"Production": [production_tonnes],
|
| 47 |
"Annual_Rainfall": [rainfall],
|
| 48 |
"Fertilizer": [fertilizer],
|
| 49 |
"Pesticide": [pesticide],
|
| 50 |
})
|
| 51 |
|
| 52 |
+
|
| 53 |
# --- Prediction ---
|
| 54 |
if st.button("π Predict Yield"):
|
| 55 |
prediction = model.predict(input_data)[0] # model outputs yield in t/ha
|
| 56 |
st.success(f"πΎ Estimated Yield: {prediction:.2f} t/ha")
|
| 57 |
+
|
| 58 |
+
prediction_bags_per_acre = (prediction * 2.47 * 1000) / bag_weight
|
| 59 |
+
st.info(f"Equivalent: {prediction_bags_per_acre:.2f} bags per acre")
|