from huggingface_hub import hf_hub_download import pandas as pd def _load_label_mapping(): csv_path = hf_hub_download(repo_id="bob-nlp/A5-CNO-BOB-ISTAC-D12", filename="data/idxs.csv") df = pd.read_csv(csv_path) _label_mapping = dict(zip(df['label'], df['CNO'])) return _label_mapping def _load_description_mapping(): csv_path = hf_hub_download(repo_id="bob-nlp/A5-CNO-BOB-ISTAC-D12", filename="data/cno11_notas.csv") df = pd.read_csv(csv_path) _description_mapping = dict(zip(df['CNO'], df['DN4'])) return _description_mapping def convert_to_cno(output_label): """ Converts a model label (e.g., 'LABEL_0') to the CNO format (e.g., 'C1111'). Parameters: output_label (str): Label from the model (like 'LABEL_0') model_id (str): The Hugging Face model ID Returns: str: Converted label, or original if not found. """ mapping = _load_label_mapping() return mapping.get(output_label, output_label) def get_cno_description(cno): """ Retrieves the description for a given CNO code. Parameters: cno (str): The CNO code (e.g., 'C1111') Returns: str: Description of the CNO code, or 'Unknown' if not found. """ mapping = _load_description_mapping() return mapping.get(cno, 'Unknown')