<commit_before>#!/usr/bin/env python3

import os
import tornado.ioloop
import tornado.web
import tornado.httpserver
import tornado.httputil
import tornado.gen
import json
import pickle
import numpy as np
from hystrix import Command
import asyncio
import fnmatch

from transformers import input_transformer, output_transformer

class PredictCommand(Command):
    inputs = [[]]
    model = None

    def run(self):
        return self.model.predict(self.inputs)

    def fallback(self):
        return 'fallback!'

class MainHandler(tornado.web.RequestHandler):
    @tornado.gen.coroutine
    def post(self, model_namespace, model_name, model_version):
        self.set_header("Content-Type", "application/json")
        command = self.build_command(model_namespace, model_name, model_version)
        output = yield self.build_future(command)
        self.write(output_transformer(output))

    def build_command(self, model_namespace, model_name, model_version):
        command = PredictCommand()
        model_key = '%s_%s_%s' % (model_namespace, model_name, model_version)

        command.name = 'Predict_%s' % model_key
        command.group_name = 'PredictGroup'
        model_key = '%s_%s_%s' % (model_namespace, model_name, model_version)
        if model_key in model_registry:
            model = model_registry[model_key]
        else:
            model = load_model(model_namespace, model_name, model_version)
        command.model = model
        command.inputs = input_transformer(self.request.body)
        return command

    def build_future(self, command):<commit_msg>update registry<commit_after>#!/usr/bin/env python3

import os
import tornado.ioloop
import tornado.web
import tornado.httpserver
import tornado.httputil
import tornado.gen
import json
import pickle
import numpy as np
from hystrix import Command
import asyncio
import fnmatch

from transformers import input_transformer, output_transformer

class PredictCommand(Command):
    inputs = [[]]
    model = None

    def run(self):
        return self.model.predict(self.inputs)

    def fallback(self):
        return 'fallback!'

class MainHandler(tornado.web.RequestHandler):
    @tornado.gen.coroutine
    def post(self, model_namespace, model_name, model_version):
        self.set_header("Content-Type", "application/json")
        command = self.build_command(model_namespace, model_name, model_version)
        output = yield self.build_future(command)
        self.write(output_transformer(output))

    def build_command(self, model_namespace, model_name, model_version):
        command = PredictCommand()
        model_key = '%s_%s_%s' % (model_namespace, model_name, model_version)

        command.name = 'Predict_%s' % model_key
        command.group_name = 'PredictGroup'
        model_key = '%s_%s_%s' % (model_namespace, model_name, model_version)
        if model_key in model_registry:
            model = model_registry[model_key]
            model_registry[model_key] = model
        else:
            model = load_model(model_namespace, model_name, model_version)
        command.model = model
        command.inputs = input_transformer(self.request.body)
        return command

    def build_future(self, command):
{'fraction_non_alphanumeric': 0.08726708074534162, 'fraction_numerical': 0.0006211180124223603, 'mean_word_length': 3.5687943262411346, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7249618', 'n_tokens_mistral': 960, 'n_tokens_neox': 933, 'n_words': 218}