Update hub-stats.py
Browse files- hub-stats.py +19 -18
hub-stats.py
CHANGED
|
@@ -82,7 +82,7 @@ ENDPOINT_CONFIGS = {
|
|
| 82 |
"spaces": {"limit": 1000, "params": {"full": "true"}},
|
| 83 |
"posts": {"limit": 50, "params": {"skip": 0}},
|
| 84 |
"daily_papers": {
|
| 85 |
-
"limit":
|
| 86 |
"params": {},
|
| 87 |
"base_url": "https://huggingface.co/api/daily_papers",
|
| 88 |
},
|
|
@@ -164,7 +164,7 @@ async def fetch_data_page(session, url, params=None, headers=None):
|
|
| 164 |
|
| 165 |
async def create_parquet_files(skip_upload=False):
|
| 166 |
start_time = time.time()
|
| 167 |
-
endpoints = ["
|
| 168 |
created_files = []
|
| 169 |
|
| 170 |
async with aiohttp.ClientSession() as session:
|
|
@@ -239,13 +239,16 @@ async def create_parquet_files(skip_upload=False):
|
|
| 239 |
created_files.append(output_file)
|
| 240 |
|
| 241 |
print(f"✓ {endpoint}: {len(df):,} rows -> {output_file}")
|
|
|
|
|
|
|
|
|
|
| 242 |
|
| 243 |
elapsed = time.time() - start_time
|
| 244 |
return created_files, elapsed
|
| 245 |
|
| 246 |
|
| 247 |
def recreate_from_jsonl():
|
| 248 |
-
endpoints = ["
|
| 249 |
|
| 250 |
for endpoint in endpoints:
|
| 251 |
jsonl_file = os.path.join(CACHE_DIR, f"{endpoint}_raw.jsonl")
|
|
@@ -273,21 +276,22 @@ def recreate_from_jsonl():
|
|
| 273 |
print(f"✓ {endpoint}: {len(df):,} rows -> {output_file}")
|
| 274 |
|
| 275 |
|
| 276 |
-
def upload_to_hub(
|
| 277 |
api = HfApi()
|
| 278 |
repo_id = "cfahlgren1/hub-stats"
|
| 279 |
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
|
|
|
| 291 |
|
| 292 |
|
| 293 |
def main(skip_upload=False):
|
|
@@ -304,9 +308,6 @@ def main(skip_upload=False):
|
|
| 304 |
if skip_upload:
|
| 305 |
print(f"\nRaw JSONL files saved to {CACHE_DIR}/ for recreation")
|
| 306 |
print("Use 'python app.py --recreate' to recreate parquet files from JSONL")
|
| 307 |
-
else:
|
| 308 |
-
print("\nUploading to HuggingFace...")
|
| 309 |
-
upload_to_hub(created_files)
|
| 310 |
|
| 311 |
|
| 312 |
if __name__ == "__main__":
|
|
|
|
| 82 |
"spaces": {"limit": 1000, "params": {"full": "true"}},
|
| 83 |
"posts": {"limit": 50, "params": {"skip": 0}},
|
| 84 |
"daily_papers": {
|
| 85 |
+
"limit": 50,
|
| 86 |
"params": {},
|
| 87 |
"base_url": "https://huggingface.co/api/daily_papers",
|
| 88 |
},
|
|
|
|
| 164 |
|
| 165 |
async def create_parquet_files(skip_upload=False):
|
| 166 |
start_time = time.time()
|
| 167 |
+
endpoints = ["daily_papers", "models", "spaces", "datasets", "posts"]
|
| 168 |
created_files = []
|
| 169 |
|
| 170 |
async with aiohttp.ClientSession() as session:
|
|
|
|
| 239 |
created_files.append(output_file)
|
| 240 |
|
| 241 |
print(f"✓ {endpoint}: {len(df):,} rows -> {output_file}")
|
| 242 |
+
|
| 243 |
+
if not skip_upload:
|
| 244 |
+
upload_to_hub(output_file)
|
| 245 |
|
| 246 |
elapsed = time.time() - start_time
|
| 247 |
return created_files, elapsed
|
| 248 |
|
| 249 |
|
| 250 |
def recreate_from_jsonl():
|
| 251 |
+
endpoints = ["daily_papers", "models", "spaces", "datasets", "posts"]
|
| 252 |
|
| 253 |
for endpoint in endpoints:
|
| 254 |
jsonl_file = os.path.join(CACHE_DIR, f"{endpoint}_raw.jsonl")
|
|
|
|
| 276 |
print(f"✓ {endpoint}: {len(df):,} rows -> {output_file}")
|
| 277 |
|
| 278 |
|
| 279 |
+
def upload_to_hub(file_path):
|
| 280 |
api = HfApi()
|
| 281 |
repo_id = "cfahlgren1/hub-stats"
|
| 282 |
|
| 283 |
+
try:
|
| 284 |
+
api.upload_file(
|
| 285 |
+
path_or_fileobj=file_path,
|
| 286 |
+
path_in_repo=os.path.basename(file_path),
|
| 287 |
+
repo_id=repo_id,
|
| 288 |
+
repo_type="dataset",
|
| 289 |
+
)
|
| 290 |
+
print(f"✓ Uploaded {os.path.basename(file_path)} to {repo_id}")
|
| 291 |
+
return True
|
| 292 |
+
except Exception as e:
|
| 293 |
+
print(f"✗ Failed to upload {os.path.basename(file_path)}: {e}")
|
| 294 |
+
return False
|
| 295 |
|
| 296 |
|
| 297 |
def main(skip_upload=False):
|
|
|
|
| 308 |
if skip_upload:
|
| 309 |
print(f"\nRaw JSONL files saved to {CACHE_DIR}/ for recreation")
|
| 310 |
print("Use 'python app.py --recreate' to recreate parquet files from JSONL")
|
|
|
|
|
|
|
|
|
|
| 311 |
|
| 312 |
|
| 313 |
if __name__ == "__main__":
|