o
    ϯiD                     @   s,  d dl Z d dlZd dlZd dlZd dlmZ eddddZeddddZeddd	Zeddd	Z	ed
dZ
eddZeddZedddddZedddddZeddZeddZeeee	e
eeeeed
Zd'defddZdefddZdefddZdedefd d!Zejd"fd#ed$efd%d&ZdS )(    N)tqdmzwhttps://openaipublic.azureedge.net/clip/models/afeb0e10f9e5a86da6080e35cf09123aca3b358a0c3e3b6c78a7b63bc04b6762/RN50.ptzlhttps://github.com/mlfoundations/open_clip/releases/download/v0.2-weights/rn50-quickgelu-yfcc15m-455df137.ptzjhttps://github.com/mlfoundations/open_clip/releases/download/v0.2-weights/rn50-quickgelu-cc12m-f000538c.pt)openaiyfcc15mcc12mzxhttps://openaipublic.azureedge.net/clip/models/8fa8567bab74a42d41c5915025a8e4538c3bdbe8804a470a72f30b0d94fab599/RN101.ptzmhttps://github.com/mlfoundations/open_clip/releases/download/v0.2-weights/rn101-quickgelu-yfcc15m-3e04b30e.pt)r   r   zyhttps://openaipublic.azureedge.net/clip/models/7e526bd135e493cef0776de27d5f42653e6b4c8bf9e0f653bb11773263205fdd/RN50x4.pt)r   zzhttps://openaipublic.azureedge.net/clip/models/52378b407f34354e150460fe41077663dd5b39c54cd0bfd2b27167a4a06ec9aa/RN50x16.ptzzhttps://openaipublic.azureedge.net/clip/models/be1cfb55d75a9666199fb2206c106743da0f6468c9d327f3e0d0a543a9919d9c/RN50x64.ptz{https://openaipublic.azureedge.net/clip/models/40d365715913c9da98579312b702a82c18be219cc2a73407c4526f58eba950af/ViT-B-32.ptzvhttps://github.com/mlfoundations/open_clip/releases/download/v0.2-weights/vit_b_32-quickgelu-laion400m_e31-d867053b.ptzvhttps://github.com/mlfoundations/open_clip/releases/download/v0.2-weights/vit_b_32-quickgelu-laion400m_e32-46683a32.ptzvhttps://github.com/mlfoundations/open_clip/releases/download/v0.2-weights/vit_b_32-quickgelu-laion400m_avg-8a00ab3c.pt)r   laion400m_e31laion400m_e32laion400m_avgz{https://openaipublic.azureedge.net/clip/models/5806e77cd80f8b59890b7e101eabd078d9fb84e6937f9e85e4ecb61988df416f/ViT-B-16.ptz{https://openaipublic.azureedge.net/clip/models/b8cca3fd41ae0c99ba7e8951adf17d267cdb84cd88be6f7c2e0eca1737a03836/ViT-L-14.pt)
RN50zRN50-quickgeluRN101zRN101-quickgeluRN50x4RN50x16zViT-B-32zViT-B-32-quickgeluzViT-B-16zViT-L-14Fas_strc                    s    fddt  D S )z returns list of pretrained models
    Returns a tuple (model_name, pretrain_tag) by default or 'name:tag' if as_str == True
    c                    s8   g | ]}t |  D ]} rd ||gn||fq
qS ):)_PRETRAINEDkeysjoin).0ktr    U/home/ubuntu/.local/lib/python3.10/site-packages/laion_clap/clap_module/pretrained.py
<listcomp>R   s   8 z#list_pretrained.<locals>.<listcomp>)r   r   r   r   r   r   list_pretrainedN   s   r   tagc                 C   s,   g }t  D ]}| t | v r|| q|S )z5 return all models having the specified pretrain tag )r   r   append)r   modelsr   r   r   r   list_pretrained_tag_modelsU   s   
r   modelc                 C   s"   g }| t v r|t |    |S )z? return all pretrain tags for the specified model architecture )r   extendr   )r   tagsr   r   r   list_pretrained_model_tags^   s   r!   c                 C   s(   | t vrdS t |  }||vrdS || S )N )r   )r   r   model_pretrainedr   r   r   get_pretrained_urlf   s   r$   z~/.cache/clipurlrootc           	   
   C   s  t j|dd t j| }d| v r| dd }nd}t j||}t j|r5t j|s5t| dt j|rX|rVt	
t|d  |krM|S t| d	 n|S tj| R}t|d
=}tt| ddddd}	 |d}|s~n|| |t| qvW d    n1 sw   Y  W d    n1 sw   Y  W d    n1 sw   Y  |rt	
t|d  |krtd|S )NT)exist_okopenaipublic/r"   z! exists and is not a regular filerbzH exists, but the SHA256 checksum does not match; re-downloading the filewbzContent-LengthP   iB)totalncolsunit
unit_scalei    zDModel has been downloaded but the SHA256 checksum does not not match)osmakedirspathbasenamesplitr   existsisfileRuntimeErrorhashlibsha256openread	hexdigestwarningswarnurllibrequesturlopenr   intinfogetwriteupdatelen)	r%   r&   filenameexpected_sha256download_targetsourceoutputloopbufferr   r   r   download_pretrainedo   s@    

  
rR   )F)r;   r3   rB   r@   r   dict_RN50_RN50_quickgelu_RN101_RN101_quickgelu_RN50x4_RN50x16_RN50x64_VITB32_VITB32_quickgelu_VITB16_VITL14r   boolr   strr   r!   r$   r5   
expanduserrR   r   r   r   r   <module>   s    	"	