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()