Exemple #1
0
def predict():
    """
    Image Classification:
    {
        "type": "images",
        "urls": ["https://my-url.com/image.jpg"],
    }
    Text Classification:
    {
        "type": "texts",
        "texts": ["the text that i want to classify"],
    }
    Sequence Classification:
    {
        "type": "sequence",
        "texts": ["the sequence that i want to label"],
    }
    """
    json = request.get_json()

    _type = json['type']
    if _type == "images":
        urls = json["urls"]
        x_train, images = utils.download_urls(urls)
        predictions = label_app.predict(x_train)
    elif _type == "text" or _type == "sequence":
        texts = json["texts"]
        predictions = label_app.predict(texts)
    return jsonify({'predictions': predictions.tolist(), **json})
Exemple #2
0
def score():
    """
    Image Classification:
    {
        "type": "images",
        "urls": ["https://my-url.com/image.jpg"],
    }
    Text Classification:
    {
        "type": "texts",
        "texts": ["the text that i want to classify"],
    }
    Sequence Classification:
    {
        "type": "sequence",
        "texts": ["the sequence that i want to label"],
    }
    """
    json = request.get_json()

    _type = json['type']
    if _type == "images":
        urls = json["urls"]
        x_train, images = utils.download_urls(urls)
        scores = label_app.score(x_train)
    elif _type == "text" or _type == "sequence":
        texts = json["texts"]
        scores = label_app.score(texts)
    return jsonify({'scores': scores.tolist(), 'labels': label_app.label_helper.classes})