Benjamin Bossan commited on
Commit
4c1bb6f
1 Parent(s): 7b83cb3

Add help page

Browse files
Files changed (6) hide show
  1. README.md +305 -2
  2. app.py +3 -0
  3. create.py +4 -4
  4. edit.py +3 -7
  5. gethelp.py +323 -0
  6. start.py +30 -6
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Skops Model Card Creator2
3
  emoji: 🐨
4
  colorFrom: indigo
5
  colorTo: blue
@@ -8,6 +8,309 @@ sdk_version: 1.17.0
8
  app_file: app.py
9
  pinned: false
10
  license: bsd-3-clause
 
 
 
 
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Skops Model Card Creator
3
  emoji: 🐨
4
  colorFrom: indigo
5
  colorTo: blue
 
8
  app_file: app.py
9
  pinned: false
10
  license: bsd-3-clause
11
+ tags:
12
+ - sklearn
13
+ - skops
14
+ - model card
15
  ---
16
 
17
+ # Create a Hugging Face model repository for scikit learn models
18
+
19
+ This page aims to provide a simple interface to use the
20
+ [`skops`](https://skops.readthedocs.io/) model card and HF Hub creation
21
+ utilities.
22
+
23
+ ## Step 1: Prepare the model repository
24
+
25
+ In this step, you do the necessary preparation work to create a [model
26
+ repository on Hugging Face Hub](https://huggingface.co/docs/hub/models).
27
+
28
+ ### Upload a model
29
+
30
+ Here you should upload the sklearn model we want to present in the model
31
+ repository. The model should be stored either as a ``pickle`` file or it should
32
+ use the [secure skops persistence
33
+ format](https://skops.readthedocs.io/en/stable/persistence.html). Later, this
34
+ model will be uploaded to the model repository so that you can share it with
35
+ others.
36
+
37
+ The uploaded model should be a scikit-learn model or a model that is compatible
38
+ with the sklearn API, e.g. using [XGBoost sklearn
39
+ wrapper](https://xgboost.readthedocs.io/en/stable/python/python_api.html#module-xgboost.sklearn)
40
+ when it's an XGBoost model.
41
+
42
+ If you just want to test out the application and don't want to upload a model, a
43
+ dummy model will be used instead.
44
+
45
+ ### Upload input data
46
+
47
+ It's possible to upload input data as a csv file. If that is done, the first few
48
+ rows of the input data will be used as sample data for the model, e.g. when
49
+ trying out the [inference API](https://huggingface.co/inference-api).
50
+
51
+
52
+ ### Choose the task type
53
+
54
+ Choose the type of task that the model is intended to solve. It can be either
55
+ classification or regression, with input data being either tabular in nature or
56
+ text.
57
+
58
+ ### Requirements
59
+
60
+ This is the list of Python requirements needed to run the model.
61
+
62
+ ### Choose the model card template
63
+
64
+ This is the final step and choosing one of the options will bring you to the
65
+ editing step.
66
+
67
+ #### Create a new skops model card
68
+
69
+ This is the recommended way of getting started. The skops model card template
70
+ prefills the model card with some [useful
71
+ contents](https://skops.readthedocs.io/en/stable/model_card.html#model-card-content)
72
+ that you probably want to have in most model cards. Don't worry: If you don't
73
+ like part of the content, you can always edit or delete it later.
74
+
75
+ #### Create a new empty model card
76
+
77
+ If you want to start the model card completely from scratch, that's also
78
+ possible by choosing this option. It will generate a completely empty model card
79
+ for you that you can fashion to your liking.
80
+
81
+ #### Load existing model card from HF Hub
82
+
83
+ If you want to use an existing model card and edit it, that's also possible.
84
+ Please enter the Hugging Face Hub repository ID here and the corresponding model
85
+ card will be loaded. The repo ID is typically someting like `username/reponame`,
86
+ e.g. `openai/whisper-small`. Some models also omit the user name, e.g. `gpt2`.
87
+
88
+ Note that when you choose an existing model card, a couple of files will be
89
+ downloaded, because they may be required to render the model card (e.g. images).
90
+ Therefore, depending on the repository, this step may take a bit.
91
+
92
+ If you notice any problems when rendering the existing model card, please let us
93
+ know by [creating an issue](https://github.com/skops-dev/skops/issues).
94
+
95
+ ## Step 2: Edit the model card
96
+
97
+ Before creating the model repository, it is crucial to ensure that the [model
98
+ card](https://huggingface.co/blog/model-cards) is edited to best represent the
99
+ model you're working on. This can be achieved in the editing step, which is
100
+ described in more detail below.
101
+
102
+ ### Editing sidbar
103
+
104
+ In the left sidebar, you will be able to edit the model card, whereas the main
105
+ screen is reserved for rendering the model card so that you see what you will
106
+ get. We will start by describing the editing sidebar.
107
+
108
+ Tip: You should increase the width of the side bar if it is too narrow for your
109
+ taste.
110
+
111
+ #### Undo, redo & reset
112
+
113
+ On top of the side bar, you have the option to undo, redo, and reset the last
114
+ operation you did. Say, you accidentally made a change, just press the `Undo`
115
+ button to undo this change. Similarly, if you want to undo your undo operation,
116
+ press the `Redo` button. Finally, if you press `Reset`, all your operations will
117
+ be undone (but don't worry if you click the button accidentally, you can redo
118
+ all of them if you want).
119
+
120
+ #### Save, create repo & delete
121
+
122
+ These buttons are intended for when you finished editing the model card. When
123
+ you click on `Save`, you will get the option to download the model card as a
124
+ markdown file.
125
+
126
+ When clicking the `Create Repo` button, you will be taken to the next screen,
127
+ which offers you to create a model repository on Hugging Face Hub. This step
128
+ will be explained in more detail further below.
129
+
130
+ Finally, you can click on `Delete` to completely discard all the changes you
131
+ made and be taken back to the start screen of the app. Be careful, any change
132
+ you made will be lost. It is thus advised to first save the model card before
133
+ pressing `Delete`.
134
+
135
+ #### Edit a section
136
+
137
+ Each section has its own form field, which allows you to make edits. Change the
138
+ name of the section or change the content (or both), then click `Update` to see
139
+ a preview of your change. As with all other operations, you can undo the change
140
+ by clicking on `Undo`.
141
+
142
+ #### Delete a section
143
+
144
+ Below the form field for editing the section, you will find a `Delete` button
145
+ (including the name of the section to make it clear which section it refers to).
146
+ If you click that button, the whole section, _including its subsections_, will
147
+ be deleted. Again, click on `Undo` if you accidentally deleted something that
148
+ you want to keep.
149
+
150
+ #### Add section below
151
+
152
+ If you click on this button, a new subsection wil be created under the current
153
+ section. This will create a section with a dummy title and dummy content, which
154
+ you can then edit.
155
+
156
+ Note that this will create a new _subsection_. If there are already existing
157
+ subsections in the current section, the new subsection will be created _below_
158
+ those existing subsections. So the new subsection you create might not appear
159
+ exactly where you expect it to appear. To illustrate this, assume that we have
160
+ the following sections and subsections:
161
+
162
+ - Section A
163
+ - Subsection A.1
164
+ - Subsection A.2
165
+ - Section B
166
+
167
+ If you create a new section below "Section A", it will be created on the same
168
+ level, and below of, "Subsection A.2", resulting in the following structure:
169
+
170
+ - Section A
171
+ - Subsection A.1
172
+ - Subsection A.2
173
+ - NEW SUBSECTION
174
+ - Section B
175
+
176
+ If you create a new section below the "Subsection A.1", you will actually create
177
+ a sub-subsection, resulting in the following structure instead:
178
+
179
+ - Section A
180
+ - Subsection A.1
181
+ - NEW SUB-SUBSECTION
182
+ - Subsection A.2
183
+ - Section B
184
+
185
+ Hopefully, this clarifies things. Unfortunately, there is no possibility (yet)
186
+ to re-order sections.
187
+
188
+ #### Add figure below
189
+
190
+ This button works quite similarly to adding a new section. The main difference
191
+ is that instead of having a text area to enter content, you will be asked to
192
+ upload an image file. By default, a dummy image will be shown in the preview.
193
+
194
+ #### Add metrics (only skops template)
195
+
196
+ If you have chosen the skops template, you will see an additional field called
197
+ `Add metrics` near the top of the side bar. Here you can choose metrics you want
198
+ to be shown in the model card, e.g. the accuracy the model achieved on a
199
+ specific dataset. Please enter one metric per line, with the metric name on the
200
+ left, then an `=` sign, and the value on the right, e.g. `accuracy on test set =
201
+ 0.85`.
202
+
203
+ After pressing `update`, the metrics will be shown in a table in the section
204
+ `Model description/Evaluation Results`. You can always add or remove metrics
205
+ from this field later. If you want to delete this section completely, look for
206
+ its edit form further below and press `Delete`. There, you can also edit the
207
+ table in a more fine grained way, e.g. by changing the alignment.
208
+
209
+ If you don't use the skops template and still want to add a table, it is
210
+ possible to do that, but it's requires a bit more work. Add a new section as
211
+ described above, then, in the text area, create a table using the [markdown
212
+ table
213
+ syntax](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/organizing-information-with-tables#creating-a-table).
214
+
215
+ ### Model card visualization
216
+
217
+ The main part of the page will show you what the final model card will look
218
+ like.
219
+
220
+ #### Metadata
221
+
222
+ On the very top, you can see the metadata of the model card (it is collapsed by
223
+ default). The metadata can be very useful for features on the HF Hub, e.g.
224
+ allowing other users to find your model by a given tag.
225
+
226
+ Right now, it is not possible to edit the metadata directly from here. But don't
227
+ worry, once you have created the model card repository, you can easily edit the
228
+ metadata there.
229
+
230
+ #### Table of Contents
231
+
232
+ For your convenience, a table of contents is also shown at the top (collapsed by
233
+ default). This is useful if you have a bigger model card and want to see the
234
+ overview of all its contents.
235
+
236
+ #### Markdown preview
237
+
238
+ Finally, the model card itself is shown. This is how the model card will look
239
+ like once it is saved as markdown and then rendered.
240
+
241
+ ## Step 3: Creating a model repository
242
+
243
+ After you have finished editing the model card, it is time to create a model
244
+ repository on Hugging Face Hub. Click on `Create Repo` and you will be taken to
245
+ the final step of the process.
246
+
247
+ ### Back & Delete
248
+
249
+ If you find yourself wanting to make more edits to the model card, just click on
250
+ the `Back` button and you'll be brought back to the editing step.
251
+
252
+ You can also click `Delete`, which will discard all your changes and bring you
253
+ back to the start page. Be careful: This step cannot be undone and all your
254
+ progress will be lost.
255
+
256
+ ### Files included in the repository
257
+
258
+ For your convenience, this will show a preview of all the files included in the
259
+ repository, as well as their sizes. Don't create a repository if you see files
260
+ there that you don't want to be uploaded.
261
+
262
+ ### Privacy settings
263
+
264
+ By default, a private repository will be created. If you untick this box, it
265
+ will be public instead. More information on what that implies can be found in
266
+ the [docs on repository
267
+ settings](https://huggingface.co/docs/hub/repositories-settings).
268
+
269
+ ### Name of the repository
270
+
271
+ Here you have to enter the name of the repository. Typically, that's something
272
+ like `username/reponame` or `organame/reponame`. This field is mandatory and you
273
+ should ensure that the corresponding repository ID does not exist yet.
274
+
275
+ ### Enter your Hugging Face token
276
+
277
+ Here you need to paste your Hugging Face token, which is used for
278
+ authentication. The token can be found [here](https://hf.co/settings/token) and
279
+ it always starts with "hf_". Entering a token is necessary to create a
280
+ repository.
281
+
282
+ Note that if you don't already have an account on Hugging Face, you need to
283
+ create one to get a token. It's free.
284
+
285
+ ### Create a new repository
286
+
287
+ Once all the required fields are filled, click on this button to create the
288
+ repository. Depending on the size, it may take a couple of seconds to finish.
289
+ Once it is created, you will see a success notification that includes the link
290
+ to the repository. Congratulations, you're done!
291
+
292
+ ## Troubleshooting
293
+
294
+ ### Not all skops features available
295
+
296
+ This app is based on the [skops model card
297
+ feature](https://skops.readthedocs.io/en/stable/model_card.html#model-card-content).
298
+ However, it does not support all the options that are available there. If you
299
+ want to use all those options in a programmatic fashion, please follow the link
300
+ and read up on what it takes to create a model card with skops. The full power
301
+ of the `Card` class is documented
302
+ [here](https://skops.readthedocs.io/en/stable/modules/classes.html#skops.card.Card).
303
+
304
+ ### Strange behavior
305
+
306
+ If the app behaves strangely, shows error messages, or renders incorrectly, it
307
+ may be necessary to refresh the browser tab. This will take you back to the
308
+ start page, with all progress being lost. If you can reproduce that behavior,
309
+ please [creating an issue](https://github.com/skops-dev/skops/issues) and let us
310
+ know.
311
+
312
+ ### Contact
313
+
314
+ If you want to contact us, you can join our discord channel. To do that, follow
315
+ [these
316
+ instructions](https://skops.readthedocs.io/en/stable/community.html#discord).
app.py CHANGED
@@ -14,6 +14,7 @@ import streamlit as st
14
 
15
  from create import create_repo_input_form
16
  from edit import edit_input_form
 
17
  from start import start_input_form
18
 
19
 
@@ -44,6 +45,8 @@ if "screen" not in st.session_state:
44
 
45
  if st.session_state.screen.state == "start":
46
  start_input_form()
 
 
47
  elif st.session_state.screen.state == "edit":
48
  edit_input_form()
49
  elif st.session_state.screen.state == "create_repo":
 
14
 
15
  from create import create_repo_input_form
16
  from edit import edit_input_form
17
+ from gethelp import help_page
18
  from start import start_input_form
19
 
20
 
 
45
 
46
  if st.session_state.screen.state == "start":
47
  start_input_form()
48
+ elif st.session_state.screen.state == "help":
49
+ help_page()
50
  elif st.session_state.screen.state == "edit":
51
  edit_input_form()
52
  elif st.session_state.screen.state == "create_repo":
create.py CHANGED
@@ -53,7 +53,9 @@ def _display_private_box():
53
  "Private repositories can only seen by you or members of the same "
54
  "organization, see https://huggingface.co/docs/hub/repositories-settings"
55
  )
56
- st.checkbox("Make repo private", value=True, help=tip, key="create_repo_private")
 
 
57
 
58
 
59
  def _repo_id_field():
@@ -62,9 +64,7 @@ def _repo_id_field():
62
 
63
  def _hf_token_field():
64
  tip = "The Hugging Face token can be found at https://hf.co/settings/token"
65
- st.text_input(
66
- "Enter your Hugging Face token ('hf_***')", key="hf_token", help=tip
67
- )
68
 
69
 
70
  def _create_hf_repo(path, repo_name, hf_token, private):
 
53
  "Private repositories can only seen by you or members of the same "
54
  "organization, see https://huggingface.co/docs/hub/repositories-settings"
55
  )
56
+ st.checkbox(
57
+ "Make repository private", value=True, help=tip, key="create_repo_private"
58
+ )
59
 
60
 
61
  def _repo_id_field():
 
64
 
65
  def _hf_token_field():
66
  tip = "The Hugging Face token can be found at https://hf.co/settings/token"
67
+ st.text_input("Enter your Hugging Face token ('hf_***')", key="hf_token", help=tip)
 
 
68
 
69
 
70
  def _create_hf_repo(path, repo_name, hf_token, private):
edit.py CHANGED
@@ -142,9 +142,7 @@ def _add_figure(model_card: card.Card, key: str) -> None:
142
  st.session_state.task_state.add(task)
143
 
144
 
145
- def _delete_section(
146
- model_card: card.Card, key: str, path: Path
147
- ) -> None:
148
  task = DeleteSectionTask(model_card, key=key, path=path)
149
  st.session_state.task_state.add(task)
150
 
@@ -211,7 +209,7 @@ def create_form_from_section(
211
  with col_0:
212
  path = st.session_state.hf_path / content.path if is_fig else None
213
  st.button(
214
- f"delete '{arepr.repr(old_title)}'",
215
  on_click=_delete_section,
216
  args=(model_card, key, path),
217
  key=f"{key}.delete",
@@ -299,9 +297,7 @@ def redo_last():
299
 
300
  def add_download_model_card_button():
301
  model_card = st.session_state.model_card
302
- data = get_rendered_model_card(
303
- model_card, hf_path=str(st.session_state.hf_path)
304
- )
305
  tip = "Download the generated model card as markdown file"
306
  st.download_button(
307
  "Save (md)",
 
142
  st.session_state.task_state.add(task)
143
 
144
 
145
+ def _delete_section(model_card: card.Card, key: str, path: Path) -> None:
 
 
146
  task = DeleteSectionTask(model_card, key=key, path=path)
147
  st.session_state.task_state.add(task)
148
 
 
209
  with col_0:
210
  path = st.session_state.hf_path / content.path if is_fig else None
211
  st.button(
212
+ f"Delete '{arepr.repr(old_title)}'",
213
  on_click=_delete_section,
214
  args=(model_card, key, path),
215
  key=f"{key}.delete",
 
297
 
298
  def add_download_model_card_button():
299
  model_card = st.session_state.model_card
300
+ data = get_rendered_model_card(model_card, hf_path=str(st.session_state.hf_path))
 
 
301
  tip = "Download the generated model card as markdown file"
302
  st.download_button(
303
  "Save (md)",
gethelp.py ADDED
@@ -0,0 +1,323 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+
4
+ def add_back_button():
5
+ def fn():
6
+ st.session_state.screen.state = "start"
7
+
8
+ st.button(
9
+ "Back", help="Get back to the start screen", on_click=fn, key="help_get_back"
10
+ )
11
+
12
+
13
+ help_md = """# Create a Hugging Face model repository for scikit learn models
14
+
15
+ This page aims to provide a simple interface to use the
16
+ [`skops`](https://skops.readthedocs.io/) model card and HF Hub creation
17
+ utilities.
18
+
19
+ ## Step 1: Prepare the model repository
20
+
21
+ In this step, you do the necessary preparation work to create a [model
22
+ repository on Hugging Face Hub](https://huggingface.co/docs/hub/models).
23
+
24
+ ### Upload a model
25
+
26
+ Here you should upload the sklearn model we want to present in the model
27
+ repository. The model should be stored either as a ``pickle`` file or it should
28
+ use the [secure skops persistence
29
+ format](https://skops.readthedocs.io/en/stable/persistence.html). Later, this
30
+ model will be uploaded to the model repository so that you can share it with
31
+ others.
32
+
33
+ The uploaded model should be a scikit-learn model or a model that is compatible
34
+ with the sklearn API, e.g. using [XGBoost sklearn
35
+ wrapper](https://xgboost.readthedocs.io/en/stable/python/python_api.html#module-xgboost.sklearn)
36
+ when it's an XGBoost model.
37
+
38
+ If you just want to test out the application and don't want to upload a model, a
39
+ dummy model will be used instead.
40
+
41
+ ### Upload input data
42
+
43
+ It's possible to upload input data as a csv file. If that is done, the first few
44
+ rows of the input data will be used as sample data for the model, e.g. when
45
+ trying out the [inference API](https://huggingface.co/inference-api).
46
+
47
+
48
+ ### Choose the task type
49
+
50
+ Choose the type of task that the model is intended to solve. It can be either
51
+ classification or regression, with input data being either tabular in nature or
52
+ text.
53
+
54
+ ### Requirements
55
+
56
+ This is the list of Python requirements needed to run the model.
57
+
58
+ ### Choose the model card template
59
+
60
+ This is the final step and choosing one of the options will bring you to the
61
+ editing step.
62
+
63
+ #### Create a new skops model card
64
+
65
+ This is the recommended way of getting started. The skops model card template
66
+ prefills the model card with some [useful
67
+ contents](https://skops.readthedocs.io/en/stable/model_card.html#model-card-content)
68
+ that you probably want to have in most model cards. Don't worry: If you don't
69
+ like part of the content, you can always edit or delete it later.
70
+
71
+ #### Create a new empty model card
72
+
73
+ If you want to start the model card completely from scratch, that's also
74
+ possible by choosing this option. It will generate a completely empty model card
75
+ for you that you can fashion to your liking.
76
+
77
+ #### Load existing model card from HF Hub
78
+
79
+ If you want to use an existing model card and edit it, that's also possible.
80
+ Please enter the Hugging Face Hub repository ID here and the corresponding model
81
+ card will be loaded. The repo ID is typically someting like `username/reponame`,
82
+ e.g. `openai/whisper-small`. Some models also omit the user name, e.g. `gpt2`.
83
+
84
+ Note that when you choose an existing model card, a couple of files will be
85
+ downloaded, because they may be required to render the model card (e.g. images).
86
+ Therefore, depending on the repository, this step may take a bit.
87
+
88
+ If you notice any problems when rendering the existing model card, please let us
89
+ know by [creating an issue](https://github.com/skops-dev/skops/issues).
90
+
91
+ ## Step 2: Edit the model card
92
+
93
+ Before creating the model repository, it is crucial to ensure that the [model
94
+ card](https://huggingface.co/blog/model-cards) is edited to best represent the
95
+ model you're working on. This can be achieved in the editing step, which is
96
+ described in more detail below.
97
+
98
+ ### Editing sidbar
99
+
100
+ In the left sidebar, you will be able to edit the model card, whereas the main
101
+ screen is reserved for rendering the model card so that you see what you will
102
+ get. We will start by describing the editing sidebar.
103
+
104
+ Tip: You should increase the width of the side bar if it is too narrow for your
105
+ taste.
106
+
107
+ #### Undo, redo & reset
108
+
109
+ On top of the side bar, you have the option to undo, redo, and reset the last
110
+ operation you did. Say, you accidentally made a change, just press the `Undo`
111
+ button to undo this change. Similarly, if you want to undo your undo operation,
112
+ press the `Redo` button. Finally, if you press `Reset`, all your operations will
113
+ be undone (but don't worry if you click the button accidentally, you can redo
114
+ all of them if you want).
115
+
116
+ #### Save, create repo & delete
117
+
118
+ These buttons are intended for when you finished editing the model card. When
119
+ you click on `Save`, you will get the option to download the model card as a
120
+ markdown file.
121
+
122
+ When clicking the `Create Repo` button, you will be taken to the next screen,
123
+ which offers you to create a model repository on Hugging Face Hub. This step
124
+ will be explained in more detail further below.
125
+
126
+ Finally, you can click on `Delete` to completely discard all the changes you
127
+ made and be taken back to the start screen of the app. Be careful, any change
128
+ you made will be lost. It is thus advised to first save the model card before
129
+ pressing `Delete`.
130
+
131
+ #### Edit a section
132
+
133
+ Each section has its own form field, which allows you to make edits. Change the
134
+ name of the section or change the content (or both), then click `Update` to see
135
+ a preview of your change. As with all other operations, you can undo the change
136
+ by clicking on `Undo`.
137
+
138
+ #### Delete a section
139
+
140
+ Below the form field for editing the section, you will find a `Delete` button
141
+ (including the name of the section to make it clear which section it refers to).
142
+ If you click that button, the whole section, _including its subsections_, will
143
+ be deleted. Again, click on `Undo` if you accidentally deleted something that
144
+ you want to keep.
145
+
146
+ #### Add section below
147
+
148
+ If you click on this button, a new subsection wil be created under the current
149
+ section. This will create a section with a dummy title and dummy content, which
150
+ you can then edit.
151
+
152
+ Note that this will create a new _subsection_. If there are already existing
153
+ subsections in the current section, the new subsection will be created _below_
154
+ those existing subsections. So the new subsection you create might not appear
155
+ exactly where you expect it to appear. To illustrate this, assume that we have
156
+ the following sections and subsections:
157
+
158
+ - Section A
159
+ - Subsection A.1
160
+ - Subsection A.2
161
+ - Section B
162
+
163
+ If you create a new section below "Section A", it will be created on the same
164
+ level, and below of, "Subsection A.2", resulting in the following structure:
165
+
166
+ - Section A
167
+ - Subsection A.1
168
+ - Subsection A.2
169
+ - NEW SUBSECTION
170
+ - Section B
171
+
172
+ If you create a new section below the "Subsection A.1", you will actually create
173
+ a sub-subsection, resulting in the following structure instead:
174
+
175
+ - Section A
176
+ - Subsection A.1
177
+ - NEW SUB-SUBSECTION
178
+ - Subsection A.2
179
+ - Section B
180
+
181
+ Hopefully, this clarifies things. Unfortunately, there is no possibility (yet)
182
+ to re-order sections.
183
+
184
+ #### Add figure below
185
+
186
+ This button works quite similarly to adding a new section. The main difference
187
+ is that instead of having a text area to enter content, you will be asked to
188
+ upload an image file. By default, a dummy image will be shown in the preview.
189
+
190
+ #### Add metrics (only skops template)
191
+
192
+ If you have chosen the skops template, you will see an additional field called
193
+ `Add metrics` near the top of the side bar. Here you can choose metrics you want
194
+ to be shown in the model card, e.g. the accuracy the model achieved on a
195
+ specific dataset. Please enter one metric per line, with the metric name on the
196
+ left, then an `=` sign, and the value on the right, e.g. `accuracy on test set =
197
+ 0.85`.
198
+
199
+ After pressing `update`, the metrics will be shown in a table in the section
200
+ `Model description/Evaluation Results`. You can always add or remove metrics
201
+ from this field later. If you want to delete this section completely, look for
202
+ its edit form further below and press `Delete`. There, you can also edit the
203
+ table in a more fine grained way, e.g. by changing the alignment.
204
+
205
+ If you don't use the skops template and still want to add a table, it is
206
+ possible to do that, but it's requires a bit more work. Add a new section as
207
+ described above, then, in the text area, create a table using the [markdown
208
+ table
209
+ syntax](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/organizing-information-with-tables#creating-a-table).
210
+
211
+ ### Model card visualization
212
+
213
+ The main part of the page will show you what the final model card will look
214
+ like.
215
+
216
+ #### Metadata
217
+
218
+ On the very top, you can see the metadata of the model card (it is collapsed by
219
+ default). The metadata can be very useful for features on the HF Hub, e.g.
220
+ allowing other users to find your model by a given tag.
221
+
222
+ Right now, it is not possible to edit the metadata directly from here. But don't
223
+ worry, once you have created the model card repository, you can easily edit the
224
+ metadata there.
225
+
226
+ #### Table of Contents
227
+
228
+ For your convenience, a table of contents is also shown at the top (collapsed by
229
+ default). This is useful if you have a bigger model card and want to see the
230
+ overview of all its contents.
231
+
232
+ #### Markdown preview
233
+
234
+ Finally, the model card itself is shown. This is how the model card will look
235
+ like once it is saved as markdown and then rendered.
236
+
237
+ ## Step 3: Creating a model repository
238
+
239
+ After you have finished editing the model card, it is time to create a model
240
+ repository on Hugging Face Hub. Click on `Create Repo` and you will be taken to
241
+ the final step of the process.
242
+
243
+ ### Back & Delete
244
+
245
+ If you find yourself wanting to make more edits to the model card, just click on
246
+ the `Back` button and you'll be brought back to the editing step.
247
+
248
+ You can also click `Delete`, which will discard all your changes and bring you
249
+ back to the start page. Be careful: This step cannot be undone and all your
250
+ progress will be lost.
251
+
252
+ ### Files included in the repository
253
+
254
+ For your convenience, this will show a preview of all the files included in the
255
+ repository, as well as their sizes. Don't create a repository if you see files
256
+ there that you don't want to be uploaded.
257
+
258
+ ### Privacy settings
259
+
260
+ By default, a private repository will be created. If you untick this box, it
261
+ will be public instead. More information on what that implies can be found in
262
+ the [docs on repository
263
+ settings](https://huggingface.co/docs/hub/repositories-settings).
264
+
265
+ ### Name of the repository
266
+
267
+ Here you have to enter the name of the repository. Typically, that's something
268
+ like `username/reponame` or `organame/reponame`. This field is mandatory and you
269
+ should ensure that the corresponding repository ID does not exist yet.
270
+
271
+ ### Enter your Hugging Face token
272
+
273
+ Here you need to paste your Hugging Face token, which is used for
274
+ authentication. The token can be found [here](https://hf.co/settings/token) and
275
+ it always starts with "hf_". Entering a token is necessary to create a
276
+ repository.
277
+
278
+ Note that if you don't already have an account on Hugging Face, you need to
279
+ create one to get a token. It's free.
280
+
281
+ ### Create a new repository
282
+
283
+ Once all the required fields are filled, click on this button to create the
284
+ repository. Depending on the size, it may take a couple of seconds to finish.
285
+ Once it is created, you will see a success notification that includes the link
286
+ to the repository. Congratulations, you're done!
287
+
288
+ ## Troubleshooting
289
+
290
+ ### Not all skops features available
291
+
292
+ This app is based on the [skops model card
293
+ feature](https://skops.readthedocs.io/en/stable/model_card.html#model-card-content).
294
+ However, it does not support all the options that are available there. If you
295
+ want to use all those options in a programmatic fashion, please follow the link
296
+ and read up on what it takes to create a model card with skops. The full power
297
+ of the `Card` class is documented
298
+ [here](https://skops.readthedocs.io/en/stable/modules/classes.html#skops.card.Card).
299
+
300
+ ### Strange behavior
301
+
302
+ If the app behaves strangely, shows error messages, or renders incorrectly, it
303
+ may be necessary to refresh the browser tab. This will take you back to the
304
+ start page, with all progress being lost. If you can reproduce that behavior,
305
+ please [creating an issue](https://github.com/skops-dev/skops/issues) and let us
306
+ know.
307
+
308
+ ### Contact
309
+
310
+ If you want to contact us, you can join our discord channel. To do that, follow
311
+ [these
312
+ instructions](https://skops.readthedocs.io/en/stable/community.html#discord).
313
+ """
314
+
315
+
316
+ def add_help_content():
317
+ # This is the exact same text as in the README.md of this space
318
+ st.markdown(help_md)
319
+
320
+
321
+ def help_page():
322
+ add_back_button()
323
+ add_help_content()
start.py CHANGED
@@ -31,10 +31,11 @@ from skops import card, hub_utils
31
 
32
 
33
  tmp_path = Path(mkdtemp(prefix="skops-")) # temporary files
34
- description = """Create an sklearn model card
35
 
36
- This Hugging Face Space that aims to provide a simple interface to use the
37
- [`skops`](https://skops.readthedocs.io/) model card creation utilities.
 
38
 
39
  """
40
 
@@ -133,7 +134,14 @@ def create_hf_model_card() -> None:
133
 
134
  try:
135
  allow_patterns = [
136
- "*.md", ".txt", "*.png", "*.gif", "*.jpg", "*.jpeg", "*.bmp", "*.webp"
 
 
 
 
 
 
 
137
  ]
138
  path = snapshot_download(repo_id, allow_patterns=allow_patterns)
139
  except (HFValidationError, RepositoryNotFoundError):
@@ -154,6 +162,18 @@ def create_hf_model_card() -> None:
154
  st.session_state.screen.state = "edit"
155
 
156
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  def start_input_form():
158
  if "model" not in st.session_state:
159
  st.session_state.model = DummyClassifier()
@@ -165,6 +185,9 @@ def start_input_form():
165
  st.session_state.model_card = None
166
 
167
  st.markdown(description)
 
 
 
168
  st.markdown("---")
169
 
170
  st.text(
@@ -191,7 +214,7 @@ def start_input_form():
191
  st.markdown("---")
192
 
193
  st.selectbox(
194
- label="Choose the task type*",
195
  options=[
196
  "tabular-classification",
197
  "tabular-regression",
@@ -204,7 +227,7 @@ def start_input_form():
204
  st.markdown("---")
205
 
206
  st.text_area(
207
- label="Requirements*",
208
  value=f"scikit-learn=={sklearn.__version__}\n",
209
  key="requirements",
210
  on_change=init_repo,
@@ -221,6 +244,7 @@ def start_input_form():
221
 
222
  with col_2:
223
  with st.form("Load existing model card from HF Hub", clear_on_submit=False):
 
224
  st.text_input("Repo name (e.g. 'gpt2')", key="hf_repo_id")
225
  st.form_submit_button("Load", on_click=create_hf_model_card)
226
 
 
31
 
32
 
33
  tmp_path = Path(mkdtemp(prefix="skops-")) # temporary files
34
+ description = """Create a Hugging Face model repository for scikit learn models
35
 
36
+ This page aims to provide a simple interface to use the
37
+ [`skops`](https://skops.readthedocs.io/) model card and HF Hub creation
38
+ utilities.
39
 
40
  """
41
 
 
134
 
135
  try:
136
  allow_patterns = [
137
+ "*.md",
138
+ ".txt",
139
+ "*.png",
140
+ "*.gif",
141
+ "*.jpg",
142
+ "*.jpeg",
143
+ "*.bmp",
144
+ "*.webp",
145
  ]
146
  path = snapshot_download(repo_id, allow_patterns=allow_patterns)
147
  except (HFValidationError, RepositoryNotFoundError):
 
162
  st.session_state.screen.state = "edit"
163
 
164
 
165
+ def add_help_button():
166
+ def fn():
167
+ st.session_state.screen.state = "help"
168
+
169
+ st.button(
170
+ "Get help",
171
+ on_click=fn,
172
+ help="Detailed explanation of this space",
173
+ key="get_help",
174
+ )
175
+
176
+
177
  def start_input_form():
178
  if "model" not in st.session_state:
179
  st.session_state.model = DummyClassifier()
 
185
  st.session_state.model_card = None
186
 
187
  st.markdown(description)
188
+
189
+ add_help_button()
190
+
191
  st.markdown("---")
192
 
193
  st.text(
 
214
  st.markdown("---")
215
 
216
  st.selectbox(
217
+ label="Choose the task type",
218
  options=[
219
  "tabular-classification",
220
  "tabular-regression",
 
227
  st.markdown("---")
228
 
229
  st.text_area(
230
+ label="Requirements",
231
  value=f"scikit-learn=={sklearn.__version__}\n",
232
  key="requirements",
233
  on_change=init_repo,
 
244
 
245
  with col_2:
246
  with st.form("Load existing model card from HF Hub", clear_on_submit=False):
247
+ st.markdown("Load existing model card from HF Hub")
248
  st.text_input("Repo name (e.g. 'gpt2')", key="hf_repo_id")
249
  st.form_submit_button("Load", on_click=create_hf_model_card)
250