Spaces:
Sleeping
Sleeping
Download data_loader.py from KRISHDEV99/OpenenvScaler: direct link, hf CLI and curl.
- Browser
- Download file 2.19 kB
-
https://huggingface.co/spaces/KRISHDEV99/OpenenvScaler/resolve/main/data_loader.py
- Command line
-
hf download hf://spaces/KRISHDEV99/OpenenvScaler/data_loader.py
-
curl -L -o data_loader.py https://huggingface.co/spaces/KRISHDEV99/OpenenvScaler/resolve/main/data_loader.py
2.19 kB
| from __future__ import annotations | |
| from pathlib import Path | |
| from typing import Dict | |
| import pandas as pd | |
| DIFFICULTIES = ("easy", "medium", "hard") | |
| DESCRIPTION_COLUMNS = ("Description", "Ticket Description") | |
| REQUIRED_COLUMNS = { | |
| "TicketID", | |
| "expected_category", | |
| "expected_action", | |
| "expected_response", | |
| "requires_escalation", | |
| "knowledge_base_id", | |
| "difficulty", | |
| } | |
| def load_dataset(csv_path: str | Path = "dataset.csv") -> pd.DataFrame: | |
| path = Path(csv_path) | |
| if not path.exists() and not path.is_absolute(): | |
| candidate = Path(__file__).resolve().parent / path | |
| if candidate.exists(): | |
| path = candidate | |
| if not path.exists(): | |
| raise FileNotFoundError(f"Dataset not found at {path}") | |
| df = pd.read_csv(path) | |
| desc_col = next((c for c in DESCRIPTION_COLUMNS if c in df.columns), None) | |
| missing = sorted(REQUIRED_COLUMNS - set(df.columns)) | |
| if desc_col is None: | |
| missing.append("Description or Ticket Description") | |
| if missing: | |
| raise ValueError(f"Missing required dataset columns: {', '.join(missing)}") | |
| df = df.copy() | |
| if desc_col != "Description": | |
| df["Description"] = df[desc_col] | |
| df["difficulty"] = df["difficulty"].astype(str).str.lower().str.strip() | |
| df["requires_escalation"] = ( | |
| df["requires_escalation"].astype(str).str.lower().map({"true": True, "false": False}).fillna(False) | |
| ) | |
| df["TicketID"] = df["TicketID"].astype(int) | |
| return df | |
| def split_difficulty(df: pd.DataFrame) -> Dict[str, pd.DataFrame]: | |
| return {d: df[df["difficulty"] == d].reset_index(drop=True).copy() for d in DIFFICULTIES} | |
| def build_expected(row: pd.Series) -> dict: | |
| return { | |
| "ticket_id": int(row["TicketID"]), | |
| "query": str(row["Description"]), | |
| "expected_category": str(row["expected_category"]), | |
| "expected_action": str(row["expected_action"]), | |
| "expected_response": str(row["expected_response"]), | |
| "requires_escalation": bool(row["requires_escalation"]), | |
| "kb_id": str(row["knowledge_base_id"]), | |
| "difficulty": str(row["difficulty"]), | |
| } |