Skip to content

Commit fd5703a

Browse files
authored
DOC extend example (#11)
1 parent 90e0fd8 commit fd5703a

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

examples/plot_hf_hub.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
# %%
1111
# Imports
1212
# =======
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.
1414

1515
import os
1616
import pickle
1717
from tempfile import mkdtemp, mkstemp
1818
from uuid import uuid4
1919

20+
from huggingface_hub import HfApi
2021
from sklearn.datasets import load_breast_cancer
2122
from sklearn.ensemble import HistGradientBoostingClassifier
2223
from sklearn.experimental import enable_halving_search_cv # noqa
@@ -74,9 +75,39 @@
7475
# We can no see what the contents of the created local repo are:
7576
print(os.listdir(local_repo))
7677

78+
# %%
79+
# Model Card
80+
# ==========
81+
# TODO: create a model card here
82+
7783

7884
# %%
7985
# Push to Hub
8086
# ===========
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

Comments
 (0)