labels.py
1 """ 2 Defines API paths for labels endpoints. 3 """ 4 5 from typing import List 6 7 from fastapi import APIRouter, Body 8 9 from .. import application 10 from ..route import EncodingAPIRoute 11 12 router = APIRouter(route_class=EncodingAPIRoute) 13 14 15 @router.post("/label") 16 def label(text: str = Body(...), labels: List[str] = Body(...)): 17 """ 18 Applies a zero shot classifier to text using a list of labels. Returns a list of 19 {id: value, score: value} sorted by highest score, where id is the index in labels. 20 21 Args: 22 text: input text 23 labels: list of labels 24 25 Returns: 26 list of {id: value, score: value} per text element 27 """ 28 29 return application.get().label(text, labels) 30 31 32 @router.post("/batchlabel") 33 def batchlabel(texts: List[str] = Body(...), labels: List[str] = Body(...)): 34 """ 35 Applies a zero shot classifier to list of text using a list of labels. Returns a list of 36 {id: value, score: value} sorted by highest score, where id is the index in labels per 37 text element. 38 39 Args: 40 texts: list of text 41 labels: list of labels 42 43 Returns: 44 list of {id: value score: value} per text element 45 """ 46 47 return application.get().label(texts, labels)