add ramdisk, load AI model to ramdisk and start recognition from it

rewrite zmq to DEALER and ROUTER
add GET_USER command to get CurrentUser from Python
all auth is on the python side
inference run and validate annotations on python
This commit is contained in:
Alex Bezdieniezhnykh
2025-01-29 17:45:26 +02:00
parent 82b3b526a7
commit 62623b7123
55 changed files with 945 additions and 895 deletions
+16 -13
View File
@@ -1,12 +1,13 @@
import traceback
from queue import Queue
cimport constants
import msgpack
from api_client cimport ApiClient
from annotation cimport Annotation
from inference import Inference
from inference cimport Inference
from remote_command cimport RemoteCommand, CommandType
from remote_command_handler cimport RemoteCommandHandler
from user cimport User
import argparse
cdef class ParsedArguments:
@@ -36,11 +37,10 @@ cdef class CommandProcessor:
while self.running:
try:
command = self.command_queue.get()
print(f'command is : {command}')
model = self.api_client.load_ai_model()
Inference(model, self.on_annotations).run_inference(command)
Inference(model, self.on_annotation).run_inference(command)
except Exception as e:
print(f"Error processing queue: {e}")
traceback.print_exc()
cdef on_command(self, RemoteCommand command):
try:
@@ -48,17 +48,20 @@ cdef class CommandProcessor:
self.command_queue.put(command)
elif command.command_type == CommandType.LOAD:
response = self.api_client.load_bytes(command.filename)
print(f'loaded file: {command.filename}, {len(response)} bytes')
self.remote_handler.send(response)
print(f'{len(response)} bytes was sent.')
self.remote_handler.send(command.client_id, response)
elif command.command_type == CommandType.GET_USER:
self.get_user(command, self.api_client.get_user())
else:
pass
except Exception as e:
print(f"Error handling client: {e}")
cdef on_annotations(self, RemoteCommand cmd, annotations: [Annotation]):
data = msgpack.packb(annotations)
self.remote_handler.send(data)
print(f'{len(data)} bytes was sent.')
cdef get_user(self, RemoteCommand command, User user):
self.remote_handler.send(command.client_id, user.serialize())
cdef on_annotation(self, RemoteCommand cmd, Annotation annotation):
data = annotation.serialize()
self.remote_handler.send(cmd.client_id, data)
def stop(self):
self.running = False