import allspark class MyProcessor(allspark.BaseProcessor): """ MyProcessor is a example you can send mesage like this to predict curl -v http://127.0.0.1:8080/api/predict/service_name -d '2 105' """ def initialize(self): """ load module, executed once at the start of the service do service intialization and load models in this function. """ self.module = {'w0': 100, 'w1': 2} def pre_proccess(self, data): """ data format pre process """ x, y = data.split(b' ') return int(x), int(y) def post_process(self, data): """ proccess after process """ return bytes(data, encoding='utf8') def process(self, data): """ process the request data """ x, y = self.pre_proccess(data) w0 = self.module['w0'] w1 = self.module['w1'] y1 = w1 * x + w0 if y1 >= y: return self.post_process("True"), 200 else: return self.post_process("False"), 400 if __name__ == '__main__': # paramter worker_threads indicates concurrency of processing runner = MyProcessor(worker_threads=10) runner.run()