File size: 3,126 Bytes
f497077
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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()