Skip to content

Commit 135ccee

Browse files
Snippet for sklearn (#341)
* first commit * align with moon-landing * return for non-skops snippet * Update js/src/lib/interfaces/Libraries.ts Co-authored-by: Omar Sanseviero <[email protected]> * nits * added disclaimer * Update js/src/lib/interfaces/Libraries.ts Co-authored-by: Omar Sanseviero <[email protected]> Co-authored-by: Omar Sanseviero <[email protected]>
1 parent 7900784 commit 135ccee

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

js/src/lib/interfaces/Libraries.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,26 @@ const timm = (model: ModelData) =>
218218
219219
model = timm.create_model("hf_hub:${model.id}", pretrained=True)`;
220220

221-
const sklearn = (model: ModelData) =>
222-
`from huggingface_hub import hf_hub_download
221+
const sklearn = (model: ModelData) => {
222+
if (model.tags?.includes("skops")) {
223+
const skopsmodelFile = model.config?.sklearn?.filename;
224+
return `from skops.hub_utils import download
225+
from skops.io import load
226+
227+
download("${model.id}", "path_to_folder")
228+
# make sure model file is in skops format
229+
# if model is a pickle file, make sure it's from a source you trust
230+
model = load("path_to_folder/${skopsmodelFile}")`;
231+
} else {
232+
return `from huggingface_hub import hf_hub_download
223233
import joblib
224234
225235
model = joblib.load(
226236
hf_hub_download("${model.id}", "sklearn_model.joblib")
227-
)`;
237+
)`;
238+
}
239+
};
240+
228241

229242
const fastai = (model: ModelData) =>
230243
`from huggingface_hub import from_pretrained_fastai

0 commit comments

Comments
 (0)