Spaces:
Sleeping
Sleeping
| # Streamlit uygulaması | |
| import streamlit as st | |
| import pandas as pd | |
| import pickle | |
| from catboost import CatBoostClassifier | |
| st.set_page_config( | |
| page_title="Irrigation Need Prediction", | |
| page_icon="🌱", | |
| layout="centered" | |
| ) | |
| st.title("🌱 Irrigation Need Prediction") | |
| st.write( | |
| "This application predicts the irrigation need level of a field " | |
| "based on soil, crop, weather, and irrigation-related inputs." | |
| ) | |
| model = CatBoostClassifier() | |
| model.load_model("src/catboost_irrigation_model.cbm") | |
| with open("src/feature_columns.pkl", "rb") as f: | |
| feature_columns = pickle.load(f) | |
| soil_type = st.selectbox("Soil Type", ["Sandy", "Clay", "Loamy", "Silt"]) | |
| soil_ph = st.number_input("Soil pH", min_value=4.0, max_value=9.0, value=6.5) | |
| soil_moisture = st.number_input("Soil Moisture", min_value=0.0, max_value=100.0, value=35.0) | |
| organic_carbon = st.number_input("Organic Carbon", min_value=0.0, max_value=3.0, value=0.9) | |
| electrical_conductivity = st.number_input("Electrical Conductivity", min_value=0.0, max_value=5.0, value=1.5) | |
| temperature_c = st.number_input("Temperature (°C)", min_value=0.0, max_value=50.0, value=28.0) | |
| humidity = st.number_input("Humidity", min_value=0.0, max_value=100.0, value=60.0) | |
| rainfall_mm = st.number_input("Rainfall (mm)", min_value=0.0, max_value=3000.0, value=1200.0) | |
| sunlight_hours = st.number_input("Sunlight Hours", min_value=0.0, max_value=15.0, value=7.5) | |
| wind_speed_kmh = st.number_input("Wind Speed (km/h)", min_value=0.0, max_value=30.0, value=10.0) | |
| crop_type = st.selectbox("Crop Type", ["Sugarcane", "Rice", "Cotton", "Maize", "Wheat", "Potato"]) | |
| crop_growth_stage = st.selectbox("Crop Growth Stage", ["Sowing", "Vegetative", "Flowering", "Harvest"]) | |
| season = st.selectbox("Season", ["Kharif", "Rabi", "Zaid"]) | |
| irrigation_type = st.selectbox("Irrigation Type", ["Canal", "Sprinkler", "Rainfed", "Drip"]) | |
| water_source = st.selectbox("Water Source", ["Reservoir", "River", "Groundwater", "Rainwater"]) | |
| field_area_hectare = st.number_input("Field Area (hectare)", min_value=0.0, max_value=20.0, value=7.5) | |
| mulching_used = st.selectbox("Mulching Used", ["Yes", "No"]) | |
| previous_irrigation_mm = st.number_input("Previous Irrigation (mm)", min_value=0.0, max_value=150.0, value=60.0) | |
| region = st.selectbox("Region", ["North", "South", "East", "West", "Central"]) | |
| input_df = pd.DataFrame({ | |
| "Soil_Type": [soil_type], | |
| "Soil_pH": [soil_ph], | |
| "Soil_Moisture": [soil_moisture], | |
| "Organic_Carbon": [organic_carbon], | |
| "Electrical_Conductivity": [electrical_conductivity], | |
| "Temperature_C": [temperature_c], | |
| "Humidity": [humidity], | |
| "Rainfall_mm": [rainfall_mm], | |
| "Sunlight_Hours": [sunlight_hours], | |
| "Wind_Speed_kmh": [wind_speed_kmh], | |
| "Crop_Type": [crop_type], | |
| "Crop_Growth_Stage": [crop_growth_stage], | |
| "Season": [season], | |
| "Irrigation_Type": [irrigation_type], | |
| "Water_Source": [water_source], | |
| "Field_Area_hectare": [field_area_hectare], | |
| "Mulching_Used": [mulching_used], | |
| "Previous_Irrigation_mm": [previous_irrigation_mm], | |
| "Region": [region] | |
| }) | |
| input_df = input_df[feature_columns] | |
| if st.button("Predict Irrigation Need / Sulama İhtiyacını Tahmin Et"): | |
| prediction = model.predict(input_df)[0][0] | |
| turkish_labels = { | |
| "Low": "Düşük", | |
| "Medium": "Orta", | |
| "High": "Yüksek" | |
| } | |
| st.success( | |
| f"Predicted Irrigation Need: {prediction}\n\n" | |
| f"Sulama İhtiyacı: {turkish_labels[prediction]}" | |
| ) |