okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
db4dd65e5
main
1"""vq.py PORT IMG [IMG2] : the picture questions through the server (chat completions, image_url data URL), greedy, 2thinking off. Prints each answer and the usage.""" 3import base64 ,json ,sys ,time ,urllib .request 4port ,img = sys .argv [1 ],sys .argv [2 ] 5QS = {"code4217.png" : ["What text is written in the image? Answer with the text only." , 6"Describe the shapes in the image with their colours and positions, one short line each." ], 7"shapes.png" : ["What text is written in the image? Answer with the text only." , 8"List every shape in the image with its colour, from left to right. One short line each." ]} 9name = img .rsplit ("/" ,1 )[- 1 ] 10b64 = base64 .b64encode (open (img ,"rb" ).read ()).decode () 11for q in QS .get (name , ["Describe this image." ]): 12body = {"model" :"x" ,"max_tokens" :120 ,"temperature" :0 ,"chat_template_kwargs" : {"enable_thinking" :False }, 13"messages" : [{"role" :"user" ,"content" : [{"type" :"image_url" ,"image_url" : {"url" :"data:image/png;base64," + b64 }}, 14 {"type" :"text" ,"text" :q }]}]} 15t0 = time .time () 16r = json .loads (urllib .request .urlopen (urllib .request .Request (f"http://127.0.0.1: { port } /v1/chat/completions" , 17json .dumps (body ).encode (), {"Content-Type" :"application/json" }),timeout = 900 ).read ()) 18"Q:" ,q ) 19"A:" ,repr (r ["choices" ][0 ]["message" ]["content" ]),"%.1fs" % (time .time ()- t0 )) 20"usage" ,r .get ("usage" ),flush = True )