Download smoke_decoder.py from maxffarrell/amos-1-small-CoreAI: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/maxffarrell/amos-1-small-CoreAI/resolve/main/smoke_decoder.py
- Command line
-
hf download hf://maxffarrell/amos-1-small-CoreAI/smoke_decoder.py
-
curl -L -o smoke_decoder.py https://huggingface.co/maxffarrell/amos-1-small-CoreAI/resolve/main/smoke_decoder.py
1.32 kB
| import argparse,asyncio,json | |
| from pathlib import Path | |
| import torch | |
| from coreai_decoder import AmosDecoder | |
| async def main(name): | |
| def forbidden(*a,**kw):raise AssertionError('PyTorch neural execution forbidden') | |
| torch.nn.Linear.forward=forbidden;torch.nn.Embedding.forward=forbidden;torch.nn.Conv2d.forward=forbidden;torch.nn.Conv3d.forward=forbidden | |
| root=Path('bundles')/(name+'-CoreAI');m=await AmosDecoder.load(root) | |
| out=await m.request({'state':'Please refund the duplicate charge.','questions':{'refund':{'type':'noul','instructions':'Is a refund requested?'}}}) | |
| assert out['answers']['refund']['noul']>0.5,out | |
| from PIL import Image | |
| image_result=await m.predict('A red image.',[{'type':'region','text':'Point to the red area.'}],[Image.new('RGB',(360,240),'red')]) | |
| assert image_result[0]['type']=='region' | |
| try:await m.predict('word '*1000,[{'type':'noul','text':'Is there text?'}]) | |
| except ValueError:capacity_guard=True | |
| else:raise AssertionError('Over-capacity request was accepted') | |
| (root/'runtime-smoke.json').write_text(json.dumps({'passed':True,'pytorch_neural_execution_disabled':True,'capacity_guard':capacity_guard,'result':out,'image_result':image_result},indent=2));print(out) | |
| if __name__=='__main__': | |
| p=argparse.ArgumentParser();p.add_argument('name');a=p.parse_args();asyncio.run(main(a.name)) | |