Skip to content

Commit

Permalink
Merge pull request #1467 from activeloopai/fy_huggingface
Browse files Browse the repository at this point in the history
Import huggingface only when user calls function
  • Loading branch information
FayazRahman authored Feb 1, 2022
2 parents 1e51fb8 + 8667d21 commit 8be1800
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions hub/integrations/huggingface/huggingface.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import Union, Set
from hub.core.dataset import Dataset
from datasets import Dataset as hfDataset # type: ignore
from datasets import ClassLabel, Sequence, DatasetDict # type: ignore
import posixpath
import hub
from tqdm import tqdm # type: ignore


def _is_seq_convertible(seq: Union[Sequence, list]):
def _is_seq_convertible(seq):
from datasets import Sequence

if isinstance(seq, Sequence):
feature = seq.feature
else:
Expand All @@ -25,6 +25,9 @@ def _is_seq_convertible(seq: Union[Sequence, list]):


def _create_tensor_from_feature(key, feature, src, ds):
from datasets import Sequence, ClassLabel
from datasets import Dataset as hfDataset

curr = posixpath.split(key)[-1]
if isinstance(feature, (dict, Sequence, list)):
if isinstance(feature, dict):
Expand Down Expand Up @@ -61,9 +64,9 @@ def _create_tensor_from_feature(key, feature, src, ds):


def ingest_huggingface(
src: Union[hfDataset, DatasetDict],
dest: Union[Dataset, str],
use_progressbar: bool = True,
src,
dest,
use_progressbar=True,
) -> Dataset:
"""Converts hugging face datasets to hub format.
Expand Down Expand Up @@ -95,6 +98,8 @@ def ingest_huggingface(
Note:
Features of the type Sequence(feature=Value(dtype='string')) are not supported. Columns of such type are skipped.
"""
from datasets import DatasetDict

if isinstance(dest, str):
ds = hub.dataset(dest)
else:
Expand Down

0 comments on commit 8be1800

Please sign in to comment.