ShreehariS754 commited on
Commit
fa3146d
·
verified ·
1 Parent(s): f3bc4fa

Initial Commit

Browse files
Best_GRU_solar_insolation_model.keras ADDED
Binary file (175 kB). View file
 
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import pickle
4
+ from tensorflow.keras.models import load_model
5
+
6
+ # Load the saved model and scaler
7
+ model = load_model('Best_GRU_solar_insolation_model.keras')
8
+ with open('scaler.pkl', 'rb') as f:
9
+ scaler = pickle.load(f)
10
+
11
+ # Preprocessing function for Gradio input (scaling + sin/cos transformations)
12
+ def preprocess_input(year, month, day, hour):
13
+ # Sin/Cos transformations
14
+ day_sin = np.sin(2 * np.pi * day / 31)
15
+ day_cos = np.cos(2 * np.pi * day / 31)
16
+ month_sin = np.sin(2 * np.pi * month / 12)
17
+ month_cos = np.cos(2 * np.pi * month / 12)
18
+ hour_sin = np.sin(2 * np.pi * hour / 24)
19
+ hour_cos = np.cos(2 * np.pi * hour / 24)
20
+
21
+ # Combine the features
22
+ input_data = np.array([year, day_sin, day_cos, month_sin, month_cos, hour_sin, hour_cos]).reshape(1, -1)
23
+
24
+ # Scale the input using the saved scaler
25
+ input_scaled = scaler.transform(input_data)
26
+
27
+ # Reshape the scaled input for the model
28
+ return np.expand_dims(input_scaled, axis=-1)
29
+
30
+ # Prediction function for Gradio
31
+ def predict_solar_insolation(year, month, day, hour):
32
+ input_data = preprocess_input(year, month, day, hour)
33
+ prediction = model.predict(input_data)
34
+ return round(float(prediction[0][0]), 3) if float(prediction[0][0])>10 else 0
35
+
36
+ # Gradio client
37
+ app = gr.app(fn=predict_solar_insolation,
38
+ inputs=[gr.Number(label="Year"),
39
+ gr.Number(label="Month"),
40
+ gr.Number(label="Day"),
41
+ gr.Number(label="Hour")],
42
+ outputs="number")
43
+
44
+ app.launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio
2
+ numpy
3
+ pandas
4
+ scikit-learn
5
+ tensorflow
6
+ matplotlib
scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:937b91f3028ec6b61b4131e5877e7218eafccc4091e895a236542edfcc6d4bf8
3
+ size 923