# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from core.model import ModelWrapper
from maxfw.core import MAX_API, PredictAPI, MetadataAPI
from flask_restplus import fields
from flask import abort

# Set up parser for input data (http://flask-restplus.readthedocs.io/en/stable/parsing.html)
input_parser = MAX_API.model(
    'ModelInput', {
        'text':
        fields.List(
            fields.String,
            required=True,
            description=
            'List of user comments (strings) to be analyzed for toxicity.')
    })

# Creating a JSON response model: https://flask-restplus.readthedocs.io/en/stable/marshalling.html#the-api-model-factory
label_description = {
    'toxic':
    'very bad, unpleasant, or harmful',
    'severe_toxic':
    'extremely bad and offensive',
    'obscene':
    '(of the portrayal or description of sexual matters) offensive or disgusting by accepted standards of '
    'morality and decency',
    'threat':
Exemplo n.º 2
0
from flask_restplus import fields
from werkzeug.datastructures import FileStorage

# Set up parser for image input data
image_parser = MAX_API.parser()
image_parser.add_argument('image',
                          type=FileStorage,
                          location='files',
                          required=True,
                          help="An image file")

label_prediction = MAX_API.model(
    'LabelPrediction', {
        'index':
        fields.String(required=False,
                      description='Labels ranked by highest probability'),
        'caption':
        fields.String(required=True, description='Caption generated by image'),
        'probability':
        fields.Float(required=True, description="Probability of the caption")
    })

predict_response = MAX_API.model(
    'ModelPredictResponse', {
        'status':
        fields.String(required=True, description='Response status message'),
        'predictions':
        fields.List(fields.Nested(label_prediction),
                    description='Predicted captions and probabilities')
    })

Exemplo n.º 3
0
from core.model import ModelWrapper
from flask_restplus import fields
from werkzeug.datastructures import FileStorage
from maxfw.core import MAX_API, PredictAPI

input_parser = MAX_API.parser()
# Example parser for file input
input_parser.add_argument('image', type=FileStorage, location='files',
                          required=True, help='An image file encoded as PNG, '
                                              'Tiff, or JPEG with an arbitrary '
                                              'size')

label_prediction = MAX_API.model('LabelPrediction', {
    'detection_box': fields.List(fields.Float(
        required=True, description='Bounding box for the detected face')),
    'probability': fields.Float(
        required=True, description='Probability of the detected face'),
    'embedding': fields.List(fields.Float(
        required=True, description='Embedding for the detected face'))
})

predict_response = MAX_API.model('ModelPredictResponse', {
    'status': fields.String(
        required=True, description='Response status message'),
    'predictions': fields.List(fields.Nested(label_prediction),
                               description='Bounding boxes, probabilities, and '
                                           'embeddings for the detected faces')})


class ModelPredictAPI(PredictAPI):

    model_wrapper = ModelWrapper()
Exemplo n.º 4
0
input_parser.add_argument(
    'image',
    type=FileStorage,
    location='files',
    required=True,
    help=
    "An image file (JPG/PNG/TIFF). Valid input size: 64 * 64, 128 * 128, 256 * 256"
)

label_prediction = MAX_API.model(
    'NucleusPrediction', {
        'mask':
        fields.List(
            fields.Integer(
                required=True,
                description='Segmented masks of each nucleus. The mask '
                'is compressed by Run-length encoding.')),
        'probability':
        fields.Float(
            required=True,
            description='Predicted probability for presence of the nucleus')
    })

predict_response = MAX_API.model(
    'ModelPredictResponse', {
        'status':
        fields.String(required=True, description='Response status message'),
        'predictions':
        fields.List(fields.Nested(label_prediction))
    })
Exemplo n.º 5
0
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import logging
from core.model import ModelWrapper
from maxfw.core import MAX_API, PredictAPI
from flask_restplus import fields

input_parser = MAX_API.model(
    'ModelInput', {
        'text':
        fields.List(
            fields.String,
            required=True,
            description=
            ('A list of input text to be summarized. '
             'Each entry in the list is treated as a separate input text and so a summary result will be returned for each entry.'
             ))
    })

predict_response = MAX_API.model(
    'ModelPredictResponse', {
        'status':
        fields.String(required=True, description='Response status message.'),
        'summary_text':
        fields.List(
            fields.String,
            required=True,
            description=
Exemplo n.º 6
0
from core.model import ModelWrapper

input_parser = MAX_API.parser()
input_parser.add_argument('image',
                          type=FileStorage,
                          location='files',
                          required=True,
                          help='An image file (encoded as JPEG, PNG or TIFF)')

label_prediction = MAX_API.model(
    'LabelPrediction', {
        'label_id':
        fields.String(required=False,
                      description='Class label identifier',
                      example='n07697313'),
        'label':
        fields.String(
            required=True, description='Class label', example='cheeseburger'),
        'probability':
        fields.Float(required=True,
                     description='Predicted probability for class label',
                     example=0.95)
    })

predict_response = MAX_API.model(
    'ModelPredictResponse', {
        'status':
        fields.String(required=True,
                      description='Response status message',
                      example='ok'),
        'predictions':
        fields.List(fields.Nested(label_prediction),
Exemplo n.º 7
0
#

from core.model import ModelWrapper, read_image

from maxfw.core import MAX_API, PredictAPI, MetadataAPI

from flask_restplus import fields
from werkzeug.datastructures import FileStorage

model_wrapper = ModelWrapper()

# === Labels API

model_label = MAX_API.model(
    'ModelLabel', {
        'id': fields.String(required=True, description='Label identifier'),
        'name': fields.String(required=True, description='Class label')
    })

labels_response = MAX_API.model(
    'LabelsResponse', {
        'count':
        fields.Integer(required=True, description='Number of labels returned'),
        'labels':
        fields.List(
            fields.Nested(model_label),
            description='Class labels that can be predicted by the model')
    })


class ModelLabelsAPI(MetadataAPI):
Exemplo n.º 8
0
from flask_restplus import fields
from werkzeug.datastructures import FileStorage
from flask import make_response, abort
from PIL import Image
import re

from maxfw.core import MAX_API, PredictAPI
from api.pre_process import alignMain
from core.model import ModelWrapper

# Creating a JSON response model: https://flask-restplus.readthedocs.io/en/stable/marshalling.html#the-api-model-factory
label_prediction = MAX_API.model(
    'LabelPrediction', {
        'label_id': fields.String(required=False,
                                  description='Label identifier'),
        'label': fields.String(required=True, description='Class label'),
        'probability': fields.Float(required=True)
    })

# Set up parser for input data (http://flask-restplus.readthedocs.io/en/stable/parsing.html)
input_parser = MAX_API.parser()
# Example parser for file input
input_parser.add_argument('file',
                          type=FileStorage,
                          location='files',
                          required=True,
                          help='An image file (encoded as PNG or JPG/JPEG)')
input_parser.add_argument(
    'mask_type',
    type=str,
Exemplo n.º 9
0
input_parser = MAX_API.parser()
input_parser.add_argument('user_id',
                          type=str,
                          required=True,
                          help='User ID to generate recommendations for')
input_parser.add_argument('num_results',
                          type=int,
                          required=False,
                          default=5,
                          help='Number of items to return')

# Creating a JSON response model: https://flask-restplus.readthedocs.io/en/stable/marshalling.html#the-api-model-factory
item_prediction = MAX_API.model(
    'ItemPrediction', {
        'user': fields.String(required=True, description='User ID'),
        'item': fields.String(required=True, description='Item ID'),
        'prediction': fields.Float(required=True,
                                   description='Predicted score')
    })

predict_response = MAX_API.model(
    'ModelPredictResponse', {
        'status':
        fields.String(required=True, description='Response status message'),
        'predictions':
        fields.List(fields.Nested(item_prediction),
                    description='Recommended items and scores')
    })


class ModelPredictAPI(PredictAPI):
Exemplo n.º 10
0
from core.model import ModelWrapper
from flask_restplus import fields
from werkzeug.datastructures import FileStorage
from maxfw.core import MAX_API, PredictAPI

# Set up parser for input data (http://flask-restplus.readthedocs.io/en/stable/parsing.html)
input_parser = MAX_API.parser()
input_parser.add_argument('image', type=FileStorage, location='files', required=True, help="An image file (RGB/HWC)")


label_prediction = MAX_API.model('LabelPrediction', {
    'label_id': fields.String(required=False, description='Class label identifier'),
    'label': fields.String(required=True, description='Class label'),
    'probability': fields.Float(required=True, description='Predicted probability for the class label')
})


predict_response = MAX_API.model('ModelPredictResponse', {
    'status': fields.String(required=True, description='Response status message'),
    'predictions': fields.List(fields.Nested(label_prediction), description='Predicted class labels and probabilities')
})


class ModelPredictAPI(PredictAPI):

    model_wrapper = ModelWrapper()

    @MAX_API.doc('predict')
    @MAX_API.expect(input_parser)
    @MAX_API.marshal_with(predict_response)
    def post(self):
Exemplo n.º 11
0
from core.model import ModelWrapper

from maxfw.core import MAX_API, PredictAPI

from flask_restplus import Namespace, Resource, fields
from flask import request
from config import MODEL_META_DATA, DEFAULT_CHARS


model_input = MAX_API.model('ModelInput', {
    'seed_text': fields.String(required=True, description='Text to seed generative model'),
    'chars': fields.Integer(default=DEFAULT_CHARS, required=False, description='Number of characters to generate')
})

model_prediction = MAX_API.model('ModelPrediction', {
    'seed_text': fields.String(required=True, description='Seed text used to generate new text'),
    'generated_text': fields.String(required=True, description='Text generated by the model'),
    'full_text': fields.String(required=False, description='Seed text followed by generated text')
})


class ModelPredictAPI(PredictAPI):

    model_wrapper = ModelWrapper()

    @MAX_API.doc('predict')
    @MAX_API.expect(model_input)
    def post(self):
        """Make a prediction given input data"""
        result = {'status': 'error'}
Exemplo n.º 12
0
# See the License for the specific language governing permissions and
# limitations under the License.
#

from core.model import ModelWrapper, read_image
from maxfw.core import MAX_API, PredictAPI, MetadataAPI
from flask_restplus import fields
from werkzeug.datastructures import FileStorage

model_wrapper = ModelWrapper()

# === Labels API

model_label = MAX_API.model(
    'ModelLabel', {
        'id': fields.String(required=True, description='Label identifier'),
        'name': fields.String(required=True, description='Label')
    })

labels_response = MAX_API.model(
    'LabelsResponse', {
        'count':
        fields.Integer(required=True, description='Number of labels returned'),
        'labels':
        fields.List(
            fields.Nested(model_label),
            description='List of labels that can be predicted by the model')
    })


class ModelLabelsAPI(MetadataAPI):
Exemplo n.º 13
0
input_parser = MAX_API.parser()
input_parser.add_argument('image',
                          type=FileStorage,
                          location='files',
                          required=True,
                          help='An image file (encoded as PNG or JPG/JPEG)')

predict_response = MAX_API.model(
    'ModelPredictResponse', {
        'status':
        fields.String(required=True, description='Response status message'),
        'image_size':
        fields.List(
            fields.Integer,
            description=
            "The size of the output image segmentation map (may differ from input image)"
        ),
        'seg_map':
        fields.List(
            fields.List(
                fields.Integer,
                description=
                "Segmentation map containing a predicted class for each pixel")
        )
    })


class ModelLabelsAPI(CustomMAXAPI):
    @MAX_API.doc('labels')
    def get(self):
        """Return the list of labels that can be predicted by the model"""
Exemplo n.º 14
0
input_parser = MAX_API.parser()
input_parser.add_argument('file',
                          type=FileStorage,
                          location='files',
                          required=True,
                          help='An image encoded as JPEG, PNG, or TIFF')

body_parts_prediction = MAX_API.model(
    'body_parts_prediction', {
        'part_id':
        fields.Integer(required=True, description='ID for the body part'),
        'part_name':
        fields.String(required=True, description='Name of the body part'),
        'score':
        fields.Fixed(required=True,
                     description='The prediction score for the body part'),
        'x':
        fields.Integer(required=True,
                       description='X coordinate of the center point of the '
                       'body part'),
        'y':
        fields.Integer(required=True,
                       description='Y coordinate of the center point of the '
                       'body part')
    })

line_prediction = MAX_API.model(
    'LinePrediction', {
        'line':
        fields.List(
            fields.Integer(required=True,
                           description='Coordinates for line '
Exemplo n.º 15
0
    'insult':
    'speak to or treat with disrespect or scornful abuse',
    'identity_hate':
    'hatred, hostility, or violence towards members of a race, ethnicity, nation, religion, gender, '
    'gender identity, sexual orientation or any other designated sector of society'
}

label_prediction = MAX_API.model(
    'LabelPrediction', {
        'toxic':
        fields.Float(required=True, description=label_description['toxic']),
        'severe_toxic':
        fields.Float(required=True,
                     description=label_description['severe_toxic']),
        'obscene':
        fields.Float(required=True, description=label_description['obscene']),
        'threat':
        fields.Float(required=True, description=label_description['threat']),
        'insult':
        fields.Float(required=True, description=label_description['insult']),
        'identity_hate':
        fields.Float(required=True,
                     description=label_description['identity_hate']),
    })

results_response = MAX_API.model(
    "ModelResultResponse", {
        'original_text':
        fields.String(reqired=True, description='User submitted text'),
        'predictions':
        fields.Nested(label_prediction,
                          choices=['simplified', 'traditional'],
                          help="Chinese: simplified or traditional.")
input_parser.add_argument(
    'theta',
    type=int,
    default=1,
    help=
    "Distance threshold for number of candidate words to return. A higher theta returns more"
    "candidate words")

# Creating a JSON response model: https://flask-restplus.readthedocs.io/en/stable/marshalling.html#the-api-model-factory

label_prediction = MAX_API.model(
    'Prediction', {
        'distance':
        fields.String(required=True, description='Label identifier'),
        'candidates':
        fields.List(fields.List(fields.String),
                    description='Nearest candidates')
    })

predict_response = MAX_API.model(
    'ModelPredictResponse', {
        'status':
        fields.String(required=True, description='Response status message'),
        'predictions':
        fields.List(fields.Nested(label_prediction),
                    description='Predicted labels and probabilities')
    })


class ModelPredictAPI(PredictAPI):
Exemplo n.º 17
0
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from core.model import ModelWrapper
from maxfw.core import MAX_API, PredictAPI
from flask_restplus import fields
from flask import abort

# Set up parser for input data (http://flask-restplus.readthedocs.io/en/stable/parsing.html)
input_parser = MAX_API.model(
    'ModelInput', {
        'text':
        fields.List(
            fields.String,
            required=True,
            description=
            'List of claims (strings) to be analyzed for either a positive or negative sentiment.'
        )
    })

with open('assets/labels.txt', 'r') as f:
    class_labels = [x.strip() for x in f]

# Creating a JSON response model: https://flask-restplus.readthedocs.io/en/stable/marshalling.html#the-api-model-factory
label_prediction = MAX_API.model(
    'LabelPrediction', {
        l: fields.Float(required=True, description='Class probability')
        for l in class_labels
    })  # noqa - E741
Exemplo n.º 18
0
from werkzeug.datastructures import FileStorage
from maxfw.core import MAX_API, PredictAPI

# set up parser for image input data
input_parser = MAX_API.parser()
input_parser.add_argument('image',
                          type=FileStorage,
                          location='files',
                          required=True,
                          help='An image file (encoded as PNG or JPG/JPEG)')

predict_response = MAX_API.model(
    'ModelPredictResponse', {
        'status':
        fields.String(required=True, description='Response status message'),
        'text':
        fields.List(
            fields.List(
                fields.String(
                    description='Predicted text from the input image')))
    })


class ModelPredictAPI(PredictAPI):

    model_wrapper = ModelWrapper()

    @MAX_API.doc('predict')
    @MAX_API.expect(input_parser)
    @MAX_API.marshal_with(predict_response)
    def post(self):
        """Make a prediction given input data"""
input_parser = MAX_API.parser()
input_parser.add_argument('first_word', type=str, required=True,
                          help="utf-8 encoded Chinese word.")
input_parser.add_argument('second_word', type=str,
                          help="utf-8 encoded Chinese word.")
input_parser.add_argument('mode', type=str, default='simplified', choices=['simplified', 'traditional'],
                          help="Chinese: simplified or traditional.")
input_parser.add_argument('theta', type=int, default=1,
                          help="Distance threshold for number of candidate words to return. A higher theta returns more "
                               "candidate words.")


# Creating a JSON response model: https://flask-restplus.readthedocs.io/en/stable/marshalling.html#the-api-model-factory

candidates_response = MAX_API.model('CandidatesResponse', {
                    'first_word': fields.List(fields.String, description='Nearest candidates to first_word'),
                    'second_word': fields.List(fields.String, description='Nearest candidates to second_word')
                })

label_prediction = MAX_API.model('Prediction', {
    'distance': fields.Float(required=True, description='Label identifier'),
    'candidates': fields.Nested(candidates_response, required=True, description='candidates')
})

predict_response = MAX_API.model('ModelPredictResponse', {
    'status': fields.String(required=True, description='Response status message'),
    'predictions': fields.List(fields.Nested(label_prediction), description='Predicted labels and probabilities')
})


class ModelPredictAPI(PredictAPI):
Exemplo n.º 20
0
input_parser.add_argument(
    'start_time',
    type=float,
    default=0,
    help=
    'The number of seconds into the audio file the prediction should start at.'
)
input_parser.add_argument('filter',
                          required=False,
                          action='split',
                          help='List of labels to filter (optional)')

label_prediction = MAX_API.model(
    'LabelPrediction', {
        'label_id': fields.String(required=False,
                                  description='Label identifier'),
        'label': fields.String(required=True, description='Audio class label'),
        'probability': fields.Float(required=True)
    })

predict_response = MAX_API.model(
    'ModelPredictResponse', {
        'status':
        fields.String(required=True, description='Response status message'),
        'predictions':
        fields.List(fields.Nested(label_prediction),
                    description='Predicted audio classes and probabilities')
    })


class ModelPredictAPI(PredictAPI):
Exemplo n.º 21
0
from core.model import ModelWrapper, load_array

from maxfw.core import MAX_API, PredictAPI

from flask_restplus import Namespace, Resource, fields
from werkzeug.datastructures import FileStorage
from config import MODEL_META_DATA, DEFAULT_MODEL, MODELS

predict_response = MAX_API.model(
    'ModelPredictResponse', {
        'status':
        fields.String(required=True, description='Response status message'),
        'predictions':
        fields.List(fields.List(fields.Float),
                    description='Predicted values for weather features')
    })

# Set up parser for input data (http://flask-restplus.readthedocs.io/en/stable/parsing.html)
input_parser = MAX_API.parser()
input_parser.add_argument(
    'file',
    type=FileStorage,
    location='files',
    required=True,
    help=
    'Input data to use for prediction, in the form of a numpy array txt file')
input_parser.add_argument('model',
                          type=str,
                          default=DEFAULT_MODEL,
                          choices=MODELS,
                          help='Underlying model to use for prediction')
Exemplo n.º 22
0
      "context": "John lives in Brussels and works for the EU",
      "questions": [
        "Where does John Live?", "What does John do?", "What is his name?"
      ]
    },
    {
      "context": "Jane lives in Paris and works for the UN",
      "questions": [
        "Where does Jane Live?", "What does Jane do?"
      ]
    }
  ]

article = MAX_API.model('Article JSON object', {
    'context': fields.String(required=True, description="Text where answers to questions can be found.",
                             example=context_example),
    'questions': fields.List(fields.String(required=True, description="Questions to be answered from the context.",
                                           example=question_example))
})

input_parser = MAX_API.model('Data JSON object', {
    'paragraphs': fields.List(fields.Nested(article),
                              description="List of paragraphs, each with a context and follow up questions.",
                              example=paragraphs_example)
})

# Creating a JSON response model:
# https://flask-restplus.readthedocs.io/en/stable/marshalling.html#the-api-model-factory

predict_response = MAX_API.model('ModelPredictResponse', {
    'status': fields.String(required=True, description='Response status message'),
    'predictions': fields.List(fields.List(fields.String), description='Predicted answers to questions')
Exemplo n.º 23
0
from maxfw.core import MAX_API, PredictAPI
from core.model import ModelWrapper

# Set up parser for input data (http://flask-restplus.readthedocs.io/en/stable/parsing.html)
input_parser = MAX_API.parser()
input_parser.add_argument(
    'audio',
    type=FileStorage,
    location='files',
    required=True,
    help='A 16 bit, 16 kHz, mono WAV file containing English speech.')

predict_response = MAX_API.model(
    'ModelPredictResponse', {
        'status':
        fields.String(required=True, description='Response status message'),
        'prediction':
        fields.String(required=True, description='Predicted text')
    })


class ModelPredictAPI(PredictAPI):

    model_wrapper = ModelWrapper()

    @MAX_API.doc('predict')
    @MAX_API.expect(input_parser)
    @MAX_API.marshal_with(predict_response)
    def post(self):
        """Generate audio embedding from input data"""
        result = {'status': 'error'}  # set default status
Exemplo n.º 24
0
from flask_restplus import fields
from werkzeug.datastructures import FileStorage
from core.model import ModelWrapper
from maxfw.core import MAX_API, PredictAPI

input_parser = MAX_API.parser()
input_parser.add_argument('text',
                          type=FileStorage,
                          location='files',
                          required=True,
                          help='A text file')

predict_response = MAX_API.model(
    'ModelPredictResponse', {
        'status':
        fields.String(required=True, description='Response status message'),
        'pred_txt':
        fields.String(required=False,
                      description='Generated text based on input')
    })


class ModelPredictAPI(PredictAPI):

    model_wrapper = ModelWrapper()

    @MAX_API.doc('predict')
    @MAX_API.expect(input_parser)
    @MAX_API.marshal_with(predict_response)
    def post(self):
        """Make a prediction given input data"""
        result = {'status': 'error'}
from maxfw.core import MAX_API, PredictAPI
from core.model import ModelWrapper

# set up parser for audio input data
input_parser = MAX_API.parser()
input_parser.add_argument('audio',
                          type=FileStorage,
                          location='files',
                          required=True,
                          help="signed 16-bit PCM WAV audio file")

predict_response = MAX_API.model(
    'ModelPredictResponse', {
        'status':
        fields.String(required=True, description='Response status message'),
        'embedding':
        fields.List(
            fields.List(fields.Float,
                        required=True,
                        description="Generated embedding"))
    })


class ModelPredictAPI(PredictAPI):
    model_wrapper = ModelWrapper()

    @MAX_API.doc('predict')
    @MAX_API.expect(input_parser)
    @MAX_API.marshal_with(predict_response)
    def post(self):
        """Generate audio embedding from input data"""
        result = {'status': 'error'}
Exemplo n.º 26
0
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from maxfw.core import MAX_API, PredictAPI, CustomMAXAPI
from flask_restx import fields
from werkzeug.datastructures import FileStorage
from core.model import ModelWrapper

model_label = MAX_API.model('ModelLabel', {
    'id': fields.String(required=True, description='Class label identifier'),
    'name': fields.String(required=True, description='Class label'),
})

labels_response = MAX_API.model('LabelsResponse', {
    'count': fields.Integer(required=True,
                            description='Number of class labels returned'),
    'labels': fields.List(fields.Nested(model_label),
                          description='Class labels that can be predicted by '
                                      'the model')
})

model_wrapper = ModelWrapper()


class ModelLabelsAPI(CustomMAXAPI):
Exemplo n.º 27
0
#

from core.model import ModelWrapper

from maxfw.core import MAX_API, PredictAPI, MetadataAPI
from flask_restplus import fields
from flask import request


model_wrapper = ModelWrapper()

# === Labels API

model_label = MAX_API.model('ModelLabel', {
    'id': fields.String(required=True, description='Label identifier'),
    'name': fields.String(required=True, description='Entity label'),
    'description': fields.String(required=False, description='Meaning of entity label')
})

labels_response = MAX_API.model('LabelsResponse', {
    'count': fields.Integer(required=True, description='Number of labels returned'),
    'labels': fields.List(fields.Nested(model_label), description='Entity labels that can be predicted by the model')
})

# Reference: http://gmb.let.rug.nl/manual.php
tag_desc = {
    'B-PER': 'Person; entities are limited to individuals that are human or have human characteristics, such as divine entities. B- tag indicates start of a new phrase.',  # noqa
    'I-PER': 'Person; entities are limited to individuals that are human or have human characteristics, such as divine entities.',  # noqa
    'B-GEO': 'Location; entities are limited to geographical entities such as geographical areas and landmasses, bodies of water, and geological formations. B- tag indicates start of a new phrase.',  # noqa
    'I-GEO': 'Location; entities are limited to geographical entities such as geographical areas and landmasses, bodies of water, and geological formations.',  # noqa
    'B-LOC': 'Location; entities are limited to geographical entities such as geographical areas and landmasses, bodies of water, and geological formations. B- tag indicates start of a new phrase.',  # noqa
Exemplo n.º 28
0
input_parser = MAX_API.parser()
# Example parser for file input
input_parser.add_argument('image',
                          type=FileStorage,
                          location='files',
                          required=True,
                          help='An image encoded as JPEG, PNG, or TIFF')

label_prediction = MAX_API.model(
    'LabelPrediction', {
        'age_estimation':
        fields.Integer(required=True,
                       description='Estimated age for the face'),
        'detection_box':
        fields.List(
            fields.Float(required=True),
            description=
            'Bounding box coordinates for the face, in the form of an array of'
            'normalized coordinates [ymin, xmin, ymax, xmax]. Each coordinate is in'
            'the range [0, 1]')
    })

predict_response = MAX_API.model(
    'ModelPredictResponse', {
        'status':
        fields.String(required=True, description='Response status message'),
        'predictions':
        fields.List(
            fields.Nested(label_prediction),
            description='Predicted age and bounding box for each detected face'
Exemplo n.º 29
0
from maxfw.core import MAX_API, PredictAPI
from flask_restplus import fields
from werkzeug.datastructures import FileStorage

# Set up parser for input data (http://flask-restplus.readthedocs.io/en/stable/parsing.html)
input_parser = MAX_API.parser()
# Example parser for file input
input_parser.add_argument('file',
                          type=FileStorage,
                          location='files',
                          required=True)

# Creating a JSON response model: https://flask-restplus.readthedocs.io/en/stable/marshalling.html#the-api-model-factory
label_prediction = MAX_API.model(
    'LabelPrediction', {
        'prediction': fields.Integer(required=True),
        'probability': fields.Float(required=True)
    })

predict_response = MAX_API.model(
    'ModelPredictResponse', {
        'status':
        fields.String(required=True, description='Response status message'),
        'predictions':
        fields.List(fields.Nested(label_prediction),
                    description='Predicted labels and probabilities')
    })


class ModelPredictAPI(PredictAPI):
from core.model import ModelWrapper
from flask_restplus import fields, abort
from werkzeug.datastructures import FileStorage
from maxfw.core import MAX_API, PredictAPI

input_parser = MAX_API.parser()
input_parser.add_argument('image', type=FileStorage, location='files', required=True,
                          help='An image file encoded as PNG with the size 64*64')

label_prediction = MAX_API.model('LabelPrediction', {
    'probability': fields.Float(required=True, description='Probability of the image containing mitosis')
})

predict_response = MAX_API.model('ModelPredictResponse', {
    'status': fields.String(required=True, description='Response status message'),
    'predictions': fields.List(fields.Nested(label_prediction), description='Predicted labels and probabilities')
})


class ModelPredictAPI(PredictAPI):

    model_wrapper = ModelWrapper()

    @MAX_API.doc('predict')
    @MAX_API.expect(input_parser)
    @MAX_API.marshal_with(predict_response)
    def post(self):
        """Make a prediction given input data"""
        result = {'status': 'error'}

        args = input_parser.parse_args()