Download smoke_mini.py from maxffarrell/amos-1-mini-CoreAI: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/maxffarrell/amos-1-mini-CoreAI/resolve/main/smoke_mini.py
- Command line
-
hf download hf://maxffarrell/amos-1-mini-CoreAI/smoke_mini.py
-
curl -L -o smoke_mini.py https://huggingface.co/maxffarrell/amos-1-mini-CoreAI/resolve/main/smoke_mini.py
1.21 kB
| import asyncio,json | |
| from pathlib import Path | |
| import torch | |
| from coreai_mini import AmosMini | |
| async def main(): | |
| def forbidden(*a,**kw):raise AssertionError('PyTorch neural execution is forbidden in runtime smoke') | |
| torch.nn.Linear.forward=forbidden;torch.nn.Embedding.forward=forbidden;torch.nn.Conv2d.forward=forbidden | |
| root=Path('bundles/amos-1-mini-CoreAI');m=await AmosMini.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__':asyncio.run(main()) | |