Download proxima.py from AtlasAI-org/Proxima: direct link, hf CLI and curl.
- Browser
- Download file 2.2 kB
-
https://huggingface.co/AtlasAI-org/Proxima/resolve/main/proxima.py
- Command line
-
hf download hf://AtlasAI-org/Proxima/proxima.py
-
curl -L -o proxima.py https://huggingface.co/AtlasAI-org/Proxima/resolve/main/proxima.py
2.2 kB
| """Portable CPU inference from Proxima's structured UTC schedule inputs.""" | |
| import json | |
| from pathlib import Path | |
| from datetime import datetime | |
| import lightgbm as lgb | |
| import pandas as pd | |
| from safetensors import safe_open | |
| from data import features | |
| class Proxima: | |
| def __init__(self,directory=None): | |
| self.directory=Path(directory) if directory else Path(__file__).parent | |
| self.config=json.loads((self.directory/'config.json').read_text(encoding='utf-8')) | |
| with safe_open(str(self.directory/'model.safetensors'),framework='numpy') as sf: | |
| self.models={t:lgb.Booster(model_str=sf.get_tensor(t+'_lightgbm_utf8').tobytes().decode('utf-8')) for t in ['arr','dep']} | |
| def predict_rows(self,rows): | |
| rows=rows.copy() | |
| for c in ['sd','sa']: | |
| values=[pd.Timestamp(v) for v in rows[c]] | |
| if any(v.tzinfo is None for v in values):raise ValueError('Schedules require timezone-aware timestamps') | |
| rows[c]=pd.to_datetime(rows[c],utc=True) | |
| duration=(rows.sa-rows.sd).dt.total_seconds()/60 | |
| if not duration.between(15,1440).all():raise ValueError('Schedule durations must be 15–1440 minutes') | |
| for c in ['origin','destination']: | |
| if not rows[c].isin(self.config['airports']).all():raise ValueError('Airport outside released metadata coverage') | |
| if not rows.airline.astype(str).str.fullmatch('[A-Z0-9]{3}').all():raise ValueError('Use three-character airline ICAO codes') | |
| X,_=features(rows,self.config) | |
| return {t:self.models[t].predict(X,num_threads=1) for t in ['arr','dep']} | |
| if __name__=='__main__': | |
| import argparse | |
| parser=argparse.ArgumentParser(description='Proxima research flight-delay estimates; input and output CSV') | |
| parser.add_argument('input',help='CSV columns airline,number,origin,destination,sd,sa; ICAO codes and offset-aware timestamps') | |
| parser.add_argument('output') | |
| args=parser.parse_args() | |
| rows=pd.read_csv(args.input) | |
| pred=Proxima().predict_rows(rows) | |
| rows['arrival_delay_minutes']=pred['arr'];rows['departure_delay_minutes']=pred['dep'] | |
| rows.to_csv(args.output,index=False) | |