No zip
This commit is contained in:
parent
9b166969e2
commit
369b3a4bf7
2 changed files with 12 additions and 28 deletions
|
|
@ -32,7 +32,7 @@ Available datasets:
|
||||||
|
|
||||||
| Dataset | Size |
|
| Dataset | Size |
|
||||||
|---------|------|
|
|---------|------|
|
||||||
| `repliqa` | ~18MB |
|
| `repliqa` | ~30MB |
|
||||||
| `hotpotqa` | ~331MB |
|
| `hotpotqa` | ~331MB |
|
||||||
| `wix` | ~511MB |
|
| `wix` | ~511MB |
|
||||||
| `open_rag_bench` | ~14GB |
|
| `open_rag_bench` | ~14GB |
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
|
||||||
import zipfile
|
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
|
|
@ -9,7 +7,7 @@ from typing import Any, cast
|
||||||
import logfire
|
import logfire
|
||||||
import typer
|
import typer
|
||||||
from dotenv import find_dotenv, load_dotenv
|
from dotenv import find_dotenv, load_dotenv
|
||||||
from huggingface_hub import HfApi, hf_hub_download
|
from huggingface_hub import HfApi, snapshot_download
|
||||||
from pydantic_evals import Case, Dataset as EvalDataset
|
from pydantic_evals import Case, Dataset as EvalDataset
|
||||||
from pydantic_evals.evaluators import LLMJudge
|
from pydantic_evals.evaluators import LLMJudge
|
||||||
from pydantic_evals.reporting import ReportCaseFailure
|
from pydantic_evals.reporting import ReportCaseFailure
|
||||||
|
|
@ -482,13 +480,12 @@ def download(
|
||||||
continue
|
continue
|
||||||
|
|
||||||
console.print(f"[blue]Downloading {spec.key}...[/blue]")
|
console.print(f"[blue]Downloading {spec.key}...[/blue]")
|
||||||
zip_filename = f"{spec.db_filename}.zip"
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
zip_path = hf_hub_download(
|
downloaded_path = snapshot_download(
|
||||||
repo_id=HF_REPO_ID,
|
repo_id=HF_REPO_ID,
|
||||||
filename=zip_filename,
|
|
||||||
repo_type="dataset",
|
repo_type="dataset",
|
||||||
|
allow_patterns=f"{spec.db_filename}/*",
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
console.print(f"[red]Failed to download {spec.key}: {e}[/red]")
|
console.print(f"[red]Failed to download {spec.key}: {e}[/red]")
|
||||||
|
|
@ -498,10 +495,9 @@ def download(
|
||||||
if db.exists():
|
if db.exists():
|
||||||
shutil.rmtree(db)
|
shutil.rmtree(db)
|
||||||
|
|
||||||
# Extract to the parent directory
|
# Copy from cache to target location
|
||||||
db.parent.mkdir(parents=True, exist_ok=True)
|
db.parent.mkdir(parents=True, exist_ok=True)
|
||||||
with zipfile.ZipFile(zip_path, "r") as zf:
|
shutil.copytree(Path(downloaded_path) / spec.db_filename, db)
|
||||||
zf.extractall(db.parent)
|
|
||||||
|
|
||||||
console.print(f"[green]Downloaded {spec.key} to {db}[/green]")
|
console.print(f"[green]Downloaded {spec.key} to {db}[/green]")
|
||||||
|
|
||||||
|
|
@ -531,24 +527,12 @@ def upload(
|
||||||
continue
|
continue
|
||||||
|
|
||||||
console.print(f"[blue]Uploading {spec.key}...[/blue]")
|
console.print(f"[blue]Uploading {spec.key}...[/blue]")
|
||||||
zip_filename = f"{spec.db_filename}.zip"
|
api.upload_folder(
|
||||||
|
folder_path=str(db),
|
||||||
with tempfile.TemporaryDirectory() as tmpdir:
|
path_in_repo=spec.db_filename,
|
||||||
zip_path = Path(tmpdir) / zip_filename
|
repo_id=HF_REPO_ID,
|
||||||
console.print("[dim]Creating zip archive...[/dim]")
|
repo_type="dataset",
|
||||||
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf:
|
)
|
||||||
for file in db.rglob("*"):
|
|
||||||
if file.is_file():
|
|
||||||
arcname = f"{spec.db_filename}/{file.relative_to(db)}"
|
|
||||||
zf.write(file, arcname)
|
|
||||||
|
|
||||||
console.print("[dim]Uploading to HuggingFace...[/dim]")
|
|
||||||
api.upload_file(
|
|
||||||
path_or_fileobj=str(zip_path),
|
|
||||||
path_in_repo=zip_filename,
|
|
||||||
repo_id=HF_REPO_ID,
|
|
||||||
repo_type="dataset",
|
|
||||||
)
|
|
||||||
|
|
||||||
console.print(f"[green]Uploaded {spec.key} to {HF_REPO_ID}[/green]")
|
console.print(f"[green]Uploaded {spec.key} to {HF_REPO_ID}[/green]")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue