def login(key, host, no_web, relogin): # type: ignore key: str = next(iter(key), None) # type: ignore host = host.strip("/") login = user_settings.get("userLogin") if login and not relogin: login = click.style(login, fg="blue", bold=True) website = user_settings.api_url.strip("/api") click.echo(f"You are already logged in as {login} ({website}).") click.echo("Use the `--relogin` flag to force relogin.") return if key is None: base_url = host.strip("/api") web_url = f"{base_url}/settings/access-tokens" styled_url = click.style(web_url, fg="blue", bold=True) click.echo("Retrieve your API key from {}".format(styled_url)) if not no_web: import webbrowser webbrowser.open(web_url) key = click.prompt(click.style("Paste your API key")).strip() if len(key) != 36: click.echo(click.style("Key must be 36 characters long.")) user_settings.api_url = host user_settings.api_key = key spinner = Spinner("Validating API key") try: api = ApiClient() user = api.viewer() user_settings.set("userLogin", user.login) user_settings.set("userName", user.name) spinner.done("Successfully logged in.") hello = click.style(user.display_name, fg="blue", bold=True) click.echo(f"Hello, {hello}!") except Exception as ex: spinner.done( click.style( f"Error connecting to API {user_settings.api_url}!", fg="red", bold=True, )) user_settings.api_url = None user_settings.api_key = None user_settings.set("userLogin", None) user_settings.set("userName", None) print(ex)
def create_agent(name: str) -> dict: api = ApiClient() # fmt: off results = api.execute(""" mutation CreateAgent($name: String!, $version: String!) { createAgent(name: $name, version: $version) { agent { id } token } } """, params=dict(name=name, version=get_version())) # fmt: on return results
def upload(path): query = """ mutation CreateFlow($str: String!) { createFlow(yaml: $str) { id name } } """ with open(path) as fp: config = fp.read() api = ApiClient() results = api.execute(query, params={"str": config}) flow = results.get("createFlow") click.echo(click.style("Flow successfully created!", bold=True)) click.echo(f"ID: {flow.get('id')}") click.echo(f"Name: {flow.get('name')}")
from typing import ClassVar, get_type_hints from datatorch.api import ApiClient, Annotation, BoundingBox, Where client = ApiClient( api_key="fa2c325a-fd78-4bc6-827f-90242530bebd", api_url="http://localhost:4000" ) project = client.project("68ca53cc-5820-4c01-9bf3-abc9e384fff4") labels = project.labels() files = project.files(where=Where(path__starts_with="dataset")) print(len(files)) # f = client.file("7b1e2d05-89ed-40fe-b2aa-9368633b8748") # anno = Annotation(label=labels[0]) # anno.add(BoundingBox.create(0, 0, 100, 100)) # f.add(anno) # print(anno.__dict__) # print(f.__dict__)
# should be imported min_score = 0.8 # If both import options are enabled the script will create two sources per # annotations, one as a segmentation the other as a bounding box. # Import bounding boxes from the coco format import_bbox = False # Import segmentations from the coco format import_segmentation = True # ----- Script ----- # Connect to DataTorch api = ApiClient() project = api.project(project_id) labels = project.labels() print_project(project) def category_in_project(name: str) -> Label: """ Returns category in project """ for cat in labels: if cat.name.lower() == name.lower(): return cat return None # Load coco categories coco = COCO(anno_file) cats = coco.loadCats(coco.getCatIds())