Download app.py from Abrar20/Smart-Automated-Irrigation-System: direct link, hf CLI and curl.
- Browser
- Download file 3.13 kB
-
https://huggingface.co/spaces/Abrar20/Smart-Automated-Irrigation-System/resolve/main/app.py
- Command line
-
hf download hf://spaces/Abrar20/Smart-Automated-Irrigation-System/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Abrar20/Smart-Automated-Irrigation-System/resolve/main/app.py
3.13 kB
| import gradio as gr | |
| import pandas as pd | |
| import joblib | |
| # Define the features | |
| features = ['tempreature', 'humidity', 'water_level', 'N', 'P', 'K'] | |
| # Load the models | |
| water_pump_model = joblib.load("xgb_Water_pump_actuator_ON_model.pkl") | |
| watering_plant_model = joblib.load("xgb_Watering_plant_pump_ON_model.pkl") | |
| fan_actuator_model = joblib.load("xgb_fan_actuator_model.pkl") | |
| # Prediction function | |
| def predict_actuators(tempreature, humidity, water_level, N, P, K): | |
| # Input as DataFrame | |
| input_data = pd.DataFrame([[tempreature, humidity, water_level, N, P, K]], columns=features) | |
| # Predictions for each model | |
| water_pump_pred = water_pump_model.predict(input_data)[0] | |
| watering_plant_pred = watering_plant_model.predict(input_data)[0] | |
| fan_actuator_pred = fan_actuator_model.predict(input_data)[0] | |
| # Interpret predictions | |
| water_pump_status = "The Water Pump Actuator is Turning On. ๐ฐ" if water_pump_pred == 1 else "The Water Pump Actuator is Off. โ" | |
| watering_plant_status = "The Watering Plant Pump is Turning On. ๐ฑ" if watering_plant_pred == 1 else "The Watering Plant Pump is Off. โ" | |
| fan_actuator_status = "The Fan Actuator is Turning On. ๐จ" if fan_actuator_pred == 1 else "The Fan Actuator is Off. โ" | |
| return water_pump_status, watering_plant_status, fan_actuator_status | |
| # Create Gradio interface | |
| with gr.Blocks() as app: | |
| gr.Markdown("# ๐พ Smart Automated Irrigation System ๐ฟ") | |
| gr.Markdown("Enter the environmental and nutrient parameters below to predict the actuator status for your irrigation system.") | |
| with gr.Row(): | |
| tempreature = gr.Number(label="Temperature (ยฐC)", value=30.5) | |
| humidity = gr.Number(label="Humidity (%)", value=75.0) | |
| water_level = gr.Number(label="Water Level (cm)", value=3.2) | |
| N = gr.Number(label="Nitrogen (N)", value=40) | |
| P = gr.Number(label="Phosphorus (P)", value=15) | |
| K = gr.Number(label="Potassium (K)", value=20) | |
| with gr.Row(): | |
| example1_btn = gr.Button("Use Example Input 1 (30.5, 75.0, 3.2, 40, 15, 20)") | |
| example2_btn = gr.Button("Use Example Input 2 (35, 12, 88, 185, 190, 160)") | |
| submit_btn = gr.Button("Predict Actuator Status") | |
| with gr.Row(): | |
| water_pump_status = gr.Textbox(label="Water Pump Status", interactive=False) | |
| watering_plant_status = gr.Textbox(label="Watering Plant Pump Status", interactive=False) | |
| fan_actuator_status = gr.Textbox(label="Fan Actuator Status", interactive=False) | |
| # Example input 1 | |
| def example1(): | |
| return 30.5, 75.0, 3.2, 40, 15, 20 | |
| # Example input 2 | |
| def example2(): | |
| return 35, 12, 88, 185, 190, 160 | |
| # Define button actions | |
| example1_btn.click(example1, [], [tempreature, humidity, water_level, N, P, K]) | |
| example2_btn.click(example2, [], [tempreature, humidity, water_level, N, P, K]) | |
| submit_btn.click( | |
| predict_actuators, | |
| [tempreature, humidity, water_level, N, P, K], | |
| [water_pump_status, watering_plant_status, fan_actuator_status], | |
| ) | |
| # Launch the app | |
| app.launch() | |