wL isA\ddlZddlZddlmZddlmZmZddlmZm Z m Z m Z m Z ddl mZddlmZmZddlmZddlmZmZmZmZd d lmZmZd d lmZej<eZ d+d e!d e!fdZ" d+de!d e!d e!fdZ#dZ$dedededZ%defdZ&defdZ' d,de e!efde e e!effdZ(e d,de!de e!fdZ)eddddddddddd de!d!e!d"e e*d#e e!de e+d$e e!d%e e*d&e e e e!e!fd'e e e e!e!fd(e e e e!e!fd)e e!fd*Z,y)-N)Path)DEFAULT_PROTOCOL PicklingError)AnyDictListOptionalUnion)version) constantssnapshot_download)HfApi)SoftTemporaryDirectoryget_fastai_versionget_fastcore_versionget_python_version)loggingvalidate_hf_hub_args) _PY_VERSIONfastai_min_versionfastcore_min_versionc txs tdk(r(td|d|dtdtd tjt}tjt}|tj|krtd|dtd |tj|krtd |d td 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. zN/Azfastai>=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)rr ImportErrorr Version)rrcurrent_fastai_versioncurrent_fastcore_versions b/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/huggingface_hub/fastai_utils.py_check_fastai_fastcore_versionsr!s( 6"4"65@)*/:N9OP22D2F1GH.01 4  %__-?-AB&/C/EF0B CC *+,"$%&    '//2F"GG ./0,./0/ /  Hstorage_folderc< ddl}tjj |dst jdy|j|d}d|jvrt jdy|d}d|jvrt jd y|d}|Dcgc]}|jd s|}}t|dk(rt jd nbt|djd d } | dk7r=tj| tj|krtd|d| d|Dcgc]}|jds|} }t| dk(rt jdyt| djd d } | dk7r>tj| tj|krtd|d| dyy#t$r tdwxYwcc}wcc}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. rNzn`push_to_hub_fastai` and `from_pretrained_fastai` require the toml module. Install it with `pip install toml`.z/pyproject.tomlzThere 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-systemzThere 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.requireszThere 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)tomlModuleNotFoundErrorrospathisfileloggerwarningloadkeys startswithlenstr partitionr r) r#rrr+pyproject_tomlbuild_system_tomlpackage_versionspckfastai_packagesfastai_versionfastcore_packagesfastcore_versions r )_check_fastai_fastcore_pyproject_versionsr@HsD6  77>>^,O< =  YY.!1ABN^0022 . &~6*//11 . (4'7Ss#..:RsSOS ?q ij_Q/0::3?B R GOON$CgooVhFi$i./0"##:<  )9WCNN:>sCAF r !goo6F&G'//ZnJo&o234,--DF 'p !u   3   NTXs#G<0HHH.H<Hu--- 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|dz }|js2|jdd5}|jtdddyy#1swYyxYw)z Creates a model card for the repository. Args: repo_dir (`Path`): Directory where model card is created. z README.mdwutf-8encodingN)existsopenwriteREADME_TEMPLATE)rA readme_pathfs r _create_model_cardrMsZ[(K       cG  4 % GGO $ % %  % % A  Ac|dz }|js2|jdd5}|jtdddyy#1swYyxYw)z Creates a `pyproject.toml` for the repository. Args: repo_dir (`Path`): Directory where `pyproject.toml` is created. zpyproject.tomlrCrDrEN)rGrHrIPYPROJECT_TEMPLATE)rApyproject_pathrLs r _create_model_pyprojectrRs\ 00N  "  w 7 (1 GG& ' ( ( # ( (rNsave_directoryconfigcbttj|d|t|tst dt |dtjj|tj}t|d5}tj||dddtt|t!t|t||_tj|d |j#dt$y#1swYqxYw#t&$r t'd wxYw) 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. T)exist_okNz(Provided config should be a dict. Got: ''rC model.pkl)fnamepickle_protocolzYou 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 isinstancedict RuntimeErrortyper.joinr CONFIG_NAMErHjsondumprMrrRexportrr)learnerrSrTr.rLs r _save_pretrained_fastairfs,$%KK.&$'!I$v,WXYZ Zww||NI,A,AB $_ ! IIfa  !tN+,D01'GLKK.  ,   ! !   E   sD 5D DD.repo_idrevisioncttjj|st ||dt }n|}t |ddlm}|tjj|dS)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&)rgrh library_namelibrary_versionr) load_learnerrX) r!r-r.isdirr rr@fastai.learnerrlr`)rgrhr#rls r from_pretrained_fastairo"sa.$% 77== !*!.0  !-n=+  ^[A BBr"z(Push FastAI model using huggingface_hub.) commit_messageprivatetokenrTbranch create_prallow_patternsignore_patternsdelete_patterns api_endpointrprqrrrsrtrurvrwrxc tt| } | j|||dj}t 5} t | |z }t |||| j|||||||| |  cdddS#1swYyxYw)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. )endpointT)rgrrrqrV)rT) rgrr folder_pathrprhrtrurvrwN)r!r create_reporgrrrf upload_folder)rergrprqrrrTrsrtrurvrwrxapitmp saved_paths r push_to_hub_fastairOs|$%  &CoogUGVZo[ccG !  S#Y( FC  "))++!      s 6BB )z2.4z1.3.27)N)-rbr-pathlibrpicklerrtypingrrrr r packagingr huggingface_hubr r huggingface_hub.hf_apirhuggingface_hub.utilsrrrrutilsrrutils._runtimer get_logger__name__r0r6r!r@rJrPrMrRrfroboolr]rr"r rsR 2338(1'   H %$ (, , , b$ (\\\\~ D44F4H3IUgUiTjjwyMyOxPP % % (d ($(,2 #t)$2  T#s(^ $2 j#)C )Csm)C)CX E"! $6:7;7;"&O O  O d^ O C= O  TNO  SMO ~O U49c>23O eDIsN34O eDIsN34O 3-O O r"