Please edit the function that loads the txt file so that it can load multiple files and merge their content into a single file to be passed for training, code: import tkinter as tk
from tkinter import filedialog
from keras.models import Sequential
from keras.layers import Embedding, LSTM, Dense
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
from keras.utils import to_categorical
import numpy as np
import os
import pickle

# Data loader and preprocessor function
def preprocess_data(file_path, sequence_length=5):
   # Initialize the tokenizer
   tokenizer = Tokenizer()
   # Load your dataset
   with open(file_path, 'r', encoding='utf-8') as file:
       text = file.read()

   # Split by lines or sentences (customize based on how your data is formatted)
   sentences = text.split('\n')

   # Fit the tokenizer on the sentences
   tokenizer.fit_on_texts(sentences)

   # Convert sentences to sequences
   sequences = tokenizer.texts_to_sequences(sentences)

   # Flatten the list of sequences into one big sequence and create input-output pairs
   big_sequence = [token for seq in sequences for token in seq]
   input_sequences, output_words = [], []
   for i in range(0, len(big_sequence) - sequence_length):
       input_sequences.append(big_sequence[i:i + sequence_length])
       output_words.append(big_sequence[i + sequence_length])
       
   # Pad the sequences
   input_sequences = pad_sequences(input_sequences, maxlen=sequence_length)
   
   # Get the total number of unique tokens
   vocab_size = len(tokenizer.word_index) + 1 # Plus 1 for zero padding
   
   # Convert output words to one-hot encoding
   output_words = np.array(output_words)
   output_words = to_categorical(output_words, num_classes=vocab_size)
   
   return input_sequences, output_words, vocab_size, tokenizer


# Function to train and save the model
def train_model():
   # Get input values
    num_layers = int(entry_layers.get())
    layer_size = int(entry_size.get())
    model_name = entry_name.get()
    epochs = int(entry_epochs.get())
    data_path = entry_data_path.get()
   
    # Preprocess the data
    input_sequences, output_words, vocab_size, tokenizer = preprocess_data(data_path)

    # Inside the train_model function, after the tokenizer is fitted
    tokenizer_path = os.path.join('tokenizers', f'{model_name}_tokenizer.pickle')
    if not os.path.exists('tokenizers'):
        os.makedirs('tokenizers')
    with open(tokenizer_path, 'wb') as handle:
        pickle.dump(tokenizer, handle, protocol=pickle.HIGHEST_PROTOCOL)
    print(f"Tokenizer saved at {tokenizer_path}")
    
    # Define the model architecture
    model = Sequential()
    model.add(Embedding(input_dim=vocab_size, output_dim=layer_size, input_length=input_sequences.shape[1]))
    for _ in range(num_layers - 1):  # -1 because the last layer is added after the loop
        model.add(LSTM(units=layer_size, return_sequences=True))
    model.add(LSTM(units=layer_size))
    model.add(Dense(vocab_size, activation='softmax'))  # Multiclass classification for next word prediction

    # Compile the model
    model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

    # Train the model
    model.fit(input_sequences, output_words, epochs=epochs)

    # Save the model
    if not os.path.exists('models'):
        os.makedirs('models')
    model.save(os.path.join('models', f'{model_name}.h5'))
    print(f"Model {model_name} trained and saved successfully!")

# UI Setup
root = tk.Tk()
root.title("Chatbot Language Model Trainer")

# Number of layers
lbl_layers = tk.Label(root, text="Number of layers:")
lbl_layers.pack()
entry_layers = tk.Entry(root)
entry_layers.pack()

# Layer size
lbl_size = tk.Label(root, text="Size of each layer:")
lbl_size.pack()
entry_size = tk.Entry(root)
entry_size.pack()

# Model name
lbl_name = tk.Label(root, text="Model name:")
lbl_name.pack()
entry_name = tk.Entry(root)
entry_name.pack()

# Number of epochs
lbl_epochs = tk.Label(root, text="Number of epochs:")
lbl_epochs.pack()
entry_epochs = tk.Entry(root)
entry_epochs.pack()

# Data file path
lbl_data_path = tk.Label(root, text="Data file path:")
lbl_data_path.pack()
entry_data_path = tk.Entry(root)
entry_data_path.pack()

def select_file():
    file_path = filedialog.askopenfilename()
    entry_data_path.delete(0, tk.END)
    entry_data_path.insert(0, file_path)

btn_browse = tk.Button(root, text="Browse...", command=select_file)
btn_browse.pack()

# Train button
btn_train = tk.Button(root, text="Train Model", command=train_model)
btn_train.pack()

# Start the tkinter loop
root.mainloop()