From bc82124ee8f6b9f8390ee735f5b014d8aab276b5 Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Thu, 19 Jan 2023 16:26:14 +0100 Subject: [PATCH 1/3] fix for metadata --- skops/card/_model_card.py | 1 + skops/card/tests/test_card.py | 1 + 2 files changed, 2 insertions(+) diff --git a/skops/card/_model_card.py b/skops/card/_model_card.py index 74fa377a..269534c0 100644 --- a/skops/card/_model_card.py +++ b/skops/card/_model_card.py @@ -154,6 +154,7 @@ def metadata_from_config(config_path: Union[str, Path]) -> ModelCardData: if task: card_data.tags += [task] card_data.model_file = config.get("sklearn", {}).get("model", {}).get("file") # type: ignore + card_data.model_format = config.get("sklearn", {}).get("model_format", {}) example_input = config.get("sklearn", {}).get("example_input", None) # Documentation on what the widget expects: # https://huggingface.co/docs/hub/models-widgets-examples diff --git a/skops/card/tests/test_card.py b/skops/card/tests/test_card.py index 92e1c68c..58ad2847 100644 --- a/skops/card/tests/test_card.py +++ b/skops/card/tests/test_card.py @@ -895,6 +895,7 @@ def test_metadata_from_config_tabular_data( } assert metadata["widget"] == expected_data + assert metadata["model_format"] == "pickle" for tag in ["sklearn", "skops", "tabular-classification"]: assert tag in metadata["tags"] From 18b6a580b9237b742672eb82fbc1b57083faefb5 Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Thu, 19 Jan 2023 16:45:04 +0100 Subject: [PATCH 2/3] initialize modelcarddata with model_format --- skops/card/_model_card.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/skops/card/_model_card.py b/skops/card/_model_card.py index 269534c0..33bef3be 100644 --- a/skops/card/_model_card.py +++ b/skops/card/_model_card.py @@ -146,15 +146,15 @@ def metadata_from_config(config_path: Union[str, Path]) -> ModelCardData: with open(config_path) as f: config = json.load(f) - - card_data = ModelCardData() + card_data = ModelCardData( + model_format=config.get("sklearn", {}).get("model_format", {}) + ) card_data.library_name = "sklearn" card_data.tags = ["sklearn", "skops"] task = config.get("sklearn", {}).get("task", None) if task: card_data.tags += [task] card_data.model_file = config.get("sklearn", {}).get("model", {}).get("file") # type: ignore - card_data.model_format = config.get("sklearn", {}).get("model_format", {}) example_input = config.get("sklearn", {}).get("example_input", None) # Documentation on what the widget expects: # https://huggingface.co/docs/hub/models-widgets-examples From 08cbffd6723defd69777c035bf19332393a7dcd9 Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Thu, 19 Jan 2023 17:10:35 +0100 Subject: [PATCH 3/3] added test for skops --- skops/card/tests/test_card.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/skops/card/tests/test_card.py b/skops/card/tests/test_card.py index 58ad2847..df00a8c6 100644 --- a/skops/card/tests/test_card.py +++ b/skops/card/tests/test_card.py @@ -895,10 +895,21 @@ def test_metadata_from_config_tabular_data( } assert metadata["widget"] == expected_data - assert metadata["model_format"] == "pickle" for tag in ["sklearn", "skops", "tabular-classification"]: assert tag in metadata["tags"] + def test_metadata_model_format_pkl( + self, pkl_model_card_metadata_from_config, destination_path + ): + metadata = metadata_load(local_path=Path(destination_path) / "README.md") + assert metadata["model_format"] == "pickle" + + def test_metadata_model_format_skops( + self, skops_model_card_metadata_from_config, destination_path + ): + metadata = metadata_load(local_path=Path(destination_path) / "README.md") + assert metadata["model_format"] == "skops" + @pytest.mark.xfail(reason="dynamic adjustment when model changes not implemented yet") class TestModelDynamicUpdate: