Skip to content
This repository was archived by the owner on Sep 27, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions model_card_toolkit/base_model_card_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ class BaseModelCardField(abc.ABC):
need to override this unless it needs some special process.
"""

def __len__(self) -> int:
"""Returns the number of items in a field. Ignores None values recursively,
so the length of a field that only contains another field that has all None
values would be 0.
"""
return len(self.to_dict())

@property
@abc.abstractmethod
def _proto_type(self):
Expand Down
2 changes: 1 addition & 1 deletion model_card_toolkit/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def export_format(self,
# If model_card is not passed in, read from Proto file.
else:
model_card = self._read_proto_file(self._mcta_proto_file)
if not model_card:
if model_card is None:
raise ValueError('model_card could not be found. '
'Call scaffold_assets() to generate model_card.')

Expand Down
9 changes: 4 additions & 5 deletions model_card_toolkit/model_card_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_merge_from_proto_and_to_proto_with_all_fields(self):

self.assertEqual(want_proto, got_proto)

def test_copy_from_proto_sucess(self):
def test_copy_from_proto_success(self):
# Test fields convert.
owner = model_card.Owner(name="my_name1")
owner_proto = model_card_pb2.Owner(name="my_name2", contact="my_contact2")
Expand All @@ -71,7 +71,7 @@ def test_copy_from_proto_sucess(self):
model_card.ModelDetails(
owners=[model_card.Owner(name="my_name2", contact="my_contact2")]))

def test_merge_from_proto_sucess(self):
def test_merge_from_proto_success(self):
# Test fields convert.
owner = model_card.Owner(name="my_name1")
owner_proto = model_card_pb2.Owner(contact="my_contact1")
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_merge_from_proto_with_invalid_proto(self):
TypeError, ".*expected .*Owner got .*Version.*"):
owner.merge_from_proto(wrong_proto)

def test_to_proto_sucess(self):
def test_to_proto_success(self):
# Test fields convert.
owner = model_card.Owner()
self.assertEqual(owner.to_proto(), model_card_pb2.Owner())
Expand All @@ -125,8 +125,7 @@ def test_to_proto_sucess(self):
self.assertEqual(
model_details.to_proto(),
model_card_pb2.ModelDetails(
owners=[model_card_pb2.Owner(name="my_name", contact="my_contact")],
version=model_card_pb2.Version()))
owners=[model_card_pb2.Owner(name="my_name", contact="my_contact")]))

def test_to_proto_with_invalid_field(self):
owner = model_card.Owner()
Expand Down
11 changes: 8 additions & 3 deletions model_card_toolkit/template/html/default_template.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
{% macro render_metrics_graphics(graphics) %}
<div class="row">
<div class="col">
{{ graphics.description }}
{% if graphics.description %}<p>{{ graphics.description }}</p>{% endif %}
{{ render_graphics(graphics.collection) }}
</div>
</div>
Expand Down Expand Up @@ -115,6 +115,9 @@
margin-left: auto;
margin-right: auto;
}
table {
margin-bottom: 10px;
}
table th {
background: #eee;
}
Expand All @@ -131,14 +134,15 @@
caption { font-weight: bold; }
</style>
<title>
Model Card for {{ model_details.name }}
Model Card{% if model_details.name %} for {{ model_details.name }}{% endif %}
</title>
</head>
<body>
<h1>
Model Card for {{ model_details.name }}
Model Card{% if model_details.name %} for {{ model_details.name }}{% endif %}
</h1>
<div class="row">
{% if model_details %}
<div class="col card">
<h2>Model Details</h2>
{% if model_details.overview %}<h3>Overview</h3>
Expand Down Expand Up @@ -178,6 +182,7 @@
{% endfor %}
</ul>{% endif %}
</div>
{% endif %}
{% if model_parameters.model_architecture or model_parameters.input_format or model_parameters.input_format_map or model_parameters.output_format or model_parameters.output_format_map %}
<div class="col card">
<h2>Model Parameters</h2>
Expand Down
4 changes: 2 additions & 2 deletions model_card_toolkit/template/md/default_template.md.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
|Name|Value|
-----|------{% for metric in metrics %}
|{{ metric_name(metric) }}|{{ metric_value(metric) }}|{% endfor %}{% endmacro %}
# Model Card for {{ model_details.name }}
# Model Card{% if model_details.name %} for {{ model_details.name }}{% endif %}{% if model_details %}

## Model Details{% if model_details.overview %}

Expand All @@ -50,7 +50,7 @@
### Citations
{% for citation in model_details.citations %}
* {{ citation.citation }}{% endfor %}
{% endif %}{% if model_parameters.model_architecture or model_parameters.input_format or model_parameters.output_format %}
{% endif %}{% endif %}{% if model_parameters.model_architecture or model_parameters.input_format or model_parameters.output_format %}

## Model Parameters
{% if model_parameters.model_architecture %}
Expand Down