shikanime commited on
Commit
be12e47
·
unverified ·
1 Parent(s): 19dc96f

add dataset def

Browse files
Files changed (4) hide show
  1. .gitattributes +2 -0
  2. .gitignore +10 -0
  3. README.md +95 -0
  4. nhentai.py +122 -0
.gitattributes CHANGED
@@ -57,3 +57,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
57
  # Video files - compressed
58
  *.mp4 filter=lfs diff=lfs merge=lfs -text
59
  *.webm filter=lfs diff=lfs merge=lfs -text
 
 
 
57
  # Video files - compressed
58
  *.mp4 filter=lfs diff=lfs merge=lfs -text
59
  *.webm filter=lfs diff=lfs merge=lfs -text
60
+ # Comic files - compressed
61
+ *.cbz filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
README.md ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ task_categories:
4
+ - image-classification
5
+ - image-to-image
6
+ - image-to-text
7
+ language:
8
+ - ja
9
+ - en
10
+ tags:
11
+ - manga
12
+ - comics
13
+ - adult
14
+ pretty_name: Nhentai Dataset
15
+ size_categories:
16
+ - 10K<n<100K
17
+ ---
18
+
19
+ # Nhentai Dataset
20
+
21
+ A collection of Japanese manga in CBZ format from Nhentai, containing adult
22
+ content manga with associated metadata.
23
+
24
+ ## Content Warning
25
+
26
+ This dataset contains adult content (NSFW) and is intended for research purposes
27
+ only. Users must be of legal age and comply with all applicable laws and
28
+ regulations.
29
+
30
+ ## Key Applications
31
+
32
+ - Image Analysis: Suitable for manga page segmentation, panel detection, and art
33
+ style analysis
34
+ - Text Recognition: Useful for Japanese text detection and translation in manga
35
+ contexts
36
+ - Content Classification: Applicable for genre classification and content
37
+ tagging systems
38
+
39
+ ## Dataset Structure
40
+
41
+ The dataset is organized as a collection of CBZ files, each representing a
42
+ complete manga volume with associated metadata.
43
+
44
+ ### Data Instances
45
+
46
+ Each instance represents a manga volume containing:
47
+
48
+ - Sequential manga pages as images
49
+ - Associated metadata (title, tags, etc.)
50
+ - Text content (if available)
51
+
52
+ ### Data Fields
53
+
54
+ - `comic`: List of images from the CBZ file
55
+ - `title`: Full title of the work
56
+ - `media_id`: Unique identifier
57
+ - `num_favorites`: Number of user favorites
58
+ - `tag`: List of content tags and themes
59
+ - `language`: List of available languages
60
+ - `artist`: List of credited artists
61
+ - `category`: Content category (e.g., "manga")
62
+ - `num_pages`: Total number of pages
63
+ - `scanlator`: Translation group (if any)
64
+ - `group`: List of publishing groups
65
+ - `parody`: List of source materials
66
+ - `character`: List of featured characters
67
+ - `epos`: Epoch timestamp of upload
68
+ - `file_name`: Original archive filename
69
+
70
+ ## Dataset Creation
71
+
72
+ ### Source Data
73
+
74
+ The data is sourced from publicly available manga on Nhentai, processed and
75
+ stored in CBZ format for efficient access and preservation of image quality.
76
+
77
+ ### Preprocessing
78
+
79
+ - Images are preserved in their original resolution
80
+ - Metadata is extracted and standardized
81
+ - Files are organized in CBZ format for efficient storage and access
82
+
83
+ ## Considerations
84
+
85
+ ### Social Impact and Biases
86
+
87
+ This dataset contains adult content and may reflect various biases. Users should
88
+ be aware of and account for these aspects in their applications.
89
+
90
+ ### Legal & Ethical Considerations
91
+
92
+ - Users must comply with age restrictions and local regulations
93
+ - The dataset should be used responsibly and in accordance with applicable laws
94
+ - Proper content filtering and access controls should be implemented in
95
+ applications
nhentai.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import io
2
+ import zipfile
3
+ from collections.abc import Sequence
4
+ from dataclasses import dataclass
5
+ from typing import TYPE_CHECKING, Union
6
+
7
+ import datasets
8
+
9
+ if TYPE_CHECKING:
10
+ import numpy as np
11
+ import PIL.Image
12
+
13
+ logger = datasets.utils.logging.get_logger(__name__)
14
+
15
+
16
+ @dataclass
17
+ class Comic(datasets.Image):
18
+ """Comic feature that extends Image feature for CBZ files."""
19
+
20
+ def encode_example(
21
+ self, value: Sequence[Union[str, bytes, dict, "np.ndarray", "PIL.Image.Image"]]
22
+ ) -> dict:
23
+ """Encode example into a format for Arrow.
24
+
25
+ Args:
26
+ value (`Sequence` of `str`, `bytes`, `dict`, `np.ndarray`, or
27
+ `PIL.Image.Image`):
28
+ Sequence of data passed as input to Comic feature. Each element can be:
29
+ - A path to a local image file
30
+ - Raw bytes of an image file
31
+ - A dictionary containing image data
32
+ - A numpy array representing an image
33
+ - A PIL Image object
34
+
35
+ Returns:
36
+ `dict` with "path" and "bytes" fields for each image in the sequence
37
+ """
38
+ return [super().encode_example(img) for img in value]
39
+
40
+ def decode_example(
41
+ self, value: dict, token_per_repo_id=None
42
+ ) -> list["PIL.Image.Image"]:
43
+ """Decode example CBZ file into image data.
44
+
45
+ Args:
46
+ value (`str` or `dict`):
47
+ Either a string with absolute path to CBZ file, or a dictionary
48
+ with keys:
49
+ - `path`: String with absolute path to CBZ file.
50
+ - `bytes`: The bytes of the CBZ file.
51
+ token_per_repo_id (`dict`, *optional*):
52
+ To access and decode files from private repositories on the Hub.
53
+
54
+ Returns:
55
+ `List[PIL.Image.Image]`: List of images from CBZ
56
+ """
57
+ if isinstance(value, str):
58
+ zip_file = value
59
+ else:
60
+ zip_file = (
61
+ io.BytesIO(value["bytes"]) if value.get("bytes") else value["path"]
62
+ )
63
+
64
+ with zipfile.ZipFile(zip_file, "r") as zip_ref:
65
+ return [
66
+ super().decode_example(img_file)
67
+ for img_file in sorted(zip_ref.namelist())
68
+ ]
69
+
70
+
71
+ class NhentaiConfig(datasets.folder_based_builder.FolderBasedBuilderConfig):
72
+ """BuilderConfig for ImageFolder."""
73
+
74
+ drop_labels: bool = None
75
+ drop_metadata: bool = None
76
+
77
+ def __post_init__(self):
78
+ super().__post_init__()
79
+
80
+
81
+ class Nhentai(datasets.folder_based_builder.FolderBasedBuilder):
82
+ BASE_COLUMN_NAME = "comic"
83
+ BASE_FEATURE = Comic
84
+ BUILDER_CONFIG_CLASS = NhentaiConfig
85
+ BUILDER_CONFIGS = [
86
+ NhentaiConfig(
87
+ name="nhentai",
88
+ description="Default configuration for nhentai dataset",
89
+ drop_labels=False,
90
+ drop_metadata=False,
91
+ )
92
+ ]
93
+ DEFAULT_CONFIG_NAME = "nhentai"
94
+ EXTENSIONS: list[str] = [".cbz"]
95
+ VERSION = datasets.Version("1.0.0")
96
+
97
+ def _info(self):
98
+ """Returns the dataset metadata."""
99
+ return datasets.DatasetInfo(
100
+ description="Dataset of comic books in CBZ format",
101
+ features=datasets.Features(
102
+ {
103
+ "comic": Comic(),
104
+ "title": datasets.Value("string"),
105
+ "media_id": datasets.Value("int64"),
106
+ "num_favorites": datasets.Value("int64"),
107
+ "tag": datasets.Sequence(datasets.Value("string")),
108
+ "language": datasets.Sequence(datasets.Value("string")),
109
+ "artist": datasets.Sequence(datasets.Value("string")),
110
+ "category": datasets.Sequence(datasets.Value("string")),
111
+ "num_pages": datasets.Value("int64"),
112
+ "scanlator": datasets.Value("string"),
113
+ "group": datasets.Sequence(datasets.Value("string")),
114
+ "parody": datasets.Sequence(datasets.Value("string")),
115
+ "character": datasets.Sequence(datasets.Value("string")),
116
+ "epos": datasets.Value("int64"),
117
+ "file_name": datasets.Value("string"),
118
+ }
119
+ ),
120
+ supervised_keys=None,
121
+ homepage="https://nhentai.net/",
122
+ )