|
import gradio as gr |
|
import numpy as np |
|
import os |
|
from joblib import load |
|
from tensorflow.keras.models import load_model |
|
|
|
|
|
|
|
|
|
|
|
def predict_energy(f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13): |
|
|
|
weather_input_array = np.array([f1,f2,f3,f4,f5,f6]).reshape(1,-1) |
|
|
|
scaler = load("scaler.joblib") |
|
scaled_weather_input_array = scaler.transform(weather_input_array) |
|
history_input_array = np.array([f7,f8,f9,f10,f11,f12,f13]) |
|
input_feature = np.concatenate((scaled_weather_input_array[0],history_input_array[0])) |
|
lstm_model_7_in_1_out = load_model('history_7_future_1.h5') |
|
|
|
|
|
|
|
output = model.predict(input_feature) |
|
output = output[0][0] |
|
return output |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inputs_app = [gr.inputs.Slider(0,12, step=1, label='Month', default=11), |
|
gr.inputs.Slider(0,23, step=1, label='Hour', default=16), |
|
gr.inputs.Slider(-4,33, step=1, label='Temperature', default=9.84), |
|
gr.inputs.Slider(0.2,1, step=0.5, label='Humidity', default=0.86), |
|
gr.inputs.Slider(0.04,15, step=0.5, label='windSpeed', default=2.95), |
|
gr.inputs.Slider(0,1, step=1, label='Holiday = 1', default=0), |
|
gr.inputs.Slider(0,1, step=0.005, label='t-1 energy consumption', default=0.38), |
|
gr.inputs.Slider(0,1, step=0.005, label='t-2 energy consumption', default=0.48), |
|
gr.inputs.Slider(0,1, step=0.005, label='t-3 energy consumption', default=0.48), |
|
gr.inputs.Slider(0,1, step=0.005, label='t-4 energy consumption', default=0.66), |
|
gr.inputs.Slider(0,1, step=0.005, label='t-5 energy consumption', default=0.30), |
|
gr.inputs.Slider(0,1, step=0.005, label='t-6 energy consumption', default=0.25), |
|
gr.inputs.Slider(0,1, step=0.005, label='t-7 energy consumption', default=0.57) |
|
|
|
] |
|
|
|
|
|
outputs_app = ["text"] |
|
|
|
|
|
weather_predictor_app = gr.Interface(fn=predict_energy, |
|
inputs=inputs_app, |
|
outputs=outputs_app, |
|
allow_flagging="manual", |
|
live=True, |
|
|
|
|
|
|
|
title = "Energy Consumption Prediction (London)", |
|
description="Enter parameters using sliders provided to predict the weather.", |
|
theme = "darkhuggingface", |
|
css="footer {visibility: hidden}", |
|
flagging_callback=hf_writer |
|
) |
|
|
|
weather_predictor_app.launch() |