|
| 1 | +import os |
| 2 | +from libs.labelbox.src.labelbox import Client |
| 3 | +from libs.labelbox.src.labelbox.schema.ontology import OntologyBuilder, Tool |
| 4 | +from libs.labelbox.src.labelbox.schema.tool_building.classification import Classification, Option |
| 5 | +from libs.labelbox.src.labelbox.schema.tool_building.types import FeatureSchemaAttribute |
| 6 | +from libs.labelbox.src.labelbox.schema.media_type import MediaType |
| 7 | +from libs.labelbox.src.labelbox.schema.ontology_kind import OntologyKind |
| 8 | +import json |
| 9 | + |
| 10 | + |
| 11 | +# client = Client( |
| 12 | +# api_key=os.environ.get('STAGE_API_KEY'), |
| 13 | +# endpoint="https://app.lb-stage.xyz/api/_gql/graphql", |
| 14 | +# rest_endpoint="https://app.lb-stage.xyz/api/api/v1") |
| 15 | + |
| 16 | +client = Client( |
| 17 | + api_key=os.environ.get('LOCALHOST_API_KEY'), |
| 18 | + endpoint="http://localhost:8080/graphql", |
| 19 | + rest_endpoint="http://localhost:3000/api/api/v1") |
| 20 | + |
| 21 | +builder = OntologyBuilder( |
| 22 | + |
| 23 | + tools=[ |
| 24 | + Tool( |
| 25 | + name="Auto OCR", |
| 26 | + tool=Tool.Type.BBOX, |
| 27 | + attributes=[ |
| 28 | + FeatureSchemaAttribute( |
| 29 | + attributeName="auto-ocr", |
| 30 | + attributeValue="true" |
| 31 | + ) |
| 32 | + ], |
| 33 | + classifications=[ |
| 34 | + Classification( |
| 35 | + name="Auto ocr text class value", |
| 36 | + instructions="This is an auto OCR text value classification", |
| 37 | + class_type=Classification.Type.TEXT, |
| 38 | + scope=Classification.Scope.GLOBAL, |
| 39 | + attributes=[ |
| 40 | + FeatureSchemaAttribute( |
| 41 | + attributeName="auto-ocr-text-value", |
| 42 | + attributeValue="true" |
| 43 | + ) |
| 44 | + ] |
| 45 | + ) |
| 46 | + ] |
| 47 | + ) |
| 48 | + ] |
| 49 | +) |
| 50 | + |
| 51 | +# client.create_ontology("Auto OCR ontology", builder.asdict(), media_type=MediaType.Document) |
| 52 | + |
| 53 | +builder = OntologyBuilder( |
| 54 | + classifications=[ |
| 55 | + Classification( |
| 56 | + name="prompt message scope text classification", |
| 57 | + instructions="This is a prompt message scoped text classification", |
| 58 | + class_type=Classification.Type.TEXT, |
| 59 | + scope=Classification.Scope.INDEX, |
| 60 | + attributes=[ |
| 61 | + FeatureSchemaAttribute( |
| 62 | + attributeName="prompt-message-scope", |
| 63 | + attributeValue="true" |
| 64 | + ) |
| 65 | + ] |
| 66 | + ) |
| 67 | + ] |
| 68 | +) |
| 69 | + |
| 70 | +# client.create_ontology('MMC Ontology with prompt message scope class', builder.asdict(), media_type=MediaType.Conversational, ontology_kind=OntologyKind.ModelEvaluation) |
| 71 | + |
| 72 | +builder = OntologyBuilder( |
| 73 | + classifications=[ |
| 74 | + Classification( |
| 75 | + name="Requires connection checklist classification", |
| 76 | + instructions="This is a requires connection checklist classification", |
| 77 | + class_type=Classification.Type.CHECKLIST, |
| 78 | + scope=Classification.Scope.GLOBAL, |
| 79 | + attributes=[ |
| 80 | + FeatureSchemaAttribute( |
| 81 | + attributeName="required-connection", |
| 82 | + attributeValue="true" |
| 83 | + ) |
| 84 | + ], |
| 85 | + options=[ |
| 86 | + Option( |
| 87 | + value='First option' |
| 88 | + ), |
| 89 | + Option( |
| 90 | + value='Second option' |
| 91 | + ) |
| 92 | + ] |
| 93 | + ) |
| 94 | + ] |
| 95 | +); |
| 96 | + |
| 97 | +# client.create_ontology('Image ontology with requires connection classes', builder.asdict(), media_type=MediaType.Image) |
| 98 | + |
| 99 | + |
| 100 | +feature_schema = client.upsert_feature_schema(Tool(name='Auto OCR from upsert feature schema', tool=Tool.Type.BBOX, attributes=[FeatureSchemaAttribute(attributeName='auto-ocr', attributeValue='true')]).asdict()) |
| 101 | +fetched_feature_schema = client.get_feature_schema(feature_schema.uid) |
| 102 | +feature_schemas_with_name = client.get_feature_schemas('Auto OCR') |
| 103 | + |
| 104 | +# Iterate over the feature schemas |
| 105 | +for schema in feature_schemas_with_name: |
| 106 | + print(schema) |
0 commit comments