|
10 | 10 | # %%
|
11 | 11 | # Imports
|
12 | 12 | # =======
|
13 |
| -# First we will import everhing required for the rest of this document. |
| 13 | +# First we will import everything required for the rest of this document. |
14 | 14 |
|
15 | 15 | import os
|
16 | 16 | import pickle
|
17 | 17 | from tempfile import mkdtemp, mkstemp
|
18 | 18 | from uuid import uuid4
|
19 | 19 |
|
| 20 | +from huggingface_hub import HfApi |
20 | 21 | from sklearn.datasets import load_breast_cancer
|
21 | 22 | from sklearn.ensemble import HistGradientBoostingClassifier
|
22 | 23 | from sklearn.experimental import enable_halving_search_cv # noqa
|
|
74 | 75 | # We can no see what the contents of the created local repo are:
|
75 | 76 | print(os.listdir(local_repo))
|
76 | 77 |
|
| 78 | +# %% |
| 79 | +# Model Card |
| 80 | +# ========== |
| 81 | +# TODO: create a model card here |
| 82 | + |
77 | 83 |
|
78 | 84 | # %%
|
79 | 85 | # Push to Hub
|
80 | 86 | # ===========
|
81 |
| -# And finally, we can push the model to the hub. |
82 |
| -hf_hub.push(repo_id=f"hf_hub_example-{uuid4()}", source=local_repo) |
| 87 | +# And finally, we can push the model to the hub. This requires a user access |
| 88 | +# token which you can get under https://huggingface.co/settings/tokens |
| 89 | +repo_name = f"hf_hub_example-{uuid4()}" |
| 90 | +# you can put your own token here. |
| 91 | +MY_TOKEN = os.environ["HF_HUB_TOKEN"] |
| 92 | +hf_hub.push(repo_id=repo_name, source=local_repo, token=MY_TOKEN) |
| 93 | + |
| 94 | +# %% |
| 95 | +# Now you can check the contents of the repository under your user. |
| 96 | +# |
| 97 | +# Update Requirements |
| 98 | +# =================== |
| 99 | +# If you update your environment and the versions of your requirements are |
| 100 | +# changed, you can update the requirement in your repo by calling |
| 101 | +# ``update_env``, which automatically detects the existing installation of the |
| 102 | +# current environment and updates the requirements accordingly. |
| 103 | + |
| 104 | +hf_hub.update_env(path=local_repo, requirements=["scikit-learn"]) |
| 105 | + |
| 106 | +# %% |
| 107 | +# Delete Repository |
| 108 | +# ================= |
| 109 | +# At the end, you can also delete the repository you created using |
| 110 | +# ``HfApi().delete_repo``. For more information please refer to the |
| 111 | +# documentation of ``huggingface_hub`` library. |
| 112 | + |
| 113 | +HfApi().delete_repo(repo_id=repo_name, token=MY_TOKEN) |
0 commit comments