Skip to content

Commit 416749f

Browse files
modelcards and tensorboard are optional
1 parent b1b99b5 commit 416749f

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

setup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,11 @@ def run(self):
161161
extras = {}
162162
extras["quality"] = ["black ~= 22.0", "isort >= 5.5.4", "flake8 >= 3.8.3"]
163163
extras["docs"] = []
164+
extras["training"] = ["tensorboard", "modelcards"]
164165
extras["test"] = [
165166
"pytest",
166167
]
167-
extras["dev"] = extras["quality"] + extras["test"]
168+
extras["dev"] = extras["quality"] + extras["test"] + extras["training"]
168169

169170
install_requires = [
170171
deps["filelock"],
@@ -174,8 +175,6 @@ def run(self):
174175
deps["requests"],
175176
deps["torch"],
176177
deps["Pillow"],
177-
deps["tensorboard"],
178-
deps["modelcards"],
179178
]
180179

181180
setup(

src/diffusers/hub_utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121

2222
from diffusers import DiffusionPipeline
2323
from huggingface_hub import HfFolder, Repository, whoami
24-
from modelcards import CardData, ModelCard
24+
from utils import is_modelcards_available
25+
26+
27+
if is_modelcards_available():
28+
from modelcards import CardData, ModelCard
2529

2630
from .utils import logging
2731

@@ -147,6 +151,12 @@ def push_to_hub(
147151

148152

149153
def create_model_card(args, model_name):
154+
if not is_modelcards_available:
155+
raise ValueError(
156+
"Please make sure to have `modelcards` installed when using the `create_model_card` function. You can"
157+
" install the package with `pip install modelcards`."
158+
)
159+
150160
if hasattr(args, "local_rank") and args.local_rank not in [-1, 0]:
151161
return
152162

src/diffusers/utils/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@
6161
_unidecode_available = False
6262

6363

64+
_modelcards_available = importlib.util.find_spec("modelcards") is not None
65+
try:
66+
_modelcards_version = importlib_metadata.version("modelcards")
67+
logger.debug(f"Successfully imported modelcards version {_modelcards_version}")
68+
except importlib_metadata.PackageNotFoundError:
69+
_modelcards_available = False
70+
71+
6472
def is_transformers_available():
6573
return _transformers_available
6674

@@ -73,6 +81,10 @@ def is_unidecode_available():
7381
return _unidecode_available
7482

7583

84+
def is_modelcards_available():
85+
return _modelcards_available
86+
87+
7688
class RepositoryNotFoundError(HTTPError):
7789
"""
7890
Raised when trying to access a hf.co URL with an invalid repository name, or with a private repo name the user does

0 commit comments

Comments
 (0)