Abrar20 commited on
Commit
f497077
Β·
verified Β·
1 Parent(s): b5dbc04

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -0
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import joblib
4
+
5
+ # Define the features
6
+ features = ['tempreature', 'humidity', 'water_level', 'N', 'P', 'K']
7
+
8
+ # Load the models
9
+ water_pump_model = joblib.load("xgb_Water_pump_actuator_ON_model.pkl")
10
+ watering_plant_model = joblib.load("xgb_Watering_plant_pump_ON_model.pkl")
11
+ fan_actuator_model = joblib.load("xgb_fan_actuator_model.pkl")
12
+
13
+ # Prediction function
14
+ def predict_actuators(tempreature, humidity, water_level, N, P, K):
15
+ # Input as DataFrame
16
+ input_data = pd.DataFrame([[tempreature, humidity, water_level, N, P, K]], columns=features)
17
+
18
+ # Predictions for each model
19
+ water_pump_pred = water_pump_model.predict(input_data)[0]
20
+ watering_plant_pred = watering_plant_model.predict(input_data)[0]
21
+ fan_actuator_pred = fan_actuator_model.predict(input_data)[0]
22
+
23
+ # Interpret predictions
24
+ water_pump_status = "The Water Pump Actuator is Turning On. 🚰" if water_pump_pred == 1 else "The Water Pump Actuator is Off. ❌"
25
+ watering_plant_status = "The Watering Plant Pump is Turning On. 🌱" if watering_plant_pred == 1 else "The Watering Plant Pump is Off. ❌"
26
+ fan_actuator_status = "The Fan Actuator is Turning On. πŸ’¨" if fan_actuator_pred == 1 else "The Fan Actuator is Off. ❌"
27
+
28
+ return water_pump_status, watering_plant_status, fan_actuator_status
29
+
30
+ # Create Gradio interface
31
+ with gr.Blocks() as app:
32
+ gr.Markdown("# 🌾 Smart Automated Irrigation System 🌿")
33
+ gr.Markdown("Enter the environmental and nutrient parameters below to predict the actuator status for your irrigation system.")
34
+
35
+ with gr.Row():
36
+ tempreature = gr.Number(label="Temperature (Β°C)", value=30.5)
37
+ humidity = gr.Number(label="Humidity (%)", value=75.0)
38
+ water_level = gr.Number(label="Water Level (cm)", value=3.2)
39
+ N = gr.Number(label="Nitrogen (N)", value=40)
40
+ P = gr.Number(label="Phosphorus (P)", value=15)
41
+ K = gr.Number(label="Potassium (K)", value=20)
42
+
43
+ with gr.Row():
44
+ example1_btn = gr.Button("Use Example Input 1 (30.5, 75.0, 3.2, 40, 15, 20)")
45
+ example2_btn = gr.Button("Use Example Input 2 (35, 12, 88, 185, 190, 160)")
46
+
47
+ submit_btn = gr.Button("Predict Actuator Status")
48
+
49
+ with gr.Row():
50
+ water_pump_status = gr.Textbox(label="Water Pump Status", interactive=False)
51
+ watering_plant_status = gr.Textbox(label="Watering Plant Pump Status", interactive=False)
52
+ fan_actuator_status = gr.Textbox(label="Fan Actuator Status", interactive=False)
53
+
54
+ # Example input 1
55
+ def example1():
56
+ return 30.5, 75.0, 3.2, 40, 15, 20
57
+
58
+ # Example input 2
59
+ def example2():
60
+ return 35, 12, 88, 185, 190, 160
61
+
62
+ # Define button actions
63
+ example1_btn.click(example1, [], [tempreature, humidity, water_level, N, P, K])
64
+ example2_btn.click(example2, [], [tempreature, humidity, water_level, N, P, K])
65
+ submit_btn.click(
66
+ predict_actuators,
67
+ [tempreature, humidity, water_level, N, P, K],
68
+ [water_pump_status, watering_plant_status, fan_actuator_status],
69
+ )
70
+
71
+ # Launch the app
72
+ app.launch()