def main(self): self.timeOut = 10 # milliseconds service = Service(CONFIG.mode, CONFIG.port, CONFIG.password, True) while True: rc = win32event.WaitForSingleObject(self.hWaitStop, self.timeOut) if rc == win32event.WAIT_OBJECT_0: servicemanager.LogInfoMsg("ButrManager - STOPPED") break else: servicemanager.LogInfoMsg("ButrManager - RUNNING") service.run_once()
def inference(request, body, response): """Makes an inference to a certain model""" print(body) if (request.headers.get('CONTENT-TYPE') == 'application/gzip'): try: original_data = gzip.decompress(request.stream.read()) input_docs = json.loads(str(original_data, 'utf-8'))["docs"] model_name = json.loads(str(original_data, 'utf-8'))["model_name"] except Exception: response.status = hug.HTTP_500 return {'status': 'unexpected gzip error'} elif (request.headers.get('CONTENT-TYPE') == 'application/json'): if (isinstance(body, str)): body = json.loads(body) model_name = body.get('model_name') input_docs = body.get('docs') else: response.status = status_codes.HTTP_400 return { 'status': 'Content-Type header must be application/json or application/gzip' } if (not model_name): response.status = status_codes.HTTP_400 return {'status': 'model_name is required'} # If we've already initialized it, no use in reinitializing if not services.get(model_name): services[model_name] = Service(model_name) if not isinstance(input_docs, list): # check if it's an array instead response.status = status_codes.HTTP_400 return {'status': 'request not in proper format '} headers = parse_headers(request.headers) parsed_doc = services[model_name].get_service_inference( input_docs, headers) resp_format = request.headers["RESPONSE-FORMAT"] ret = format_response(resp_format, parsed_doc) if (request.headers.get('CONTENT-TYPE') == 'application/gzip'): response.content_type = resp_format response.body = ret # no return due to the fact that hug seems to assume json type upon return else: return ret
import logging from server.config import CONFIG from server.service import Service logger = logging.getLogger('butrserver') if __name__ == '__main__': logger.info('Initializing service instance') instance = Service(CONFIG.mode, CONFIG.port, CONFIG.password) logger.info('Starting service') instance.run_forever()
def get_paragraphs(): if (not services['machine_comprehension']): services['machine_comprehension'] = Service('machine_comprehension') return services['machine_comprehension'].get_paragraphs()
def prefetchModels(): models = ['machine_comprehension', 'bist', 'ner', 'intent_extraction'] for model in models: services[model] = Service(model)
def prefetchModels(): models = ['bist', 'spacy_ner', 'ner'] for model in models: services[model] = Service(model)
def init(configs): from server.service import Service core.app['SERVICE'] = Service(configs)