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.inputs.Number(label="Dew Point"), gr.inputs.Number(label="Pressure"), gr.inputs.Number(label="Gust Speed"), gr.inputs.Number(label="Relative Humidity"), gr.inputs.Number(label="Wind Direction"), gr.inputs.Number(label="Wind Speed"), gr.inputs.Number(label="Temperature"), gr.inputs.Number(label="Rained"), gr.inputs.Number(label="Water Content"), gr.inputs.Number(label="Solar Radiation") ] output = gr.outputs.Textbox(label="Prediction") gr.Interface(fn=predict_rainfall, inputs=inputs, outputs=output, title="Rainfall Prediction").launch()