Datasets:

Modalities:
Image
Text
Formats:
parquet
Languages:
English
Libraries:
Datasets
Dask
License:
Brett Renfer commited on
Commit
1c3f728
·
2 Parent(s): 9184420 c9ef186
Files changed (5) hide show
  1. README.md +25 -1
  2. add_images.py +99 -0
  3. clean.py +26 -0
  4. metadata_cleaned.csv.gz +3 -0
  5. metadata_just_images.csv.gz +3 -0
README.md CHANGED
@@ -3,6 +3,9 @@ license: cc0-1.0
3
  language:
4
  - en
5
  pretty_name: The Metropolitan Museum of Art - Open Access CSV
 
 
 
6
  ---
7
  The Metropolitan Museum of Art Open Access on HuggingFace
8
  ===================
@@ -13,11 +16,32 @@ Since it was founded in 1870, The Met has always aspired to be more than a treas
13
 
14
  The Metropolitan Museum of Art provides select datasets of information on more than 470,000 artworks in its Collection for unrestricted commercial and noncommercial use. To the extent possible under law, The Metropolitan Museum of Art has waived all copyright and related or neighboring rights to this dataset using [Creative Commons Zero](https://creativecommons.org/publicdomain/zero/1.0/). This work is published from: The United States Of America. You can also find the text of the CC Zero deed in the file [LICENSE](https://github.com/metmuseum/openaccess/blob/master/LICENSE) in this repository. These select datasets are now available for use in any media without permission or fee; they also include identifying data for artworks under copyright. The datasets support the search, use, and interaction with the Museum's collection.
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  ## Additional usage guidelines
17
  For more details on how to use images of artworks in The Metropolitan Museum of Art’s collection, please visit our [Open Access](http://www.metmuseum.org/about-the-met/policies-and-documents/image-resources) page.
18
 
 
 
19
  ## Updating or recreating the CSV + images
20
- Right now, this is a manual process. Working on it!
 
21
  1. Download or clone the CSV from our [github](https://github.com/metmuseum/openaccess)
22
  2. (Optional) Create a compressed CSV
23
  * Since some operating systems or machines choke on our huge CSV, it can be convenient to compress the file.
 
3
  language:
4
  - en
5
  pretty_name: The Metropolitan Museum of Art - Open Access CSV
6
+
7
+ dataset_info:
8
+ features:
9
  ---
10
  The Metropolitan Museum of Art Open Access on HuggingFace
11
  ===================
 
16
 
17
  The Metropolitan Museum of Art provides select datasets of information on more than 470,000 artworks in its Collection for unrestricted commercial and noncommercial use. To the extent possible under law, The Metropolitan Museum of Art has waived all copyright and related or neighboring rights to this dataset using [Creative Commons Zero](https://creativecommons.org/publicdomain/zero/1.0/). This work is published from: The United States Of America. You can also find the text of the CC Zero deed in the file [LICENSE](https://github.com/metmuseum/openaccess/blob/master/LICENSE) in this repository. These select datasets are now available for use in any media without permission or fee; they also include identifying data for artworks under copyright. The datasets support the search, use, and interaction with the Museum's collection.
18
 
19
+ ## Documentation in progress
20
+ This data is provided “as is” and you use this data at your own risk. The Metropolitan Museum of Art makes no representations or warranties of any kind. Documentation of the Museum’s collection is an ongoing process and parts of the datasets are incomplete.
21
+
22
+ We plan to update the datasets with new and revised information on a regular basis. You are advised to regularly update your copy of the datasets to ensure you are using the best available information.
23
+
24
+ ## Pull requests
25
+ Because these datasets are generated from our internal database, we do not accept pull requests. If you have identified errors or have extra information to share, please email us at openaccess@metmuseum.org and we will forward to the appropriate department for review.
26
+
27
+ ## Attribution
28
+ Please consider attributing or citing The Metropolitan Museum of Art's CC0 select datasets, especially with respect to research or publication. Attribution supports efforts to release other datasets in the future. It also reduces the amount of "orphaned data," helping to retain source links.
29
+
30
+ ## Do not misrepresent the dataset
31
+ Do not mislead others or misrepresent the datasets or their source. You must not use The Metropolitan Museum of Art’s trademarks or otherwise claim or imply that the Museum or any other third party endorses you or your use of the dataset.
32
+
33
+ Whenever you transform, translate or otherwise modify the dataset, you must make it clear that the resulting information has been modified. If you enrich or otherwise modify the dataset, consider publishing the derived dataset without reuse restrictions.
34
+
35
+ The writers of these guidelines thank the [The Museum of Modern Art](https://www.moma.org/), the [Tate](https://www.tate.org.uk/), [Cooper-Hewitt](https://www.cooperhewitt.org/), and [Europeana](https://www.europeana.eu/en).
36
+
37
  ## Additional usage guidelines
38
  For more details on how to use images of artworks in The Metropolitan Museum of Art’s collection, please visit our [Open Access](http://www.metmuseum.org/about-the-met/policies-and-documents/image-resources) page.
39
 
40
+ ---------------------
41
+
42
  ## Updating or recreating the CSV + images
43
+ Right now, this is a manual process. This will eventually be automated.
44
+
45
  1. Download or clone the CSV from our [github](https://github.com/metmuseum/openaccess)
46
  2. (Optional) Create a compressed CSV
47
  * Since some operating systems or machines choke on our huge CSV, it can be convenient to compress the file.
add_images.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import gzip
3
+ import csv
4
+ import requests
5
+ from requests.adapters import HTTPAdapter, Retry
6
+ import urllib3
7
+
8
+ import urllib.parse
9
+ from io import StringIO
10
+
11
+
12
+ # NOTE: this is not a good idea; this is solely a fix for Met networks
13
+ do_verify = False
14
+
15
+ if not do_verify:
16
+ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
17
+
18
+ # Setup HTTPAdaptor & requests session to add retry pattern
19
+ s = requests.Session()
20
+
21
+ retries = Retry(total=3,
22
+ backoff_factor=0.1,
23
+ status_forcelist=[ 500, 502, 503, 504 ])
24
+
25
+ s.mount('https://', HTTPAdapter(max_retries=retries))
26
+
27
+ # Function to load and clean the CSV data
28
+ def load_and_clean_csv(file_path):
29
+ valid_rows = []
30
+ invalid_rows = []
31
+
32
+ index = 0
33
+
34
+ # Read the gzip file line by line
35
+ with gzip.open(file_path, 'rt') as f:
36
+ reader = csv.reader(f)
37
+ header = next(reader) # Read the header separately
38
+ header.append("primaryImageSmall") # Add the new column to the header
39
+ valid_rows.append(header)
40
+ expected_columns = len(header) - 1 # Exclude the new column
41
+
42
+ for line in f:
43
+ try:
44
+ # Try to parse the line
45
+ row = next(csv.reader([line]))
46
+ index = index + 1
47
+ # print(len(row)+":"+expected_columns)
48
+ if len(row) == expected_columns:
49
+ # Fetch primaryImageSmall from the API
50
+ object_id = row[4]
51
+ image_url = fetch_primary_image_small(object_id)
52
+ image_url = image_url.replace(" ","%20")
53
+ image_url = image_url.replace(u'\u2013',"–")
54
+ row.append(image_url)
55
+ valid_rows.append(row)
56
+
57
+ if index % 100 == 0:
58
+ print("Fetched " + str(index) +" image URLs")
59
+ else:
60
+ invalid_rows.append(line)
61
+ except Exception as e:
62
+ print(e)
63
+ invalid_rows.append(line)
64
+
65
+ print(f"Found {len(invalid_rows)} invalid rows")
66
+ return valid_rows, invalid_rows
67
+
68
+ # Function to fetch the primaryImageSmall URL from the MET Museum API
69
+ def fetch_primary_image_small(object_id):
70
+ url = f"https://collectionapi.metmuseum.org/public/collection/v1/objects/{object_id}"
71
+ try:
72
+ response = s.get(url, verify=do_verify)
73
+ response.raise_for_status() # Raise an error for bad status codes
74
+ data = response.json()
75
+ # print (data.get("primaryImageSmall", ""))
76
+ return data.get("primaryImageSmall", "")
77
+ except Exception as e:
78
+ print(f"Error fetching image for object ID {object_id}: {e}")
79
+ return ""
80
+
81
+ # Function to save the cleaned data to a new gzip CSV file
82
+ def save_cleaned_csv(valid_rows, output_path):
83
+ with gzip.open(output_path, 'wt', newline='') as f:
84
+ writer = csv.writer(f)
85
+ writer.writerows(valid_rows)
86
+ print(f"Cleaned data saved to {output_path}")
87
+
88
+ def main():
89
+ input_file = 'metadata.csv.gz'
90
+ output_file = 'metadata_images.csv.gz'
91
+
92
+ # Load and clean the data
93
+ valid_rows, invalid_rows = load_and_clean_csv(input_file)
94
+
95
+ # Save the cleaned data
96
+ save_cleaned_csv(valid_rows, output_file)
97
+
98
+ if __name__ == "__main__":
99
+ main()
clean.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ import gzip
3
+ import io
4
+
5
+ def load_and_process_csv(input_file_path, output_file_path):
6
+ with gzip.open(input_file_path, 'rt', newline='', encoding='utf-8') as infile:
7
+ reader = csv.reader(infile)
8
+ rows = list(reader)
9
+
10
+ processed_rows = []
11
+ for row in rows:
12
+ processed_row = []
13
+ for field in row:
14
+ if field.startswith('"') and field.endswith('"'):
15
+ field = field.replace('\n', ' ')
16
+ processed_row.append(field)
17
+ processed_rows.append(processed_row)
18
+
19
+ with gzip.open(output_file_path, 'wt', newline='', encoding='utf-8') as outfile:
20
+ writer = csv.writer(outfile)
21
+ writer.writerows(processed_rows)
22
+
23
+ # Example usage
24
+ input_file_path = 'MetObjects.csv.gz'
25
+ output_file_path = 'metadata.csv.gz'
26
+ load_and_process_csv(input_file_path, output_file_path)
metadata_cleaned.csv.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:88afe8c754ffb90dba4305d8092390f800a7f81209611b9cba5fcb43af824aea
3
+ size 35757161
metadata_just_images.csv.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2d95e545c75a6689ace9a339ed2fce7c05b3ac4e28769a1ea01dc6a3b2701985
3
+ size 14474650