File size: 1,612 Bytes
cce7692
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import joblib
import pandas as pd
import gradio as gr
from datetime import datetime

# Load the trained model
model = joblib.load('power_consumption_model.pkl')

# Function to preprocess input and make predictions
def predict_power_consumption(global_reactive_power, voltage, global_intensity, sub_metering_1, sub_metering_2, sub_metering_3, hour, day, month):
    # Create a DataFrame from the input
    input_data = pd.DataFrame({
        'Global_reactive_power': [global_reactive_power],
        'Voltage': [voltage],
        'Global_intensity': [global_intensity],
        'Sub_metering_1': [sub_metering_1],
        'Sub_metering_2': [sub_metering_2],
        'Sub_metering_3': [sub_metering_3],
        'Hour': [hour],
        'Day': [day],
        'Month': [month]
    })
    
    # Make a prediction
    prediction = model.predict(input_data)
    return prediction[0]

# Gradio interface
inputs = [
    gr.Number(label="Global Reactive Power"),
    gr.Number(label="Voltage"),
    gr.Number(label="Global Intensity"),
    gr.Number(label="Sub Metering 1"),
    gr.Number(label="Sub Metering 2"),
    gr.Number(label="Sub Metering 3"),
    gr.Slider(0, 23, step=1, label="Hour"),
    gr.Slider(1, 31, step=1, label="Day"),
    gr.Slider(1, 12, step=1, label="Month")
]

outputs = gr.Number(label="Predicted Global Active Power")

# Create the Gradio app
app = gr.Interface(
    fn=predict_power_consumption,
    inputs=inputs,
    outputs=outputs,
    title="Power Consumption Prediction",
    description="Predict global active power consumption based on input features."
)

# Launch the app
app.launch()