RAINFALL / app.py
mistermprah's picture
Update app.py
1da15ff verified
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()