Recording Epochs Using Brainflow

Hi Folks,

I have a project to analyze the data and then predict the action in real-time. My problem is that my accuracy is so high between three classes offline, but it is pretty low in real-time. Moreover, in real-time, sometimes, although I record the data for, for example, 30 seconds, suddenly, it will record for 23 seconds or also maybe 28secodns. It is like some lagging issue, or I do not know, but it seems the function time.sleep(30) not exact. The tasks is also moving left hand and right hand and rest.
Here is my code:

from tensorflow.keras.models import load_model
from collections import Counter
from scipy.fft import fft
model = load_model('First_Model.h5')
BoardShim.enable_dev_board_logger()
# use synthetic board for demo
params = BrainFlowInputParams()
params.serial_port = '/dev/cu.usbserial-D200QEPF'
board = BoardShim(BoardIds.CYTON_DAISY_BOARD.value, params)
board.prepare_session()
board.start_stream()
time.sleep(30)
data = board.get_board_data()
board.stop_stream()
board.release_session()
eeg_channels = BoardShim.get_eeg_channels(BoardIds.CYTON_DAISY_BOARD.value)
eeg_data = data[eeg_channels, :]
eeg_data = eeg_data / 1000000  # BrainFlow returns uV, convert to V for MNE
# Creating MNE objects from brainflow data arrays
ch_types = ['eeg'] * len(eeg_channels)
ch_names = BoardShim.get_eeg_names(BoardIds.CYTON_DAISY_BOARD.value)
sfreq = BoardShim.get_sampling_rate(BoardIds.CYTON_DAISY_BOARD.value)
info = mne.create_info(ch_names=ch_names, sfreq=sfreq, ch_types=ch_types)
raw = mne.io.RawArray(eeg_data, info)
LowPass_Freq = 0.5
HighPass_Freq = 50
Resampled_Frequency = 100
Epoch_Duration = 1
OverLap = 0.5
montage = mne.channels.make_standard_montage('standard_1020')
raw.drop_channels(['Fp2', 'O1', 'F4'])
print("Channel names before applying montage:", raw.ch_names)
raw.crop(tmin=2,tmax=30)
raw.filter(l_freq=LowPass_Freq, h_freq=HighPass_Freq)  # Filter before downsampling
raw.resample(sfreq=Resampled_Frequency)
# raw.set_eeg_reference('average')
raw.set_montage(montage)
epochs = mne.make_fixed_length_epochs(raw, duration=Epoch_Duration, overlap=OverLap)
# raw.plot()
All_Epcohs=mne.concatenate_epochs([epochs])
All_Epcohs_Array=All_Epcohs.get_data()
data_array = np.moveaxis(All_Epcohs_Array, 1, 2)
predictions=model.predict(data_array)
predicted_classes = np.argmax(predictions, axis=1)
print(predicted_classes)
# All_Epcohs.plot()