import zipfile
import tempfile


def training_model_archive(filepath):
    """
    Create zip archive file for training model.
    :param filepath:
    :return: temporary archive file
    """
    if zipfile.is_zipfile(filepath):
        return open(filepath, 'rb')
    tmp_file = tempfile.NamedTemporaryFile(suffix='.zip')
    with zipfile.ZipFile(tmp_file.name, 'w', compression=zipfile.ZIP_DEFLATED) as new_zip:
        new_zip.write(filepath)
    tmp_file.seek(0)
    return tmp_file