spacr.model_cards

The 3-page model cards of the Model Zoo: data, repository mapping, images.

Each published segmentation model has three card pages on Hugging Face (cards/page1.png to page3.png): its scores against the stock base, its training facts, and an about-and-links page. The same data ships with spaCR as resources/model_cards/<repo>.json, so a card can be shown as text when the images cannot be fetched.

Nothing here imports Qt; the viewer lives in spacr.qt.widgets.model_card_viewer.

Functions

about_lines(→ List[str])

Page 3 as plain sentences, without the empty fields.

cache_dir(→ pathlib.Path)

Where the page images of repo are cached, under the spaCR home.

cached_pages(→ List[Optional[pathlib.Path]])

The cached image of each page, None where it is not cached.

card_for_entry(→ Optional[Dict[str, Any]])

The card data of a ModelEntry, or None.

card_keys(→ Tuple[str, ...])

The zoo keys that have a 3-page card.

clear_cache(→ None)

Remove the cached images of repo.

fact_rows(→ List[Tuple[str, str]])

Page 2 as (fact, value) pairs.

fetch_pages(→ List[pathlib.Path])

Download the missing page images of repo into the cache.

model_link(→ str)

The Hugging Face URL of the model the card describes.

page_html() → str)

The text fallback of one card page (1-based) as a small HTML body.

page_url(→ str)

The Hugging Face URL of card page page (1-based) of repo.

repo_of_key(→ str)

The owner/repo of a zoo key that has a card, else ''.

repo_url(→ str)

The Hugging Face page of a model repository.

score_rows(→ List[Tuple[str, str]])

Page 1 as (metric, "this (stock x)") pairs.

Module Contents

spacr.model_cards.about_lines(card: Dict[str, Any]) → List[str][source]

Page 3 as plain sentences, without the empty fields.

Parameters:

card – the card data.

spacr.model_cards.cache_dir(repo: str) → pathlib.Path[source]

Where the page images of repo are cached, under the spaCR home.

Parameters:

repo – owner/repo.

spacr.model_cards.cached_pages(repo: str) → List[pathlib.Path | None][source]

The cached image of each page, None where it is not cached.

Parameters:

repo – owner/repo.

spacr.model_cards.card_for_entry(entry: Any) → Dict[str, Any] | None[source]

The card data of a ModelEntry, or None.

Matched on the zoo key, then on the repository the entry is fetched from.

Parameters:

entry – the model zoo entry.

spacr.model_cards.card_keys() → Tuple[str, ...][source]

The zoo keys that have a 3-page card.

spacr.model_cards.clear_cache(repo: str) → None[source]

Remove the cached images of repo.

Parameters:

repo – owner/repo.

spacr.model_cards.fact_rows(card: Dict[str, Any]) → List[Tuple[str, str]][source]

Page 2 as (fact, value) pairs.

Parameters:

card – the card data.

spacr.model_cards.fetch_pages(repo: str, fetch: Callable[[str], bytes] | None = None) → List[pathlib.Path][source]

Download the missing page images of repo into the cache.

Parameters:
  • repo – owner/repo.

  • fetch – byte source taking a URL; defaults to urlopen.

Returns:

the three cached paths.

Raises:

OSError – when a page cannot be fetched or is not a PNG. Pages fetched before the failure stay cached.

The Hugging Face URL of the model the card describes.

Parameters:

card – the card data.

spacr.model_cards.page_html(card: Dict[str, Any], page: int, headers: Tuple[str, str, str, str] = ('Score', 'Value', 'Fact', 'Value')) → str[source]

The text fallback of one card page (1-based) as a small HTML body.

Parameters:
  • card – the card data.

  • page – the page number, from 1.

  • headers – the already translated column headings for the scores and facts tables.

spacr.model_cards.page_url(repo: str, page: int) → str[source]

The Hugging Face URL of card page page (1-based) of repo.

Parameters:
  • repo – owner/repo.

  • page – the page number, from 1.

spacr.model_cards.repo_of_key(key: Any) → str[source]

The owner/repo of a zoo key that has a card, else ''.

Parameters:

key – a model zoo key.

spacr.model_cards.repo_url(repo: str) → str[source]

The Hugging Face page of a model repository.

Parameters:

repo – owner/repo.

spacr.model_cards.score_rows(card: Dict[str, Any]) → List[Tuple[str, str]][source]

Page 1 as (metric, "this (stock x)") pairs.

Parameters:

card – the card data.