|
import gradio as gr |
|
import pandas as pd |
|
import joblib |
|
|
|
|
|
features = ['tempreature', 'humidity', 'water_level', 'N', 'P', 'K'] |
|
|
|
|
|
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") |
|
|
|
|
|
def predict_actuators(tempreature, humidity, water_level, N, P, K): |
|
|
|
input_data = pd.DataFrame([[tempreature, humidity, water_level, N, P, K]], columns=features) |
|
|
|
|
|
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] |
|
|
|
|
|
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 |
|
|
|
|
|
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) |
|
|
|
|
|
def example1(): |
|
return 30.5, 75.0, 3.2, 40, 15, 20 |
|
|
|
|
|
def example2(): |
|
return 35, 12, 88, 185, 190, 160 |
|
|
|
|
|
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], |
|
) |
|
|
|
|
|
app.launch() |
|
|