U
    !?h                     @   sV   d dl Z d dlmZ d dlZddlmZ ddlmZ ddl	m
Z
 deedd	d
ZdS )    N)Type   )sessions_class)BaseSession)U2netSessionu2net)
model_namereturnc                 O   sh   t }tD ]}| | kr|} q"qt }dtjkrTttjd |_ttjd |_	|| ||f||S )a  
    Create a new session object based on the specified model name.

    This function searches for the session class based on the model name in the 'sessions_class' list.
    It then creates an instance of the session class with the provided arguments.
    The 'sess_opts' object is created using the 'ort.SessionOptions()' constructor.
    If the 'OMP_NUM_THREADS' environment variable is set, the 'inter_op_num_threads' option of 'sess_opts' is set to its value.

    Parameters:
        model_name (str): The name of the model.
        providers: The providers for the session.
        *args: Additional positional arguments.
        **kwargs: Additional keyword arguments.

    Returns:
        BaseSession: The created session object.
    ZOMP_NUM_THREADS)
r   r   nameortZSessionOptionsosenvironintZinter_op_num_threadsZintra_op_num_threads)r   	providersargskwargsZsession_classscZ	sess_opts r   G/var/www/html/venv/lib/python3.8/site-packages/rembg/session_factory.pynew_session   s    
r   )r   N)r   typingr   Zonnxruntimer   sessionsr   Zsessions.baser   Zsessions.u2netr   strr   r   r   r   r   <module>   s      