from core.models.BaseModel import BaseModel
from core.models.OrderingModel import OrderingModel
from functools import lru_cache


@lru_cache(maxsize=50)
def create_model(model_name, dataset, seed, label=None, sharpness=None):
    # Create new model
    if model_name == 'BaseModel':
        model = BaseModel(dataset, seed)
    elif model_name == 'OrderingModel':
        if sharpness is None:
            sharpness = 10
        model = OrderingModel(dataset, label, seed, sharpness)
    else:
        raise ValueError(f"Model {model_name} not found")

    model.load(model.path)
    return model


def clear_model_cache():
    """Clear the model cache. Useful for memory management."""
    create_model.cache_clear()
