File size: 3,017 Bytes
facb76c 2369f0c facb76c 69d8efa 8906400 cb1fee4 93a4dd9 6a24129 facb76c cb1fee4 facb76c 3cdcdc1 d6bf0e6 facb76c 987f5a5 ede6aa5 987f5a5 ede6aa5 facb76c c4ea787 bae98f9 facb76c bae98f9 add832c 97a23d3 81058b9 594cda1 d3ee645 b80a3ba adfed2d facb76c a5129d2 |
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 |
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 = [f1,f2,f3,f4,f5,f6]
history_input =[f7,f8,f9,f10,f11,f12,f13]
weather_input_array = np.array(weather_input).reshape(1,-1)
history_input_array = np.array(history_input).reshape(1,-1)
scaler = load("scaler.joblib")
scaled_weather_input_array = scaler.transform(weather_input_array)
input_feature = np.concatenate((scaled_weather_input_array[0],history_input_array[0]))
model = load_model('history_7_future_1.h5')
output = model.predict(input_feature.reshape(1,1,-1))
output = output[0][0]
return output
# Interface Inputs
inputs_app = [gr.Slider(0,12, step=1, label='Month', value=11),
gr.Slider(0,23, step=1, label='Hour', value=20),
gr.Slider(-4,33, step=1, label='Temperature', value=8.69),
gr.Slider(0.2,1, step=0.5, label='Humidity', value=0.93),
gr.Slider(0.04,15, step=0.5, label='windSpeed', value=2.96),
gr.Slider(0,1, step=1, label='Holiday = 1', value=0),
gr.Slider(0,1, step=0.005, label='t-7 energy consumption', value=0.482),
gr.Slider(0,1, step=0.005, label='t-6 energy consumption', value=0.476),
gr.Slider(0,1, step=0.005, label='t-5 energy consumption', value=0.377),
gr.Slider(0,1, step=0.005, label='t-4 energy consumption', value=0.374),
gr.Slider(0,1, step=0.005, label='t-3 energy consumption', value=0.475),
gr.Slider(0,1, step=0.005, label='t-2 energy consumption', value=0.523),
gr.Slider(0,1, step=0.005, label='t-1 energy consumption', value=0.774)
]
#Interface Output
outputs_app = ["number"]
# Building the Gradio Interface
weather_predictor_app = gr.Interface(fn=predict_energy,
inputs=inputs_app,
outputs=outputs_app,
# allow_flagging="manual",
# live=True,
examples = [[2,23,3.93,0.85,2.75,0,0.428821,0.507056,0.658782,0.722878,0.694360,0.657011,0.587121],
[8,15,23.34,0.45,5.32,0,0.341136,0.337360,0.332931,0.336212,0.338439,0.327198,0.316899],
[12,8,2.10,0.96,1.34,0.0,0.327180,0.278838,0.253315,0.247601,0.262393,0.326879,0.458636]],
title = "Average Energy Consumption (per household) Prediction using Custom LSTM (London)",
description="Enter parameters using sliders provided to predict the next hour's energy consumption. \n Answer for demo's data are available under Files -> samples.csv -> var1(t).")
weather_predictor_app.launch(share=True) |