wissemkarous commited on
Commit
8a2c474
1 Parent(s): 59d907e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -17
app.py CHANGED
@@ -1,23 +1,22 @@
1
  from tensorflow.keras.models import load_model
2
  from tensorflow.keras.initializers import Orthogonal
3
- from tensorflow.keras.utils import CustomObjectScope
4
  from tensorflow.keras.layers import LSTM
5
  import gradio as gr
 
6
 
7
- lstm_layer = LSTM(64, return_sequences=True, time_major=False)
 
8
 
9
- # Register custom initializers or objects
10
- with CustomObjectScope({'Orthogonal': Orthogonal}):
11
  model = load_model('models/lstm-combinedmodel.h5')
12
 
13
- import pandas as pd
14
-
15
  def predict_from_csv(file_path):
16
- # Load the data
17
  data = pd.read_csv(file_path)
18
 
19
- # Assume your model expects data in a specific order and format
20
- # Here we reorder the columns if necessary and handle any preprocessing like normalization
21
  required_columns = ['CAN ID', 'RTR', 'DLC', 'Data1', 'Data2', 'Data3', 'Data4', 'Data5', 'Data6', 'Data7', 'Data8']
22
  data = data[required_columns]
23
 
@@ -27,15 +26,13 @@ def predict_from_csv(file_path):
27
  # Predict using the model
28
  predictions = model.predict(input_data)
29
 
30
- # Here, you could process the predictions to a more readable format if needed
31
- return predictions
32
 
33
- def interface_func(file_info):
34
- # Get the path of the uploaded file
35
- filepath = file_info["path"]
36
- # Use the prediction function
37
- prediction = predict_from_csv(filepath)
38
- return prediction
39
 
40
  iface = gr.Interface(fn=interface_func,
41
  inputs=gr.File(label="Upload CSV"),
 
1
  from tensorflow.keras.models import load_model
2
  from tensorflow.keras.initializers import Orthogonal
3
+ from tensorflow.keras.utils import custom_object_scope
4
  from tensorflow.keras.layers import LSTM
5
  import gradio as gr
6
+ import pandas as pd
7
 
8
+ # Initialize LSTM layer correctly without time_major
9
+ lstm_layer = LSTM(64, return_sequences=True)
10
 
11
+ # Register custom initializers or objects when loading the model
12
+ with custom_object_scope({'Orthogonal': Orthogonal}):
13
  model = load_model('models/lstm-combinedmodel.h5')
14
 
 
 
15
  def predict_from_csv(file_path):
16
+ # Load the data from CSV
17
  data = pd.read_csv(file_path)
18
 
19
+ # Reorder and preprocess data if necessary
 
20
  required_columns = ['CAN ID', 'RTR', 'DLC', 'Data1', 'Data2', 'Data3', 'Data4', 'Data5', 'Data6', 'Data7', 'Data8']
21
  data = data[required_columns]
22
 
 
26
  # Predict using the model
27
  predictions = model.predict(input_data)
28
 
29
+ # Process predictions to readable format if needed
30
+ return str(predictions)
31
 
32
+ def interface_func(uploaded_file):
33
+ # Use the prediction function on the uploaded file path
34
+ predictions = predict_from_csv(uploaded_file.name)
35
+ return predictions
 
 
36
 
37
  iface = gr.Interface(fn=interface_func,
38
  inputs=gr.File(label="Upload CSV"),