mattdeitke
commited on
Commit
·
a45fb11
1
Parent(s):
e4e7d90
add load github metadata
Browse files- objaverse_xl/github.py +35 -0
objaverse_xl/github.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import os
|
3 |
+
import fsspec
|
4 |
+
import requests
|
5 |
+
|
6 |
+
|
7 |
+
def load_github_metadata(download_dir: str = "~/.objaverse") -> pd.DataFrame:
|
8 |
+
"""Loads the GitHub 3D object metadata as a Pandas DataFrame.
|
9 |
+
|
10 |
+
Args:
|
11 |
+
download_dir (str, optional): Directory to download the parquet metadata file.
|
12 |
+
Supports all file systems supported by fsspec. Defaults to "~/.objaverse".
|
13 |
+
|
14 |
+
Returns:
|
15 |
+
pd.DataFrame: GitHub 3D object metadata as a Pandas DataFrame with columns for
|
16 |
+
the object "githubUrl", "license", and "sha256".
|
17 |
+
"""
|
18 |
+
filename = os.path.join(download_dir, "github", "github-urls.parquet")
|
19 |
+
fs, path = fsspec.core.url_to_fs(filename)
|
20 |
+
fs.makedirs(os.path.dirname(path), exist_ok=True)
|
21 |
+
|
22 |
+
# download the parquet file if it doesn't exist
|
23 |
+
if not fs.exists(path):
|
24 |
+
url = "https://huggingface.co/datasets/allenai/objaverse-xl/resolve/main/github/github-urls.parquet"
|
25 |
+
|
26 |
+
response = requests.get(url)
|
27 |
+
response.raise_for_status()
|
28 |
+
with fs.open(path, "wb") as file:
|
29 |
+
file.write(response.content)
|
30 |
+
|
31 |
+
# load the parquet file with fsspec
|
32 |
+
with fs.open(path) as f:
|
33 |
+
df = pd.read_parquet(f)
|
34 |
+
|
35 |
+
return df
|