def post(self, *args, **kwargs): response = self.request.data['response'] label_mapping = self.request.data['label_mapping'] project = get_object_or_404(Project, pk=self.kwargs['project_id']) task = TaskFactory.create(project.project_type) labels = task.label_collection(response) post_processor = PostProcessor(label_mapping) labels = post_processor.transform(labels) return Response(labels.dict(), status=status.HTTP_200_OK)
def post(self, *args, **kwargs): response = self.request.data['response'] template = self.request.data['template'] project = get_object_or_404(Project, pk=self.kwargs['project_id']) task = TaskFactory.create(project.project_type) template = MappingTemplate(label_collection=task.label_collection, template=template) labels = template.render(response) if not labels.dict(): raise SampleDataException() return Response(labels.dict(), status=status.HTTP_200_OK)
def execute_pipeline(text: str, project_type: str, model_name: str, model_attrs: dict, template: str, label_mapping: dict): task = TaskFactory.create(project_type) model = RequestModelFactory.create(model_name=model_name, attributes=model_attrs) template = MappingTemplate(label_collection=task.label_collection, template=template) post_processor = PostProcessor(label_mapping) labels = pipeline(text=text, request_model=model, mapping_template=template, post_processing=post_processor) return labels.dict()
def filter_by_task(cls, task_name: str) -> List[Option]: task = TaskFactory.create(task_name) return [option for option in cls.options if option.task == task or option.task == GenericTask]