Skip to content

Commit

Permalink
Merged card command with catalog. #1264 (#1285)
Browse files Browse the repository at this point in the history
* remove card command

* remove unused class

* add ModelCard class

* add new card flag and update catalog function

* de-register card function in cmd.py

* remove card.py

* Refactor '--card' to a flag and add 'model' as a positional argument

- Changed the '--card' option to a flag with a default value of 'False'.
- Added 'model' as a positional argument to the 'catalog' command and made it optional.
- Implemented logic to handle the case where 'card' is provided without a 'model'.
- Added error handling to notify user if no metadata is found for the specified model when using the 'card' flag.

* Removed dead code and unncessary comments

* Fix omission by displaying errors in red

* update --card option help text

---------

Co-authored-by: Dhanshree Arora <[email protected]>
  • Loading branch information
teddyCodex and DhanshreeA authored Oct 9, 2024
1 parent 1d54d56 commit a5a2f37
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 51 deletions.
4 changes: 0 additions & 4 deletions ersilia/cli/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ def auth(self):
m = importlib.import_module("ersilia.cli.commands.auth")
m.auth_cmd()

def card(self):
m = importlib.import_module("ersilia.cli.commands.card")
m.card_cmd()

def catalog(self):
m = importlib.import_module("ersilia.cli.commands.catalog")
m.catalog_cmd()
Expand Down
44 changes: 0 additions & 44 deletions ersilia/cli/commands/card.py

This file was deleted.

40 changes: 38 additions & 2 deletions ersilia/cli/commands/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from . import ersilia_cli
from ...hub.content.catalog import ModelCatalog
from ...hub.content.search import ModelSearcher
from ...hub.content.card import ModelCard


def catalog_cmd():
Expand All @@ -29,7 +29,43 @@ def catalog_cmd():
default=False,
help="Show more information than just the EOS identifier",
)
def catalog(local=False, file_name=None, browser=False, more=False):
@click.option(
"--card",
is_flag=True,
default=False,
help="Use this flag to display model card for a given model ID",
)
@click.argument(
"model",
type=click.STRING,
required=False,
)
def catalog(
local=False, file_name=None, browser=False, more=False, card=False, model=None
):
if card and not model:
click.echo(
click.style("Error: --card option requires a model ID", fg="red"),
err=True,
)
return
if card and model:
try:
mc = ModelCard()
model_metadata = mc.get(model, as_json=True)

if not model_metadata:
click.echo(
click.style(
f"Error: No metadata found for model ID '{model}'", fg="red"
),
err=True,
)
return
click.echo(model_metadata)
except Exception as e:
click.echo(click.style(f"Error fetching model metadata: {e}", fg="red"))
return
if local is True and browser is True:
click.echo(
"You cannot show the local model catalog in the browser",
Expand Down
1 change: 0 additions & 1 deletion ersilia/cli/create_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def create_ersilia_cli():
cmd = Command()

cmd.auth()
cmd.card()
cmd.catalog()
cmd.clear()
cmd.close()
Expand Down

0 comments on commit a5a2f37

Please sign in to comment.