Spaces:
Sleeping
Sleeping
PERDYPTO commited on
Update pipeline.py
Browse files- pipeline.py +25 -19
pipeline.py
CHANGED
|
@@ -19,7 +19,7 @@ from pathlib import Path
|
|
| 19 |
from queue import Empty
|
| 20 |
|
| 21 |
import orjson
|
| 22 |
-
from datasets import load_dataset
|
| 23 |
from huggingface_hub import batch_bucket_files
|
| 24 |
from fastapi import FastAPI
|
| 25 |
from fastapi.responses import JSONResponse
|
|
@@ -58,7 +58,7 @@ REMOTE_STATE = f"{REMOTE_ROOT}/state"
|
|
| 58 |
REMOTE_FINAL = f"{REMOTE_ROOT}/final"
|
| 59 |
|
| 60 |
# ----------------------------------------------------------------------
|
| 61 |
-
# DATASETS
|
| 62 |
# ----------------------------------------------------------------------
|
| 63 |
DATASETS = [
|
| 64 |
{
|
|
@@ -300,7 +300,7 @@ def extract_record(row, cfg):
|
|
| 300 |
}
|
| 301 |
|
| 302 |
# ----------------------------------------------------------------------
|
| 303 |
-
# AST VALIDATOR
|
| 304 |
# ----------------------------------------------------------------------
|
| 305 |
AST_CHILD_CODE = r'''
|
| 306 |
import ast
|
|
@@ -403,7 +403,7 @@ def get_interpreters():
|
|
| 403 |
return interpreters
|
| 404 |
|
| 405 |
# ----------------------------------------------------------------------
|
| 406 |
-
# DATASET LOADER
|
| 407 |
# ----------------------------------------------------------------------
|
| 408 |
def load_stream(cfg):
|
| 409 |
kwargs = {"split": cfg["split"], "streaming": True, "token": HF_TOKEN}
|
|
@@ -414,22 +414,28 @@ def load_stream(cfg):
|
|
| 414 |
if cfg.get("languages"):
|
| 415 |
kwargs["languages"] = cfg["languages"]
|
| 416 |
|
| 417 |
-
#
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 430 |
|
| 431 |
# ----------------------------------------------------------------------
|
| 432 |
-
# WORKER FUNCTION
|
| 433 |
# ----------------------------------------------------------------------
|
| 434 |
def worker_task(cfg, task_id, total_tasks, interpreters, result_queue):
|
| 435 |
dataset_name = cfg["name"]
|
|
@@ -538,7 +544,7 @@ def worker_task(cfg, task_id, total_tasks, interpreters, result_queue):
|
|
| 538 |
local_conn.close()
|
| 539 |
|
| 540 |
# ----------------------------------------------------------------------
|
| 541 |
-
# COORDINATOR
|
| 542 |
# ----------------------------------------------------------------------
|
| 543 |
class Coordinator:
|
| 544 |
def __init__(self):
|
|
|
|
| 19 |
from queue import Empty
|
| 20 |
|
| 21 |
import orjson
|
| 22 |
+
from datasets import load_dataset
|
| 23 |
from huggingface_hub import batch_bucket_files
|
| 24 |
from fastapi import FastAPI
|
| 25 |
from fastapi.responses import JSONResponse
|
|
|
|
| 58 |
REMOTE_FINAL = f"{REMOTE_ROOT}/final"
|
| 59 |
|
| 60 |
# ----------------------------------------------------------------------
|
| 61 |
+
# DATASETS
|
| 62 |
# ----------------------------------------------------------------------
|
| 63 |
DATASETS = [
|
| 64 |
{
|
|
|
|
| 300 |
}
|
| 301 |
|
| 302 |
# ----------------------------------------------------------------------
|
| 303 |
+
# AST VALIDATOR
|
| 304 |
# ----------------------------------------------------------------------
|
| 305 |
AST_CHILD_CODE = r'''
|
| 306 |
import ast
|
|
|
|
| 403 |
return interpreters
|
| 404 |
|
| 405 |
# ----------------------------------------------------------------------
|
| 406 |
+
# DATASET LOADER — FIXED: use select_columns instead of features
|
| 407 |
# ----------------------------------------------------------------------
|
| 408 |
def load_stream(cfg):
|
| 409 |
kwargs = {"split": cfg["split"], "streaming": True, "token": HF_TOKEN}
|
|
|
|
| 414 |
if cfg.get("languages"):
|
| 415 |
kwargs["languages"] = cfg["languages"]
|
| 416 |
|
| 417 |
+
# Load the dataset
|
| 418 |
+
ds = load_dataset(cfg["dataset"], **kwargs)
|
| 419 |
+
|
| 420 |
+
# Only select columns we actually need (avoids the cast error)
|
| 421 |
+
# The dataset has many columns; we only need these few
|
| 422 |
+
needed_columns = ["text", "repo_name", "path", "license"]
|
| 423 |
+
|
| 424 |
+
# Some datasets might use different column names, so check what exists
|
| 425 |
+
existing_cols = [col for col in needed_columns if col in ds.column_names]
|
| 426 |
+
|
| 427 |
+
if existing_cols:
|
| 428 |
+
try:
|
| 429 |
+
ds = ds.select_columns(existing_cols)
|
| 430 |
+
print(f"[LOAD] {cfg['name']}: selected columns: {existing_cols}")
|
| 431 |
+
except Exception as e:
|
| 432 |
+
# If select_columns fails (e.g., in streaming mode), fall back to keeping all columns
|
| 433 |
+
print(f"[LOAD] {cfg['name']}: select_columns failed ({e}), keeping all columns")
|
| 434 |
+
|
| 435 |
+
return ds
|
| 436 |
|
| 437 |
# ----------------------------------------------------------------------
|
| 438 |
+
# WORKER FUNCTION
|
| 439 |
# ----------------------------------------------------------------------
|
| 440 |
def worker_task(cfg, task_id, total_tasks, interpreters, result_queue):
|
| 441 |
dataset_name = cfg["name"]
|
|
|
|
| 544 |
local_conn.close()
|
| 545 |
|
| 546 |
# ----------------------------------------------------------------------
|
| 547 |
+
# COORDINATOR
|
| 548 |
# ----------------------------------------------------------------------
|
| 549 |
class Coordinator:
|
| 550 |
def __init__(self):
|