File size: 1,838 Bytes
6d5d7e5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | """Pinned source-derived numerical inference. Research fixtures only."""
from pathlib import Path
import json,sys,argparse
ROOT=Path(__file__).resolve().parent
sys.path.insert(0,str(ROOT))
from humanization_research.parameters import ParameterPack,ContractError
from humanization_research.predictors import NCLPredictor,MRIPredictor,RhythmPredictor
PIN='f687e0fdcf1f807988d275102cbe2c8c21e923e959ef2ec8356f90c189b89e7b'
PRODUCT='rhythm'
def run(request):
if type(request)!=dict or request.get('synthetic') is not True:raise ContractError('Synthetic research-use declaration required; patient execution is disabled')
p=ParameterPack(ROOT/'parameters',PIN)
f=request.get('features')
if PRODUCT=='ncl':return NCLPredictor(p).run(f,synthetic=True)
if PRODUCT=='mri':return MRIPredictor(p).run(f,space=request.get('space','huret'),variant=request.get('variant','optimized'),synthetic=True)
return RhythmPredictor(p).run(f,synthetic=True,acknowledge_export_version_mismatch=request.get('acknowledge_export_version_mismatch') is True)
def main():
ap=argparse.ArgumentParser();ap.add_argument('--request',type=Path,default=ROOT/'example.json');a=ap.parse_args()
if a.request.stat().st_size>1000000:raise ValueError('Request too large')
def pairs(items):
out={}
for k,v in items:
if k in out:raise ValueError('Duplicate JSON key')
out[k]=v
return out
request=json.loads(a.request.read_text(),object_pairs_hook=pairs,parse_constant=lambda _:(_ for _ in ()).throw(ValueError('Nonfinite JSON')))
print(json.dumps(run(request),ensure_ascii=False,indent=2,allow_nan=False))
if __name__=='__main__':
try:main()
except (OSError,ValueError,TypeError,KeyError) as e:print(json.dumps({'status':'ERROR','reason':str(e)}),file=sys.stderr);raise SystemExit(2)
|