How to download the dataset in one go? (getting authentication error)

#2
by himanshunitrr - opened

import os
import requests
from huggingface_hub import login
login(token = " here")

Base directory where the files will be stored

BASE_DIR = "/home/himanshu/Downloads/"

Base URL for downloading the files

BASE_URL = "https://huggingface.co/datasets/BIOMEDICA/biomedica_webdataset_24M/resolve/main"

Categories with their respective ranges

CATEGORIES = {
"commercial": (0, 1861),
"noncommercial": (0, 559),
"other": (0, 114),
}

Iterate over each category and its range

for category, (start, end) in CATEGORIES.items():
# Ensure the category directory exists
category_dir = os.path.join(BASE_DIR, category)
os.makedirs(category_dir, exist_ok=True)

# Iterate through the specified numerical range
for i in range(start, end + 1):
    file_name = f"{i:06}.tar"
    file_url = f"{BASE_URL}/{category}/{file_name}"
    print(file_url)
    dest_file = os.path.join(category_dir, file_name)

    # Print the progress
    print(f"Downloading {file_url} to {dest_file}...")

    # Perform the file download
    response = requests.get(file_url, stream=True)
    if response.status_code == 200:
        with open(dest_file, 'wb') as f:
            for chunk in response.iter_content(chunk_size=8192):
                f.write(chunk)
    else:
        print(f"Failed to download {file_url} (Status code: {response.status_code})")
    break

print("Download complete.")

Your need to confirm your account before you can post a new comment.

Sign up or log in to comment