Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checks for images using PIL only if available #1112

Merged
merged 4 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/distilabel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@

from rich import traceback as rich_traceback

__version__ = "1.5.2"
__version__ = "1.6.0"

rich_traceback.install(show_locals=True)
21 changes: 19 additions & 2 deletions src/distilabel/distiset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import importlib.util
import json
import logging
import os.path as posixpath
Expand Down Expand Up @@ -52,6 +53,19 @@
from distilabel.pipeline._dag import DAG


def is_PIL_available() -> bool:
"""Checks if the PIL library is available.

Returns:
True if the PIL library is available, False otherwise.
"""
try:
importlib.util.find_spec("PIL")
except ImportError:
return False
return True


class Distiset(dict):
"""Convenient wrapper around `datasets.Dataset` to push to the Hugging Face Hub.

Expand Down Expand Up @@ -187,11 +201,14 @@ def _get_card(
record = (
dataset[0] if not isinstance(dataset, dict) else dataset["train"][0]
)
from PIL import ImageFile
if is_PIL_available():
from PIL import ImageFile
else:
ImageFile = None

for key, value in record.items():
# If the value is an image, we set it to an empty string to avoid the `README.md` to huge
if isinstance(value, ImageFile.ImageFile):
if ImageFile and isinstance(value, ImageFile.ImageFile):
value = ""
# If list is too big, the `README.md` generated will be huge so we truncate it
elif isinstance(value, list):
Expand Down
Loading