Skip to content

Make it possible to collapse/fold any section in model card #315

@BenjaminBossan

Description

@BenjaminBossan

Right now, it is possible to collapse/fold certain types of sections, plots and tables, but not others, especially normal text sections. Other sections like hyperparams are always folded with no way to disable that. It would be nice if all types of sections could be folded in a consistent manner.

To achieve this, all Section classes should have a folded parameter and all add_* methods should expose it. It might be useful to change the Section's format methods to _format and to add a format method that adds the folding:

@dataclass
class Section:
    ...
    folded: bool = False
   ...
    def _format(self) -> str:  # <= used to be format
        return self.content

    def format(self) -> str:  # <= new format takes care of folding
        return wrap_as_details(self._format(), folded=self.folded)

This would be a small deviation from current behavior. Right now, if I add, say, a table with a description and with folded=True, only the table is folded, not the description. With the proposed change, everything would be folded, but I think that's actually better.

With #310 being merged, it would also be possible to change the folding after the fact:

model_card.add_plot(..., folded=False)
# nah, let's fold it
model_card.select(<fig section name>).folded = True

If users add multiple contents with a single add call, then the folded parameter would be the same for all of them. If they want to have some folded and some non-folded contents, they would need to call add multiple times.

An open question to me is what to do with the subsections if a section is folded.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions