Skip to content

Commit

Permalink
Fix hub model card (#33)
Browse files Browse the repository at this point in the history
* fix missing model_card.md

* fix missing model_card

* update manifest.in
  • Loading branch information
clementchadebec committed Jul 7, 2022
1 parent dbcfb54 commit 37d4e07
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="pythae",
version="0.0.4",
version="0.0.5",
author="Clement Chadebec (HekA team INRIA)",
author_email="clement.chadebec@inria.fr",
description="Unifying Generative Autoencoders in Python",
Expand Down
21 changes: 11 additions & 10 deletions src/pythae/models/base/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from ..nn import BaseDecoder, BaseEncoder
from ..nn.default_architectures import Decoder_AE_MLP
from .base_config import BaseAEConfig, EnvironmentConfig
from .base_utils import CPU_Unpickler, ModelOutput, hf_hub_is_available
from .base_utils import CPU_Unpickler, ModelOutput, hf_hub_is_available, model_card_template

logger = logging.getLogger(__name__)
console = logging.StreamHandler()
Expand Down Expand Up @@ -188,15 +188,6 @@ def push_to_hf_hub(self, hf_hub_path: str): # pragma: no cover
api = HfApi()
hf_operations = []

hf_operations.append(
CommitOperationAdd(
path_in_repo="README.md",
path_or_fileobj=os.path.join(
os.path.dirname(os.path.abspath(__file__)), "model_card.md"
),
)
)

for file in model_files:
hf_operations.append(
CommitOperationAdd(
Expand All @@ -205,6 +196,16 @@ def push_to_hf_hub(self, hf_hub_path: str): # pragma: no cover
)
)

with open(os.path.join(tempdir, "model_card.md"), "w") as f:
f.write(model_card_template)

hf_operations.append(
CommitOperationAdd(
path_in_repo="README.md",
path_or_fileobj=os.path.join(tempdir, "model_card.md"),
)
)

try:
api.create_commit(
commit_message=f"Uploading {self.model_name} in {hf_hub_path}",
Expand Down
15 changes: 15 additions & 0 deletions src/pythae/models/base/base_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
logger.addHandler(console)
logger.setLevel(logging.INFO)

model_card_template = """---
language: en
tags:
- pythae
license: apache-2.0
---
### Downloading this model from the Hub
This model was trained with pythae. It can be downloaded or reloaded using the method `load_from_hf_hub`
```python
>>> from pythae.models import AutoModel
>>> model = AutoModel.load_from_hf_hub(hf_hub_path="your_hf_username/repo_name")
```
"""


def hf_hub_is_available():
return importlib.util.find_spec("huggingface_hub") is not None
Expand Down
13 changes: 0 additions & 13 deletions src/pythae/models/base/model_card.md

This file was deleted.

0 comments on commit 37d4e07

Please sign in to comment.