allietran commited on
Commit
32d3527
·
verified ·
1 Parent(s): 355bd62

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. products.parquet +3 -0
  2. restructure.py +37 -0
  3. reviews.parquet +3 -0
products.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:da6343941aad9f23e3f74014f1b23c065ef2071411ff08fcacf120d0df404865
3
+ size 6145231
restructure.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import shutil
3
+ import pandas as pd
4
+
5
+
6
+ def restructure_images(df, image_dir, output_dir):
7
+ """
8
+ Moves images from a flat folder to a nested structure: /01/ab/image_id.jpg
9
+ and updates the DataFrame with the new paths.
10
+ """
11
+ new_paths = []
12
+ for img_id in df["image_path"]:
13
+ # Create nested folders based on first 4 chars of ID
14
+ sub_dir_1 = img_id[0:2]
15
+ sub_dir_2 = img_id[2:4]
16
+
17
+ target_folder = os.path.join(output_dir, sub_dir_1, sub_dir_2)
18
+ os.makedirs(target_folder, exist_ok=True)
19
+
20
+ src = os.path.join(image_dir, f"{img_id}.jpg")
21
+ dst = os.path.join(target_folder, f"{img_id}.jpg")
22
+
23
+ if os.path.exists(src):
24
+ shutil.copy(src, dst)
25
+ # Store relative path for the metadata
26
+ new_paths.append(f"{sub_dir_1}/{sub_dir_2}/{img_id}.jpg")
27
+ else:
28
+ new_paths.append(None)
29
+
30
+ df["relative_path"] = new_paths
31
+ return df
32
+
33
+
34
+ # Usage
35
+ df = pd.read_parquet("products.parquet")
36
+ df = restructure_images(df, "./images_flat", "./images_nested")
37
+ df.to_parquet("products.parquet", index=False)
reviews.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6ffc489a40557346901b0f3e370d3e507f138ec72f8a296f0b0aaae0b0e6e7b1
3
+ size 50519071