nikethanreddy commited on
Commit
1e1a4ef
·
verified ·
1 Parent(s): ce828d7

Upload 6 files

Browse files
Files changed (6) hide show
  1. app.py +25 -0
  2. best_model_TKAN_nahead_1.h5 +3 -0
  3. final.csv +0 -0
  4. requirements.txt +5 -0
  5. tkan.py +18 -0
  6. tkat.py +16 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from tensorflow.keras.models import load_model
4
+ from tkan import TKAN
5
+ from tkat import TKAT
6
+ from keras.utils import custom_object_scope
7
+
8
+ # Load the model with custom objects
9
+ with custom_object_scope({"TKAN": TKAN, "TKAT": TKAT}):
10
+ model = load_model("best_model_TKAN_nahead_1.h5")
11
+
12
+ # Define predict function
13
+ def predict(pm25, pm10, co, temp):
14
+ input_data = np.array([[pm25, pm10, co, temp]])
15
+ output = model.predict(input_data)
16
+ return float(output[0][0])
17
+
18
+ # Gradio interface
19
+ interface = gr.Interface(
20
+ fn=predict,
21
+ inputs=[gr.Number(), gr.Number(), gr.Number(), gr.Number()],
22
+ outputs=gr.Number()
23
+ )
24
+
25
+ interface.launch()
best_model_TKAN_nahead_1.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dbbb02d8bfc51e23d05291151a330448efc27086afb59b10a54060714b7abbb5
3
+ size 856432
final.csv ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ tensorflow==2.15.0
3
+ numpy==1.26.4
4
+ pandas==2.1.3
5
+ matplotlib==3.9.2
tkan.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ from tensorflow.keras import layers
3
+
4
+ class TKAN(tf.keras.layers.Layer):
5
+ def __init__(self, units, **kwargs):
6
+ super(TKAN, self).__init__(**kwargs)
7
+ self.units = units
8
+ self.dense1 = layers.Dense(units, activation="relu")
9
+ self.dense2 = layers.Dense(units, activation="relu")
10
+
11
+ def call(self, inputs):
12
+ x = self.dense1(inputs)
13
+ return self.dense2(x)
14
+
15
+ def get_config(self):
16
+ config = super(TKAN, self).get_config()
17
+ config.update({"units": self.units})
18
+ return config
tkat.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ from tensorflow.keras.layers import Layer, Dense
3
+
4
+ class AttentionLayer(Layer):
5
+ def __init__(self, units):
6
+ super(AttentionLayer, self).__init__()
7
+ self.W1 = Dense(units)
8
+ self.W2 = Dense(units)
9
+ self.V = Dense(1)
10
+
11
+ def call(self, query, values):
12
+ score = self.V(tf.nn.tanh(self.W1(query) + self.W2(values)))
13
+ attention_weights = tf.nn.softmax(score, axis=1)
14
+ context_vector = attention_weights * values
15
+ context_vector = tf.reduce_sum(context_vector, axis=1)
16
+ return context_vector, attention_weights