MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / generate_meta_json

Function generate_meta_json

PosterAgent/create_dataset.py:8–39  ·  view source on GitHub ↗
(base_dir='Paper2Poster-data')

Source from the content-addressed store, hash-verified

6import json
7
8def generate_meta_json(base_dir='Paper2Poster-data'):
9 # Loop over each item in the specified base directory
10 for folder_name in os.listdir(base_dir):
11 subfolder_path = os.path.join(base_dir, folder_name)
12
13 # Ensure the item is a directory
14 if os.path.isdir(subfolder_path):
15 poster_path = os.path.join(subfolder_path, 'poster.png')
16
17 # Check if the poster.png exists in the subfolder
18 if os.path.exists(poster_path):
19 try:
20 # Open the image and get size (width, height)
21 with Image.open(poster_path) as img:
22 width, height = img.size
23
24 # Prepare metadata dictionary
25 metadata = {
26 'width': width,
27 'height': height
28 }
29
30 # Write metadata to meta.json in the same subfolder
31 meta_json_path = os.path.join(subfolder_path, 'meta.json')
32 with open(meta_json_path, 'w') as json_file:
33 json.dump(metadata, json_file)
34
35 print(f"Metadata for '{folder_name}' saved successfully.")
36 except Exception as e:
37 print(f"Error processing image in folder '{folder_name}': {e}")
38 else:
39 print(f"No poster.png found in folder '{folder_name}'.")
40
41if __name__ == "__main__":
42 dataset = load_dataset("Paper2Poster/Paper2Poster", split="train")

Callers 1

create_dataset.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected