Add files using upload-large-folder tool
Browse files- CreateDataset.py +8 -8
- metadata.parquet +3 -0
CreateDataset.py
CHANGED
|
@@ -11,7 +11,6 @@ import argparse
|
|
| 11 |
from pathlib import Path
|
| 12 |
import pandas as pd
|
| 13 |
from pydantic import BaseModel, field_validator
|
| 14 |
-
from typing import Optional
|
| 15 |
|
| 16 |
|
| 17 |
IMAGE_EXT = {".jpg", ".jpeg", ".png", ".webp"}
|
|
@@ -23,15 +22,15 @@ def clean_name(name: str) -> str:
|
|
| 23 |
|
| 24 |
|
| 25 |
class MemeRecord(BaseModel):
|
| 26 |
-
image_file_name:
|
| 27 |
-
video_file_name:
|
| 28 |
category: str
|
| 29 |
caption: str = ""
|
| 30 |
|
| 31 |
@field_validator("image_file_name", "video_file_name")
|
| 32 |
@classmethod
|
| 33 |
-
def normalize_path(cls, v:
|
| 34 |
-
return v.replace("\\", "/") if v else
|
| 35 |
|
| 36 |
@field_validator("category")
|
| 37 |
@classmethod
|
|
@@ -56,32 +55,33 @@ def main(root: Path):
|
|
| 56 |
for file in files:
|
| 57 |
path = Path(root_dir) / file
|
| 58 |
ext = path.suffix.lower()
|
| 59 |
-
|
| 60 |
rel = str(path.relative_to(root))
|
| 61 |
|
| 62 |
if ext in IMAGE_EXT:
|
| 63 |
records.append(
|
| 64 |
MemeRecord(
|
| 65 |
image_file_name=rel,
|
|
|
|
| 66 |
category=category
|
| 67 |
)
|
| 68 |
)
|
| 69 |
elif ext in VIDEO_EXT:
|
| 70 |
records.append(
|
| 71 |
MemeRecord(
|
|
|
|
| 72 |
video_file_name=rel,
|
| 73 |
category=category
|
| 74 |
)
|
| 75 |
)
|
| 76 |
|
| 77 |
if not records:
|
| 78 |
-
raise SystemExit("❌ No media found")
|
| 79 |
|
| 80 |
df = pd.DataFrame([r.model_dump() for r in records])
|
| 81 |
df.to_csv(root / "metadata.csv", index=False)
|
| 82 |
df.to_parquet(root / "metadata.parquet", index=False)
|
| 83 |
|
| 84 |
-
print(f"✔ Indexed {len(df)} files (HF
|
| 85 |
|
| 86 |
|
| 87 |
if __name__ == "__main__":
|
|
|
|
| 11 |
from pathlib import Path
|
| 12 |
import pandas as pd
|
| 13 |
from pydantic import BaseModel, field_validator
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
IMAGE_EXT = {".jpg", ".jpeg", ".png", ".webp"}
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
class MemeRecord(BaseModel):
|
| 25 |
+
image_file_name: str = ""
|
| 26 |
+
video_file_name: str = ""
|
| 27 |
category: str
|
| 28 |
caption: str = ""
|
| 29 |
|
| 30 |
@field_validator("image_file_name", "video_file_name")
|
| 31 |
@classmethod
|
| 32 |
+
def normalize_path(cls, v: str) -> str:
|
| 33 |
+
return v.replace("\\", "/") if v else ""
|
| 34 |
|
| 35 |
@field_validator("category")
|
| 36 |
@classmethod
|
|
|
|
| 55 |
for file in files:
|
| 56 |
path = Path(root_dir) / file
|
| 57 |
ext = path.suffix.lower()
|
|
|
|
| 58 |
rel = str(path.relative_to(root))
|
| 59 |
|
| 60 |
if ext in IMAGE_EXT:
|
| 61 |
records.append(
|
| 62 |
MemeRecord(
|
| 63 |
image_file_name=rel,
|
| 64 |
+
video_file_name="",
|
| 65 |
category=category
|
| 66 |
)
|
| 67 |
)
|
| 68 |
elif ext in VIDEO_EXT:
|
| 69 |
records.append(
|
| 70 |
MemeRecord(
|
| 71 |
+
image_file_name="",
|
| 72 |
video_file_name=rel,
|
| 73 |
category=category
|
| 74 |
)
|
| 75 |
)
|
| 76 |
|
| 77 |
if not records:
|
| 78 |
+
raise SystemExit("❌ No media files found")
|
| 79 |
|
| 80 |
df = pd.DataFrame([r.model_dump() for r in records])
|
| 81 |
df.to_csv(root / "metadata.csv", index=False)
|
| 82 |
df.to_parquet(root / "metadata.parquet", index=False)
|
| 83 |
|
| 84 |
+
print(f"✔ Indexed {len(df)} files (HF streaming safe)")
|
| 85 |
|
| 86 |
|
| 87 |
if __name__ == "__main__":
|
metadata.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7a68320e83cbd6f5490e69115ae8eb165e73c50bf8bb52ac5565b3ec9a696b1a
|
| 3 |
+
size 3560
|