Update ecoset.py
Browse files
ecoset.py
CHANGED
@@ -51,8 +51,7 @@ _LICENSE = "CC BY NC SA 2.0"
|
|
51 |
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
52 |
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
53 |
_URLS = {
|
54 |
-
|
55 |
-
"codeocean": "s3://codeocean-datasets/0ab003f4-ff2d-4de3-b4f8-b6e349c0e5e5/ecoset.zip",
|
56 |
}
|
57 |
|
58 |
# Define the labels available for ecoset
|
@@ -131,19 +130,7 @@ class Ecoset(datasets.GeneratorBasedBuilder):
|
|
131 |
print(line.strip())
|
132 |
sys.stdout.flush()
|
133 |
|
134 |
-
|
135 |
-
"""Extremely slow download"""
|
136 |
-
# ask password
|
137 |
-
password = getpass(_PWD_MSG)
|
138 |
-
check_pass(password)
|
139 |
-
# download and unzip
|
140 |
-
print('Using slow Python-based download and unzipping. This can take up to 70h on a typical computer. Sorry.')
|
141 |
-
s3 = S3FileSystem(anon=True, use_ssl=False, default_block_size=int(15 * 2**20))
|
142 |
-
with s3.open(source_url, "rb") as raw_filw:
|
143 |
-
with ZipFile(raw_filw, compression=zipfile.ZIP_DEFLATED, allowZip64=True) as zip_file:
|
144 |
-
member_list = zip_file.namelist()
|
145 |
-
for member in tqdm(member_list, total=len(member_list), desc="Extracting ecoset to disc"):
|
146 |
-
zip_file.extract(member, target_dir, pwd=password.encode("ascii"))
|
147 |
|
148 |
|
149 |
def subprocess_download(source_url, target_dir):
|
@@ -153,18 +140,27 @@ class Ecoset(datasets.GeneratorBasedBuilder):
|
|
153 |
check_pass(password)
|
154 |
# download
|
155 |
print('Using native OS unzipping. This will take about 15h on a typical Linux/Mac and 8h on a typical Windows Computer.')
|
156 |
-
|
157 |
-
|
158 |
-
if not op.exists(target_dir):
|
159 |
os.makedirs(target_dir)
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
# unzip using platform-based subprocess
|
169 |
if platform.system() in ("Linux", "Darwin"):
|
170 |
#subprocess.call(["unzip", "-n", "-P", password.encode("ascii"), "-o", zip_path, "-d", target_dir], shell=False)
|
@@ -174,31 +170,10 @@ class Ecoset(datasets.GeneratorBasedBuilder):
|
|
174 |
subprocess_call_print(["tar.exe", "-xf", zip_path, "-C", target_dir, "--passphrase", password])
|
175 |
|
176 |
|
177 |
-
|
178 |
-
"""Moderately slow download"""
|
179 |
-
# ask password
|
180 |
-
password = getpass(_PWD_MSG)
|
181 |
-
check_pass(password)
|
182 |
-
# download
|
183 |
-
print('Using native OS unzipping. This will take about 15h on a typical Linux/Mac and 8h on a typical Windows Computer.')
|
184 |
-
urlinfo = urlparse(source_url, allow_fragments=False)
|
185 |
-
# create destination path if not existing
|
186 |
-
if not op.exists(target_dir):
|
187 |
-
os.makedirs(target_dir)
|
188 |
-
# download zip file if not existing
|
189 |
-
zip_path = op.join(target_dir, "ecoset.zip")
|
190 |
-
if not op.exists(zip_path):
|
191 |
-
s3 = boto3.client(urlinfo.scheme, config=Config(signature_version=UNSIGNED))
|
192 |
-
s3.download_file(urlinfo.netloc, urlinfo.path[1:], zip_path)
|
193 |
-
# unzip using platform-based subprocess
|
194 |
-
if platform.system() in ("Linux", "Darwin"):
|
195 |
-
subprocess.call(["unzip", "-n", "-P", password.encode("ascii"), "-o", zip_path, "-d", target_dir], shell=False)
|
196 |
-
else:
|
197 |
-
subprocess.call(["tar.exe", "-xf", zip_path, "-C", target_dir, "--passphrase", password], shell=False)
|
198 |
-
|
199 |
|
200 |
# download and unzip using subprocess. S3 download was discontinued due to being extremely slow
|
201 |
-
archives = dl_manager.download_custom(_URLS["
|
202 |
print("Ecoset files are stored under: \n", archives)
|
203 |
|
204 |
# create a dict containing all files
|
|
|
51 |
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
52 |
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
53 |
_URLS = {
|
54 |
+
"ikw": "https://files.ikw.uni-osnabrueck.de/ml/ecoset/ecoset.zip",
|
|
|
55 |
}
|
56 |
|
57 |
# Define the labels available for ecoset
|
|
|
130 |
print(line.strip())
|
131 |
sys.stdout.flush()
|
132 |
|
133 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
|
136 |
def subprocess_download(source_url, target_dir):
|
|
|
140 |
check_pass(password)
|
141 |
# download
|
142 |
print('Using native OS unzipping. This will take about 15h on a typical Linux/Mac and 8h on a typical Windows Computer.')
|
143 |
+
# Ensure the target directory exists, or create it if it doesn't.
|
144 |
+
if not os.path.exists(target_dir):
|
|
|
145 |
os.makedirs(target_dir)
|
146 |
+
|
147 |
+
# Extract the filename from the URL.
|
148 |
+
filename = source_url.split("/")[-1]
|
149 |
+
|
150 |
+
# Combine the target directory and the filename to get the full path.
|
151 |
+
zip_file_path = os.path.join(target_dir, filename)
|
152 |
+
|
153 |
+
# Use subprocess to execute the modified wget command.
|
154 |
+
wget_command = f"wget --no-check-certificate {source_url} -O {zip_file_path}"
|
155 |
+
subprocess.run(wget_command, shell=True)
|
156 |
+
|
157 |
+
# Download the zip file.
|
158 |
+
response = requests.get(source_url, stream=True)
|
159 |
+
if response.status_code == 200:
|
160 |
+
with open(zip_file_path, 'wb') as file:
|
161 |
+
for chunk in response.iter_content(1024):
|
162 |
+
file.write(chunk)
|
163 |
+
print(f"Downloaded {filename}")
|
164 |
# unzip using platform-based subprocess
|
165 |
if platform.system() in ("Linux", "Darwin"):
|
166 |
#subprocess.call(["unzip", "-n", "-P", password.encode("ascii"), "-o", zip_path, "-d", target_dir], shell=False)
|
|
|
170 |
subprocess_call_print(["tar.exe", "-xf", zip_path, "-C", target_dir, "--passphrase", password])
|
171 |
|
172 |
|
173 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
|
175 |
# download and unzip using subprocess. S3 download was discontinued due to being extremely slow
|
176 |
+
archives = dl_manager.download_custom(_URLS["ikw"], subprocess_download)
|
177 |
print("Ecoset files are stored under: \n", archives)
|
178 |
|
179 |
# create a dict containing all files
|