Exemplo n.º 1
0
Arquivo: main.py Projeto: proyev/K-C
    def get(self):
        # Bind vars to global
        global template_text
        global preprocessed_text
        global current_options

        # Call BERT with reduced options
        bert_result = fill_in(preprocessed_text, current_options, fb)
        text = bert_result[0]
        # update available options
        current_options = bert_result[1]

        # Check if any of the options is used up
        empty = False
        for key in current_options:
            if len(current_options[key]) == 0:
                empty = True
                break
        # Include a warning flag in response
        warn = ""
        if empty:
            warn = "EMPTY"

        # Build response with flask function, default http code is 200 (OK)
        response = make_response({"text": text, "warn": warn})
        # Add header so Angular doesnt complain
        response.headers.add("Access-Control-Allow-Origin", "*")
        return response
Exemplo n.º 2
0
Arquivo: main.py Projeto: proyev/K-C
    def get(self):
        # Bind vars to global
        global template_text
        global preprocessed_text
        global current_options

        # Parse arguments
        parser = reqparse.RequestParser()
        parser.add_argument('perspective',
                            type=str,
                            help='perspective',
                            required=True)
        parser.add_argument('mood', type=str, help='mood', required=True)
        parser.add_argument('name1', type=str, help='name')
        parser.add_argument('age', type=int, help='age')
        args = parser.parse_args()

        # Convert arguments to constructor parameters
        plural = (args["perspective"] == "many")
        age = 0
        if args["age"] is not None:
            age = args["age"]
        # Call constructor
        template_text = con.birthday_constructor(plural, args["mood"],
                                                 args["name1"], age)
        # Preprocess for BERT
        processed_result = preprocess(template_text, args["mood"])
        preprocessed_text = processed_result[0]
        current_options = processed_result[1]
        # Call BERT
        bert_result = fill_in(preprocessed_text, current_options, fb)
        text = bert_result[0]
        # update available options
        current_options = bert_result[1]

        # Build response with flask function, default http code is 200 (OK)
        response = make_response({"text": text})
        # Add header so Angular doesnt complain
        response.headers.add("Access-Control-Allow-Origin", "*")
        return response