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 execute_pipeline(data: str, config: AutoLabelingConfig): label_collection = get_label_collection(config.task_type) model = RequestModelFactory.create(model_name=config.model_name, attributes=config.model_attrs) template = MappingTemplate(label_collection=label_collection, template=config.template) post_processor = PostProcessor(config.label_mapping) labels = pipeline(text=data, request_model=model, mapping_template=template, post_processing=post_processor) labels = create_labels(config.task_type, labels) return labels
def test_gcp_label_detection_pipeline(data_path, cassettes_path): with vcr.use_cassette( str(cassettes_path / 'pipeline_gcp_label_detection.yaml'), mode='once', filter_query_parameters=['key'] ): model = GCPImageLabelDetectionRequestModel(key=os.environ.get('API_KEY_GCP', '')) template = GCPImageLabelDetectionTemplate() filepath = data_path / 'images/1500x500.jpeg' post_processor = PostProcessor({}) labels = pipeline( text=filepath, request_model=model, mapping_template=template, post_processing=post_processor ) labels = labels.dict() assert isinstance(labels, list) assert len(labels) == 1 assert 'label' in labels[0]
def test_amazon_pipeline(cassettes_path): with vcr.use_cassette(str(cassettes_path / 'amazon_comprehend_sentiment.yaml'), mode='once', filter_headers=['authorization']): model = AmazonComprehendSentimentRequestModel( aws_access_key=os.environ.get('AWS_ACCESS_KEY', ''), aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', ''), region_name='us-east-1', language_code='en') template = AmazonComprehendSentimentTemplate() post_processor = PostProcessor({}) labels = pipeline(text='I am very sad.', request_model=model, mapping_template=template, post_processing=post_processor) labels = labels.dict() assert isinstance(labels, list) assert len(labels) == 1 assert 'label' in labels[0]