Ë
    Q^(hiA  ã                   ó\  — d dl Z d dlZd dlmZ d dlmZmZ d dlmZm	Z	m
Z
mZmZ d dlmZ d dlmZmZ d dlmZ d dlmZmZmZmZ d	d
lmZmZ d	dlmZ  ej<                  e«      Z 	 	 d+de!de!fd„Z"	 	 d+de!de!de!fd„Z#dZ$d e«       › d e«       › d e«       › d�Z%defd„Z&defd„Z'	 d,dee!ef   dee	e!ef      fd„Z(e	 d,de!dee!   fd„«       Z)eddddddddddd œ
de!d!e!d"ee*   d#ee!   dee+   d$ee!   d%ee*   d&eee
e!   e!f      d'eee
e!   e!f      d(eee
e!   e!f      d)ee!   fd*„«       Z,y)-é    N)ÚPath)ÚDEFAULT_PROTOCOLÚPicklingError)ÚAnyÚDictÚListÚOptionalÚUnion)Úversion)Ú	constantsÚsnapshot_download)ÚHfApi)ÚSoftTemporaryDirectoryÚget_fastai_versionÚget_fastcore_versionÚget_python_versioné   )ÚloggingÚvalidate_hf_hub_args)Ú_PY_VERSIONÚfastai_min_versionÚfastcore_min_versionc                 óÂ  — t        «       xs
 t        «       dk(  r(t        d| › d|› dt        «       › dt        «       › d�	«      ‚t        j                  t        «       «      }t        j                  t        «       «      }|t        j                  | «      k  rt        d| › dt        «       › d	�«      ‚|t        j                  |«      k  rt        d
|› dt        «       › d�«      ‚y)a+  
    Checks that the installed fastai and fastcore versions are compatible for pickle serialization.

    Args:
        fastai_min_version (`str`, *optional*):
            The minimum fastai version supported.
        fastcore_min_version (`str`, *optional*):
            The minimum fastcore version supported.

    <Tip>
    Raises the following error:

        - [`ImportError`](https://docs.python.org/3/library/exceptions.html#ImportError)
          if the fastai or fastcore libraries are not available or are of an invalid version.

    </Tip>
    zN/Azfastai>=z and fastcore>=z' are required. Currently using fastai==z and fastcore==ú.zD`push_to_hub_fastai` and `from_pretrained_fastai` require a fastai>=z+ version, but you are using fastai version zA which is incompatible. Upgrade with `pip install fastai==2.5.6`.zF`push_to_hub_fastai` and `from_pretrained_fastai` require a fastcore>=ú- version, but you are using fastcore version zD which is incompatible. Upgrade with `pip install fastcore==1.3.27`.N)r   r   ÚImportErrorr   ÚVersion)r   r   Úcurrent_fastai_versionÚcurrent_fastcore_versions       úZ/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/huggingface_hub/fastai_utils.pyÚ_check_fastai_fastcore_versionsr!      s  € ô, 	ÓÒ6Ô"4Ó"6¸5Ò@ÜØÐ)Ð*¨/Ð:NÐ9Oð P2Ü2DÓ2FÐ1Gð HÜ.Ó0Ð1°ð4ó
ð 	
ô %Ÿ_™_Ô-?Ó-AÓBÐÜ&Ÿ™Ô/CÓ/EÓFÐà¤§¡Ð0BÓ CÒCÜðØ*Ð+ð ,Ü"Ó$Ð%ð &ðó
ð 	
ð  ¤'§/¡/Ð2FÓ"GÒGÜðØ.Ð/ð 0Ü,Ó.Ð/ð 0/ð/ó
ð 	
ð Hó    Ústorage_folderc                 ó<  — 	 ddl }t        j                  j                  | › d�«      st        j                  d«       y|j                  | › d�«      }d|j                  «       vrt        j                  d«       y|d   }d|j                  «       vrt        j                  d	«       y|d   }|D �cg c]  }|j                  d
«      sŒ|‘Œ }}t        |«      dk(  rt        j                  d«       nbt        |d   «      j                  d«      d   }	|	dk7  r=t        j                  |	«      t        j                  |«      k  rt        d|› d|	› d�«      ‚|D �cg c]  }|j                  d«      sŒ|‘Œ }
}t        |
«      dk(  rt        j                  d«       yt        |
d   «      j                  d«      d   }|dk7  r>t        j                  |«      t        j                  |«      k  rt        d|› d|› d�«      ‚yy# t        $ r t        d«      ‚w xY wc c}w c c}w )aê  
    Checks that the `pyproject.toml` file in the directory `storage_folder` has fastai and fastcore versions
    that are compatible with `from_pretrained_fastai` and `push_to_hub_fastai`. If `pyproject.toml` does not exist
    or does not contain versions for fastai and fastcore, then it logs a warning.

    Args:
        storage_folder (`str`):
            Folder to look for the `pyproject.toml` file.
        fastai_min_version (`str`, *optional*):
            The minimum fastai version supported.
        fastcore_min_version (`str`, *optional*):
            The minimum fastcore version supported.

    <Tip>
    Raises the following errors:

        - [`ImportError`](https://docs.python.org/3/library/exceptions.html#ImportError)
          if the `toml` module is not installed.
        - [`ImportError`](https://docs.python.org/3/library/exceptions.html#ImportError)
          if the `pyproject.toml` indicates a lower than minimum supported version of fastai or fastcore.

    </Tip>
    r   Nzn`push_to_hub_fastai` and `from_pretrained_fastai` require the toml module. Install it with `pip install toml`.z/pyproject.tomlzàThere is no `pyproject.toml` in the repository that contains the fastai `Learner`. The `pyproject.toml` would allow us to verify that your fastai and fastcore versions are compatible with those of the model you want to load.zbuild-systemzúThere is no `build-system` section in the pyproject.toml of the repository that contains the fastai `Learner`. The `build-system` would allow us to verify that your fastai and fastcore versions are compatible with those of the model you want to load.ÚrequireszòThere is no `requires` section in the pyproject.toml of the repository that contains the fastai `Learner`. The `requires` would allow us to verify that your fastai and fastcore versions are compatible with those of the model you want to load.ÚfastaizPThe repository does not have a fastai version specified in the `pyproject.toml`.ú=é   Ú z*`from_pretrained_fastai` requires fastai>=z$ version but the model to load uses z which is incompatible.ÚfastcorezRThe repository does not have a fastcore version specified in the `pyproject.toml`.z,`from_pretrained_fastai` requires fastcore>=r   )ÚtomlÚModuleNotFoundErrorr   ÚosÚpathÚisfileÚloggerÚwarningÚloadÚkeysÚ
startswithÚlenÚstrÚ	partitionr   r   )r#   r   r   r+   Úpyproject_tomlÚbuild_system_tomlÚpackage_versionsÚpckÚfastai_packagesÚfastai_versionÚfastcore_packagesÚfastcore_versions               r    Ú)_check_fastai_fastcore_pyproject_versionsr@   J   sD  € ð:
Ûô �7‰7�>‰>˜^Ð,¨OÐ<Ô=Ü�‰ðô	
ð 	Ø—Y‘Y .Ð!1°ÐAÓB€Nà˜^×0Ñ0Ó2Ñ2Ü�‰ð.ô	
ð 	Ø& ~Ñ6ÐàÐ*×/Ñ/Ó1Ñ1Ü�‰ð.ô	
ð 	Ø(¨Ñ4Ðð '7ÖS˜s¸#¿.¹.ÈÕ:R’sÐS€OÐSÜ
ˆ?Ó˜qÒ Ü�‰ÐiÕjô ˜_¨QÑ/Ó0×:Ñ:¸3Ó?ÀÑBˆØ˜RÒ¤G§O¡O°NÓ$CÄgÇoÁoÐVhÓFiÒ$iÜðØ.Ð/ð 0Ø"Ð#Ð#:ð<óð ð )9ÖW ¸C¿N¹NÈ:Õ<VšÐWÐÐWÜ
ÐÓ Ò"Ü�‰ÐkÕlô Ð0°Ñ3Ó4×>Ñ>¸sÓCÀAÑFÐØ˜rÒ!¤g§o¡oÐ6FÓ&GÌ'Ï/É/ÐZnÓJoÒ&oÜðØ2Ð3ð 4Ø,Ð-Ð-DðFóð ð 'pÐ!øôu ò 
Üð3ó
ð 	
ð
üòN Tùò Xs#   ‚G< Â0HÃHÅHÅ.HÇ<Hu   ---
tags:
- fastai
---

# Amazing!

ðŸ¥³ Congratulations on hosting your fastai model on the Hugging Face Hub!

# Some next steps
1. Fill out this model card with more information (see the template below and the [documentation here](https://huggingface.co/docs/hub/model-repos))!

2. Create a demo in Gradio or Streamlit using ðŸ¤— Spaces ([documentation here](https://huggingface.co/docs/hub/spaces)).

3. Join the fastai community on the [Fastai Discord](https://discord.com/invite/YKrxeNn)!

Greetings fellow fastlearner ðŸ¤�! Don't forget to delete this content from your model card.


---


# Model card

## Model description
More information needed

## Intended uses & limitations
More information needed

## Training and evaluation data
More information needed
zB[build-system]
requires = ["setuptools>=40.8.0", "wheel", "python=z", "fastai=z", "fastcore=z6"]
build-backend = "setuptools.build_meta:__legacy__"
Úrepo_dirc                 óª   — | dz  }|j                  «       s2|j                  dd¬«      5 }|j                  t        «       ddd«       yy# 1 sw Y   yxY w)z‹
    Creates a model card for the repository.

    Args:
        repo_dir (`Path`):
            Directory where model card is created.
    z	README.mdÚwúutf-8©ÚencodingN)ÚexistsÚopenÚwriteÚREADME_TEMPLATE)rA   Úreadme_pathÚfs      r    Ú_create_model_cardrM   Ó   sZ   € ð ˜[Ñ(€Kà×ÑÔØ×Ñ˜c¨GÐÓ4ð 	%¸Ø�G‰G”OÔ$÷	%ð 	%ð  ÷	%ð 	%úó   ©A	Á	Ac                 óª   — | dz  }|j                  «       s2|j                  dd¬«      5 }|j                  t        «       ddd«       yy# 1 sw Y   yxY w)z—
    Creates a `pyproject.toml` for the repository.

    Args:
        repo_dir (`Path`):
            Directory where `pyproject.toml` is created.
    zpyproject.tomlrC   rD   rE   N)rG   rH   rI   ÚPYPROJECT_TEMPLATE)rA   Úpyproject_pathrL   s      r    Ú_create_model_pyprojectrR   â   s\   € ð Ð 0Ñ0€Nà× Ñ Ô"Ø× Ñ  ¨wÐ Ó7ð 	(¸1Ø�G‰GÔ&Ô'÷	(ð 	(ð #÷	(ð 	(úrN   Úsave_directoryÚconfigc                 ób  — t        «        t        j                  |d¬«       |��t        |t        «      st        dt        |«      › d�«      ‚t        j                  j                  |t        j                  «      }t        |d«      5 }t        j                  ||«       ddd«       t        t        |«      «       t!        t        |«      «       t        |«      | _        t        j                  |d¬«       	 | j#                  dt$        ¬«       y# 1 sw Y   ŒqxY w# t&        $ r t'        d	«      ‚w xY w)
aù  
    Saves a fastai learner to `save_directory` in pickle format using the default pickle protocol for the version of python used.

    Args:
        learner (`Learner`):
            The `fastai.Learner` you'd like to save.
        save_directory (`str` or `Path`):
            Specific directory in which you want to save the fastai learner.
        config (`dict`, *optional*):
            Configuration object. Will be uploaded as a .json file. Example: 'https://huggingface.co/espejelomar/fastai-pet-breeds-classification/blob/main/config.json'.

    <Tip>

    Raises the following error:

        - [`RuntimeError`](https://docs.python.org/3/library/exceptions.html#RuntimeError)
          if the config file provided is not a dictionary.

    </Tip>
    T)Úexist_okNz(Provided config should be a dict. Got: 'ú'rC   ú	model.pkl)ÚfnameÚpickle_protocolzÀYou are using a lambda function, i.e., an anonymous function. `pickle` cannot pickle function objects and requires that all functions have names. One possible solution is to name the function.)r!   r-   ÚmakedirsÚ
isinstanceÚdictÚRuntimeErrorÚtyper.   Újoinr   ÚCONFIG_NAMErH   ÚjsonÚdumprM   r   rR   Úexportr   r   )ÚlearnerrS   rT   r.   rL   s        r    Ú_save_pretrained_fastairf   ñ   s  € ô2 $Ô%ä‡K�K�¨Õ.ð ÐÜ˜&¤$Ô'ÜÐ!IÌ$ÈvË,ÈÐWXÐYÓZÐZÜ�w‰w�|‰|˜N¬I×,AÑ,AÓBˆÜ�$˜‹_ð 	! Ü�I‰I�f˜aÔ ÷	!ô ”t˜NÓ+Ô,ÜœD Ó0Ô1ô ˜Ó'€G„LÜ‡K�K�¨Õ.ð

Ø�‰ØÜ,ð 	õ 	
÷	!ð 	!ûô ò 
ÜðEó
ð 	
ð
ús   ÂDÃ5D ÄDÄD.Úrepo_idÚrevisionc                 óö   — t        «        t        j                  j                  | «      st	        | |dt        «       ¬«      }n| }t        |«       ddlm}  |t        j                  j                  |d«      «      S )ap  
    Load pretrained fastai model from the Hub or from a local directory.

    Args:
        repo_id (`str`):
            The location where the pickled fastai.Learner is. It can be either of the two:
                - Hosted on the Hugging Face Hub. E.g.: 'espejelomar/fatai-pet-breeds-classification' or 'distilgpt2'.
                  You can add a `revision` by appending `@` at the end of `repo_id`. E.g.: `dbmdz/bert-base-german-cased@main`.
                  Revision is the specific model version to use. Since we use a git-based system for storing models and other
                  artifacts on the Hugging Face Hub, it can be a branch name, a tag name, or a commit id.
                - Hosted locally. `repo_id` would be a directory containing the pickle and a pyproject.toml
                  indicating the fastai and fastcore versions used to build the `fastai.Learner`. E.g.: `./my_model_directory/`.
        revision (`str`, *optional*):
            Revision at which the repo's files are downloaded. See documentation of `snapshot_download`.

    Returns:
        The `fastai.Learner` model in the `repo_id` repo.
    r&   )rg   rh   Úlibrary_nameÚlibrary_versionr   )Úload_learnerrX   )
r!   r-   r.   Úisdirr   r   r@   Úfastai.learnerrl   r`   )rg   rh   r#   rl   s       r    Úfrom_pretrained_fastairo   )  sa   € ô. $Ô%ô
 �7‰7�=‰=˜Ô!Ü*ØØØ!Ü.Ó0ô	
‰ð !ˆä-¨nÔ=å+áœŸ™Ÿ™ ^°[ÓAÓBÐBr"   z(Push FastAI model using huggingface_hub.)
Úcommit_messageÚprivateÚtokenrT   ÚbranchÚ	create_prÚallow_patternsÚignore_patternsÚdelete_patternsÚapi_endpointrp   rq   rr   rs   rt   ru   rv   rw   rx   c                ó  — t        «        t        |¬«      }|j                  |||d¬«      j                  }t	        «       5 }t        |«      |z  }t        | ||¬«       |j                  ||||||||	|
¬«	      cddd«       S # 1 sw Y   yxY w)a¼	  
    Upload learner checkpoint files to the Hub.

    Use `allow_patterns` and `ignore_patterns` to precisely filter which files should be pushed to the hub. Use
    `delete_patterns` to delete existing remote files in the same commit. See [`upload_folder`] reference for more
    details.

    Args:
        learner (`Learner`):
            The `fastai.Learner' you'd like to push to the Hub.
        repo_id (`str`):
            The repository id for your model in Hub in the format of "namespace/repo_name". The namespace can be your individual account or an organization to which you have write access (for example, 'stanfordnlp/stanza-de').
        commit_message (`str`, *optional*):
            Message to commit while pushing. Will default to :obj:`"add model"`.
        private (`bool`, *optional*):
            Whether or not the repository created should be private.
            If `None` (default), will default to been public except if the organization's default is private.
        token (`str`, *optional*):
            The Hugging Face account token to use as HTTP bearer authorization for remote files. If :obj:`None`, the token will be asked by a prompt.
        config (`dict`, *optional*):
            Configuration object to be saved alongside the model weights.
        branch (`str`, *optional*):
            The git branch on which to push the model. This defaults to
            the default branch as specified in your repository, which
            defaults to `"main"`.
        create_pr (`boolean`, *optional*):
            Whether or not to create a Pull Request from `branch` with that commit.
            Defaults to `False`.
        api_endpoint (`str`, *optional*):
            The API endpoint to use when pushing the model to the hub.
        allow_patterns (`List[str]` or `str`, *optional*):
            If provided, only files matching at least one pattern are pushed.
        ignore_patterns (`List[str]` or `str`, *optional*):
            If provided, files matching any of the patterns are not pushed.
        delete_patterns (`List[str]` or `str`, *optional*):
            If provided, remote files matching any of the patterns will be deleted from the repo.

    Returns:
        The url of the commit of your model in the given repository.

    <Tip>

    Raises the following error:

        - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
          if the user is not log on to the Hugging Face Hub.

    </Tip>
    )ÚendpointT)rg   rr   rq   rV   )rT   )	rg   rr   Úfolder_pathrp   rh   rt   ru   rv   rw   N)r!   r   Úcreate_reporg   r   r   rf   Úupload_folder)re   rg   rp   rq   rr   rT   rs   rt   ru   rv   rw   rx   ÚapiÚtmpÚ
saved_paths                  r    Úpush_to_hub_fastair�   V  s™   € ôB $Ô%Ü
˜Ô
&€CØ�o‰o g°UÀGÐVZˆoÓ[×cÑc€Gô 
 Ó	!ð 
 SÜ˜#“Y Ñ(ˆ
Ü ¨¸FÕCØ× Ñ ØØØ"Ø)ØØØ)Ø+Ø+ð !ó 

÷
÷ 
ò 
ús   Á 6B Â B	)z2.4z1.3.27)N)-rb   r-   Úpathlibr   Úpickler   r   Útypingr   r   r   r	   r
   Ú	packagingr   Úhuggingface_hubr   r   Úhuggingface_hub.hf_apir   Úhuggingface_hub.utilsr   r   r   r   Úutilsr   r   Úutils._runtimer   Ú
get_loggerÚ__name__r0   r6   r!   r@   rJ   rP   rM   rR   rf   ro   Úboolr]   r�   © r"   r    ú<module>r�      sR  ðÛ Û 	Ý ß 2ß 3Õ 3å ç 8Ý (÷ó ÷ 1Ý 'ð 
ˆ×	Ñ	˜HÓ	%€ð $Ø (ñ.
Øð.
àó.
ðf $Ø (ñ^Øð^àð^ð ó^ðB €ðD4Ù4FÓ4HÐ3IÈÑUgÓUiÐTjÐjwñ  yMó  yOð  xPð PðÐ ð% ó %ð( dó (ð$ (,ñ5
à˜#˜t˜)Ñ$ð5
ð �T˜#˜s˜(‘^Ñ$ó5
ðp ð #ñ)CØð)Cà�s‰mò)Có ð)CðX ð
 EØ"ØØ!Ø Ø $Ø6:Ø7;Ø7;Ø"&òR
ð ðR
ð ð	R
ð
 �d‰^ðR
ð �C‰=ðR
ð �T‰NðR
ð �S‰MðR
ð ˜‰~ðR
ð ˜U 4¨¡9¨c >Ñ2Ñ3ðR
ð ˜e D¨¡I¨s NÑ3Ñ4ðR
ð ˜e D¨¡I¨s NÑ3Ñ4ðR
ð ˜3‘-òR
ó ñR
r"   