@@ -11,6 +11,9 @@ beginning of it, following with the content of the model card in markdown
11
11
format. The metadata section is used to make models searchable on the Hub, and
12
12
get the inference API and the widgets on the website working.
13
13
14
+ Metadata
15
+ --------
16
+
14
17
The metadata part of the file needs to follow the specifications `here
15
18
<https://huggingface.co/docs/hub/models-cards#model-card-metadata> `__. It
16
19
includes simple attributes of your models such as the task you're solving,
@@ -40,6 +43,9 @@ Here's an example of the metadata section of the ``README.md`` file:
40
43
``skops `` creates this section of the file for you, and you almost never need
41
44
to touch it yourself.
42
45
46
+ Model Card Content
47
+ ------------------
48
+
43
49
The markdown part does not necessarily need to follow any specification in
44
50
terms of information passed, which gives the user a lot of flexibility. The
45
51
markdown part of the ``README.md `` file comes with a couple of defaults provided
@@ -90,8 +96,8 @@ as well as adding some subsections with plots below that, you can call the
90
96
})
91
97
92
98
Furthermore, you can select existing sections (as well as their subsections)
93
- using :meth: `Card.select `, and you can delete sections using
94
- :meth: `Card.delete `:
99
+ using :meth: `. Card.select `, and you can delete sections using
100
+ :meth: `. Card.delete `:
95
101
96
102
.. code-block :: python
97
103
@@ -103,3 +109,43 @@ using :meth:`Card.select`, and you can delete sections using
103
109
104
110
To see how you can use the API in ``skops `` to create a model card, please
105
111
refer to :ref: `sphx_glr_auto_examples_plot_model_card.py `.
112
+
113
+ Saving and Loading Model Cards
114
+ ------------------------------
115
+
116
+ Once you have finished creating and modifying the model card, you can save it
117
+ using the :meth: `.Card.save ` method:
118
+
119
+ .. code-block :: python
120
+
121
+ card.save(" README.md" )
122
+
123
+ This renders the content of the model card to markdown format and stores it in
124
+ the indicated file. It is now ready to be uploaded to Hugging Face Hub.
125
+
126
+ If you have a finished model card but want to load to make some modifications,
127
+ you can use the function :func: `skops.card.parse_modelcard `. This function
128
+ parses the model card back into a :class: `.Card ` instance that you can work on
129
+ further:
130
+
131
+ .. code-block :: python
132
+
133
+ from skops import card
134
+ model_card = card.parse_modelcard(" README.md" )
135
+ model_card.add(** {" A new section" : " Some new content" })
136
+ model_card.save(" README.md" )
137
+
138
+ When the card is parsed, some minor details of the model card can change, e.g.
139
+ if you used different column alignment than the default, this could change, as
140
+ well as removing excess empty lines or trailing whitespace. However, the content
141
+ itself should be exactly the same. All known deviations are documented in the
142
+ `parse_modelcard docs
143
+ <https://skops.readthedocs.io/en/stable/modules/classes.html#skops.card.parse_modelcard> `_
144
+
145
+ For the parsing part, we rely on `pandoc <https://pandoc.org/ >`_. If you haven't
146
+ installed it, please follow `these instructions
147
+ <https://pandoc.org/installing.html> `_. The advantage of using pandoc is that
148
+ it's a very mature library and that it supports many different document formats.
149
+ Therefore, it should be possible to parse model cards even if they use a format
150
+ that's not markdown, for instance reStructuredText, org, or asciidoc. For
151
+ saving, we only support markdown for now.
0 commit comments