File size: 1,584 Bytes
4f82165
d70af30
 
8c73bdf
 
 
d70af30
 
 
 
4f82165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from tensorflow.keras.models import load_model
from tensorflow.keras.initializers import Orthogonal
from tensorflow.keras.utils import CustomObjectScope
from tensorflow.keras.layers import LSTM

lstm_layer = LSTM(64, return_sequences=True, time_major=False)

# Register custom initializers or objects
with CustomObjectScope({'Orthogonal': Orthogonal}):
    model = load_model('models/lstm-combinedmodel.h5')

import pandas as pd

def predict_from_csv(file_path):
    # Load the data
    data = pd.read_csv(file_path)
    
    # Assume your model expects data in a specific order and format
    # Here we reorder the columns if necessary and handle any preprocessing like normalization
    required_columns = ['CAN ID', 'RTR', 'DLC', 'Data1', 'Data2', 'Data3', 'Data4', 'Data5', 'Data6', 'Data7', 'Data8']
    data = data[required_columns]
    
    # Convert data to numpy array or the format your model expects
    input_data = data.values
    
    # Predict using the model
    predictions = model.predict(input_data)
    
    # Here, you could process the predictions to a more readable format if needed
    return predictions

def interface_func(file_info):
    # Get the path of the uploaded file
    filepath = file_info["path"]
    # Use the prediction function
    prediction = predict_from_csv(filepath)
    return prediction

iface = gr.Interface(fn=interface_func,
                     inputs=gr.inputs.File(label="Upload CSV"),
                     outputs="text",
                     description="Upload a CSV file with the specified columns to predict.")

iface.launch()