Spaces:
Sleeping
Sleeping
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() |