Skip to content

Commit

Permalink
Fix downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
erikbern committed Dec 23, 2024
1 parent 266b14f commit cc7cd1e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ann_benchmarks/datasets.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import os
import random
import tarfile
from urllib.request import urlopen, urlretrieve
from urllib.request import build_opener, install_opener, urlopen, urlretrieve
import traceback

import h5py
import numpy
from typing import Any, Callable, Dict, Tuple

# Needed for Cloudflare's firewall
opener = build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
install_opener(opener)


def download(source_url: str, destination_path: str) -> None:
"""
Downloads a file from the provided source URL to the specified destination path
Expand Down Expand Up @@ -54,6 +61,7 @@ def get_dataset(dataset_name: str) -> Tuple[h5py.File, int]:
dataset_url = f"https://ann-benchmarks.com/{dataset_name}.hdf5"
download(dataset_url, hdf5_filename)
except:
traceback.print_exc()
print(f"Cannot download {dataset_url}")
if dataset_name in DATASETS:
print("Creating dataset locally")
Expand Down

0 comments on commit cc7cd1e

Please sign in to comment.