import gradio as gr import numpy as np import os from joblib import load from tensorflow.keras.models import load_model # HF_TOKEN = os.getenv("HF_TOKEN") # hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "weather-madrid-flags") def predict_energy(f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13): # input_feature = [f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13] # if f0 is not None: # if f= == "Custom LSTM": weather_input_array = [f1,f2,f3,f4,f5,f6] history_input_array =[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') # dtc = load('dtc_model.sav') # xgb = load('xgb_model.sav') output = model.predict(input_feature.reshape(1,1,-1)) output = output[0][0] return output # if input_feature is not None: # if f1 == "Decision Trees": # model = dtc.predict(input_feature) # elif f1 == "Random Forest": # model = rfc.predict(input_feature) # elif f1 == "XGBoost": # model = xgb.predict(input_feature) # elif f1 is None: # return "Please select an algorithm to use." # else: # pass # if model[0] == 0: # return "The forecasted weather using the " + str(f1) + " algorithm is: Extreme" # elif model[0] == 1: # return "The forecasted weather using the " + str(f1) + " algorithm is: Fog" # elif model[0] == 2: # return "The forecasted weather using the " + str(f1) + " algorithm is: Fog-Rain" # elif model[0] == 3: # return "The forecasted weather using the " + str(f1) + " algorithm is: Nothing" # elif model[0] == 4: # return "The forecasted weather using the " + str(f1) + " algorithm is: Rain" # elif model[0] == 5: # return "The forecasted weather using the " + str(f1) + " algorithm is: Rain-Snow" # elif model[0] == 6: # return "The forecasted weather using the " + str(f1) + " algorithm is: Rain-Thunderstorms" # elif model[0] == 7: # return "The forecasted weather using the " + str(f1) + " algorithm is: Thunderstorms" # else: # pass #Create the input component for Gradio since we are expecting 23 inputs # Interface Inputs inputs_app = [gr.Slider(0,12, step=1, label='Month', value=11), gr.Slider(0,23, step=1, label='Hour', value=16), gr.Slider(-4,33, step=1, label='Temperature', value=9.84), gr.Slider(0.2,1, step=0.5, label='Humidity', value=0.86), gr.Slider(0.04,15, step=0.5, label='windSpeed', value=2.95), gr.Slider(0,1, step=1, label='Holiday = 1', value=0), gr.Slider(0,1, step=0.005, label='t-1 energy consumption', value=0.38), gr.Slider(0,1, step=0.005, label='t-2 energy consumption', value=0.48), gr.Slider(0,1, step=0.005, label='t-3 energy consumption', value=0.48), gr.Slider(0,1, step=0.005, label='t-4 energy consumption', value=0.66), gr.Slider(0,1, step=0.005, label='t-5 energy consumption', value=0.30), gr.Slider(0,1, step=0.005, label='t-6 energy consumption', value=0.25), gr.Slider(0,1, step=0.005, label='t-7 energy consumption', value=0.57) ] #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 = [["Decision Trees", 7,4,2,5,3,2,100,95,76,1010,1008,1004,10,9,4,13,6,0,6,229,1997,1], # ["Random Forest", 37,28,18,7,4,-2,43,18,4,1019,1016,1010,31,29,16,29,13,0,6,244,2015,7], # ["XGBoost", 16,12,8,11,7,4,94,69,52,1014,1012,1009,10,10,10,14,5,0,5,35,2004,10]], # 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()