Spaces:
Sleeping
Sleeping
File size: 1,468 Bytes
e2a1faa 1da15ff e2a1faa 1da15ff e2a1faa |
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 |
import numpy as np
import joblib
from tensorflow.keras.models import load_model
import gradio as gr
# Load the saved scaler and model
scaler = joblib.load('scaler.joblib')
model = load_model('rainfall_prediction_model.h5')
def predict_rainfall(Dew_Point, Pressure, Gust_Speed, RH, Wind_Direction,
Wind_Speed, Temperature, Rained, Water_Content, Solar_Radiation):
# Preprocess the input data
input_data = np.array([[Dew_Point, Pressure, Gust_Speed, RH, Wind_Direction,
Wind_Speed, Temperature, Rained, Water_Content, Solar_Radiation]])
input_data_scaled = scaler.transform(input_data)
input_data_scaled = input_data_scaled.reshape((input_data_scaled.shape[0], 1, input_data_scaled.shape[1]))
# Make a prediction
prediction = model.predict(input_data_scaled)
# Output the prediction
return 'Rain' if prediction[0][0] > 0 else 'No Rain'
# Gradio Interface
inputs = [
gr.Number(label="Dew Point"),
gr.Number(label="Pressure"),
gr.Number(label="Gust Speed"),
gr.Number(label="Relative Humidity"),
gr.Number(label="Wind Direction"),
gr.Number(label="Wind Speed"),
gr.Number(label="Temperature"),
gr.Number(label="Rained"),
gr.Number(label="Water Content"),
gr.Number(label="Solar Radiation")
]
output = gr.Textbox(label="Prediction")
gr.Interface(fn=predict_rainfall, inputs=inputs, outputs=output, title="Rainfall Prediction").launch()
|