File size: 1,321 Bytes
ebef316
 
 
 
 
 
 
 
 
 
f7f4846
 
 
 
 
 
 
ebef316
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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))