Download model/main.py from ajvelasque/Transformer: direct link, hf CLI and curl.
- Browser
- Download file 1.92 kB
-
https://huggingface.co/ajvelasque/Transformer/resolve/main/model/main.py
- Command line
-
hf download hf://ajvelasque/Transformer/model/main.py
-
curl -L -o main.py https://huggingface.co/ajvelasque/Transformer/resolve/main/model/main.py
1.92 kB
| from __future__ import annotations | |
| import os | |
| import sys | |
| from typing import Any, Dict | |
| import pandas as pd | |
| sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) | |
| from base_main import run_pipeline # noqa: E402 | |
| from dataset import TrainingDataset, tokenize_smiles # noqa: E402 | |
| from model import create_model # noqa: E402 | |
| def smiles_predict_input_loader( | |
| predict_dir: str, | |
| predict_cfg: Dict[str, Any], | |
| metadata: Dict[str, Any], | |
| ) -> Dict[str, Any]: | |
| """Carrega CSV/XLSX no modo predict e tokeniza a coluna de SMILES.""" | |
| input_file = predict_cfg.get("input_file") | |
| if not input_file: | |
| raise ValueError("Campo 'input_file' ausente no predict_config.json") | |
| input_path = os.path.join(predict_dir, input_file) | |
| if not os.path.isfile(input_path): | |
| raise FileNotFoundError(f"Arquivo de entrada não encontrado: {input_path}") | |
| ext = os.path.splitext(input_file)[-1].lower() | |
| df_input = ( | |
| pd.read_excel(input_path) if ext in (".xlsx", ".xls") else pd.read_csv(input_path) | |
| ) | |
| feature_cols = metadata.get("features") or [] | |
| smiles_col = feature_cols[0] if feature_cols else next( | |
| (c for c in df_input.columns if "smiles" in c.lower()), None | |
| ) | |
| if not smiles_col or smiles_col not in df_input.columns: | |
| raise ValueError("Coluna SMILES não encontrada no arquivo de predição.") | |
| max_len = 120 | |
| X_tokens = tokenize_smiles(df_input[smiles_col].astype(str).tolist(), max_len=max_len) | |
| return { | |
| "X": X_tokens, | |
| "input_size": max_len, | |
| "df_input": df_input, | |
| "input_file": input_file, | |
| } | |
| if __name__ == "__main__": | |
| sys.exit( | |
| run_pipeline( | |
| dataset_cls=TrainingDataset, | |
| model_factory=create_model, | |
| predict_input_loader=smiles_predict_input_loader, | |
| ) | |
| ) |