|
|
|
|
|
|
|
|
|
|
|
import sys |
|
|
import time |
|
|
from pathlib import Path |
|
|
|
|
|
import click |
|
|
|
|
|
from dyff.client import Client |
|
|
from dyff.schema.platform import * |
|
|
from dyff.schema.requests import * |
|
|
|
|
|
from app.api.models import PredictionResponse |
|
|
|
|
|
|
|
|
|
|
|
WORKDIR = Path(__file__).resolve().parent |
|
|
|
|
|
|
|
|
@click.command() |
|
|
@click.option( |
|
|
"--account", |
|
|
type=str, |
|
|
required=True, |
|
|
help="Your account ID", |
|
|
) |
|
|
@click.option( |
|
|
"--name", |
|
|
type=str, |
|
|
required=True, |
|
|
help="The name of your detector model. For display and querying purposes only.", |
|
|
) |
|
|
@click.option( |
|
|
"--image", |
|
|
type=str, |
|
|
required=True, |
|
|
help="The Docker image to upload. Must exist in your local Docker deamon.", |
|
|
) |
|
|
@click.option( |
|
|
"--endpoint", |
|
|
type=str, |
|
|
default="predict", |
|
|
help="The endpoint to call on your model to make a prediction.", |
|
|
) |
|
|
def main(account: str, name: str, image: str, endpoint: str) -> None: |
|
|
dyffapi = Client() |
|
|
|
|
|
|
|
|
artifact_id = None |
|
|
service_id = None |
|
|
|
|
|
|
|
|
if artifact_id is None: |
|
|
|
|
|
artifact = dyffapi.artifacts.create(ArtifactCreateRequest(account=account)) |
|
|
click.echo(f"artifact_id = \"{artifact.id}\"") |
|
|
time.sleep(5) |
|
|
|
|
|
dyffapi.artifacts.push(artifact, source=f"docker-daemon:{image}") |
|
|
time.sleep(5) |
|
|
|
|
|
dyffapi.artifacts.finalize(artifact.id) |
|
|
else: |
|
|
artifact = dyffapi.artifacts.get(artifact_id) |
|
|
assert artifact is not None |
|
|
|
|
|
|
|
|
if service_id is None: |
|
|
|
|
|
service_request = InferenceServiceCreateRequest( |
|
|
account=account, |
|
|
name=name, |
|
|
model=None, |
|
|
runner=InferenceServiceRunner( |
|
|
kind=InferenceServiceRunnerKind.CONTAINER, |
|
|
imageRef=EntityIdentifier.of(artifact), |
|
|
resources=ModelResources(), |
|
|
), |
|
|
interface=InferenceInterface( |
|
|
endpoint=endpoint, |
|
|
outputSchema=DataSchema.make_output_schema(PredictionResponse), |
|
|
), |
|
|
) |
|
|
service = dyffapi.inferenceservices.create(service_request) |
|
|
click.echo(f"service_id = \"{service.id}\"") |
|
|
else: |
|
|
service = dyffapi.inferenceservices.get(service_id) |
|
|
assert service is not None |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
|