Benjamin Bossan commited on
Commit
af69d1f
·
1 Parent(s): 1bd69d6

Fix issues with requirements

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -5,7 +5,6 @@ from __future__ import annotations
5
  import base64
6
  import glob
7
  import io
8
- import json
9
  import os
10
  import pickle
11
  import re
@@ -32,7 +31,11 @@ PLOT_PREFIX = "__plot__:"
32
  if "custom_sections" not in st.session_state:
33
  st.session_state.custom_sections = {}
34
 
 
35
  tmp_repo = Path(mkdtemp(prefix="skops-"))
 
 
 
36
  left_col, right_col = st.columns([1, 2])
37
 
38
  # a hacky way to "persist" custom sections
@@ -61,17 +64,19 @@ def _write_plot(plot_name, plot_file):
61
 
62
 
63
  def init_repo():
64
- _clear_repo(tmp_repo)
65
 
66
  try:
67
- file_name = Path(mkdtemp(prefix="skops-")) / "model.skops"
68
  sio.dump(model, file_name)
 
 
69
  hub_utils.init(
70
  model=file_name,
71
- dst=tmp_repo,
72
  task=task,
73
  data=data,
74
- requirements=requirements,
75
  )
76
  except Exception as exc:
77
  print("Uh oh, something went wrong when initializing the repo:", exc)
@@ -116,7 +121,7 @@ def _create_model_card():
116
  return
117
 
118
  init_repo()
119
- metadata = card.metadata_from_config(tmp_repo)
120
  model_card = card.Card(model=model, metadata=metadata)
121
 
122
  if model_description:
@@ -283,9 +288,9 @@ with left_col:
283
  on_change=init_repo,
284
  )
285
 
286
- requirements = st.text_input(
287
  label="Requirements*",
288
- value=[f"scikit-learn=={sklearn.__version__}\n"],
289
  on_change=init_repo,
290
  )
291
 
 
5
  import base64
6
  import glob
7
  import io
 
8
  import os
9
  import pickle
10
  import re
 
31
  if "custom_sections" not in st.session_state:
32
  st.session_state.custom_sections = {}
33
 
34
+ # the tmp_repo is used to upload the sklearn model to
35
  tmp_repo = Path(mkdtemp(prefix="skops-"))
36
+ # the hf_repo is the actual repo used for init()
37
+ hf_repo = Path(mkdtemp(prefix="skops-"))
38
+
39
  left_col, right_col = st.columns([1, 2])
40
 
41
  # a hacky way to "persist" custom sections
 
64
 
65
 
66
  def init_repo():
67
+ _clear_repo(hf_repo)
68
 
69
  try:
70
+ file_name = tmp_repo / "model.skops"
71
  sio.dump(model, file_name)
72
+
73
+ reqs = [r.strip().rstrip(",") for r in requirements.splitlines()]
74
  hub_utils.init(
75
  model=file_name,
76
+ dst=hf_repo,
77
  task=task,
78
  data=data,
79
+ requirements=reqs,
80
  )
81
  except Exception as exc:
82
  print("Uh oh, something went wrong when initializing the repo:", exc)
 
121
  return
122
 
123
  init_repo()
124
+ metadata = card.metadata_from_config(hf_repo)
125
  model_card = card.Card(model=model, metadata=metadata)
126
 
127
  if model_description:
 
288
  on_change=init_repo,
289
  )
290
 
291
+ requirements = st.text_area(
292
  label="Requirements*",
293
+ value=f"scikit-learn=={sklearn.__version__}\n",
294
  on_change=init_repo,
295
  )
296