Skip to content

Commit

Permalink
Merge branch 'main' into video_inference_fps
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjball authored Aug 13, 2024
2 parents 30c9463 + b1c63d6 commit dbbc8b3
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ repos:
additional_dependencies: ["bandit[toml]"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.4
rev: v0.5.6
hooks:
- id: ruff-format
- id: ruff
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
certifi
chardet==4.0.0
idna==3.7
cycler
kiwisolver>=1.3.1
Expand Down
1 change: 1 addition & 0 deletions roboflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from roboflow.models import CLIPModel, GazeModel # noqa: F401
from roboflow.util.general import write_line


__version__ = "1.1.39"


Expand Down
61 changes: 61 additions & 0 deletions roboflow/adapters/deploymentapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import requests

from roboflow.config import DEDICATED_DEPLOYMENT_URL


class DeploymentApiError(Exception):
pass


def add_deployment(api_key, machine_type, deployment_name, inference_version):
url = f"{DEDICATED_DEPLOYMENT_URL}/add"
response = requests.post(
url,
json={
"api_key": api_key,
# "security_level": security_level,
"machine_type": machine_type,
"deployment_name": deployment_name,
"inference_version": inference_version,
},
)
if response.status_code != 200:
raise DeploymentApiError(f"{response.status_code}: {response.text}")
result = response.json()
return result


def get_deployment(api_key, deployment_id):
url = f"{DEDICATED_DEPLOYMENT_URL}/get"
response = requests.get(url, json={"api_key": api_key, "deployment_id": deployment_id})
if response.status_code != 200:
raise DeploymentApiError(f"{response.status_code}: {response.text}")
result = response.json()
return result


def list_deployment(api_key):
url = f"{DEDICATED_DEPLOYMENT_URL}/list"
response = requests.get(url, json={"api_key": api_key})
if response.status_code != 200:
raise DeploymentApiError(f"{response.status_code}: {response.text}")
result = response.json()
return result


def delete_deployment(api_key, deployment_id):
url = f"{DEDICATED_DEPLOYMENT_URL}/delete"
response = requests.post(url, json={"api_key": api_key, "deployment_id": deployment_id})
if response.status_code != 200:
raise DeploymentApiError(f"{response.status_code}: {response.text}")
result = response.json()
return result


def list_machine_types(api_key):
url = f"{DEDICATED_DEPLOYMENT_URL}/machine_types"
response = requests.get(url, json={"api_key": api_key})
if response.status_code != 200:
raise DeploymentApiError(f"{response.status_code}: {response.text}")
result = response.json()
return result
4 changes: 4 additions & 0 deletions roboflow/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def get_conditional_configuration_variable(key, default):
CLIP_FEATURIZE_URL = get_conditional_configuration_variable("CLIP_FEATURIZE_URL", "CLIP FEATURIZE URL NOT IN ENV")
OCR_URL = get_conditional_configuration_variable("OCR_URL", "OCR URL NOT IN ENV")

DEDICATED_DEPLOYMENT_URL = get_conditional_configuration_variable(
"DEDICATED_DEPLOYMENT_URL", "https://ddploy.roboflow.com"
)

DEMO_KEYS = ["coco-128-sample", "chess-sample-only-api-key"]

TYPE_CLASSICATION = "classification"
Expand Down
84 changes: 84 additions & 0 deletions roboflow/deployment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import json

from roboflow.adapters import deploymentapi
from roboflow.config import load_roboflow_api_key


def add_deployment_parser(subparsers):
deployment_parser = subparsers.add_parser(
"deployment",
help="deployment related commands. type 'roboflow deployment' to see detailed command help",
)
deployment_subparsers = deployment_parser.add_subparsers(title="deployment subcommands")
deployment_machine_type_parser = deployment_subparsers.add_parser("machine_type", help="list machine types")
deployment_add_parser = deployment_subparsers.add_parser("add", help="create a dedicated deployment")
deployment_get_parser = deployment_subparsers.add_parser(
"get", help="show detailed info for a dedicated deployment"
)
deployment_list_parser = deployment_subparsers.add_parser("list", help="list dedicated deployments in a workspace")
deployment_delete_parser = deployment_subparsers.add_parser("delete", help="delete a dedicated deployment")

deployment_machine_type_parser.set_defaults(func=list_machine_types)
deployment_machine_type_parser.add_argument("-a", dest="api_key", help="api key")

deployment_add_parser.set_defaults(func=add_deployment)
deployment_add_parser.add_argument("-a", dest="api_key", help="api key")
# deployment_add_parser.add_argument(
# "-s", dest="security_level", help="security level (protected)", default="protected"
# )
deployment_add_parser.add_argument(
"-m", dest="machine_type", help="machine type, run `roboflow deployment machine_type` to see available options"
)
deployment_add_parser.add_argument(
"-n", dest="deployment_name", help="deployment name, must contain 3-10 lowercase characters"
)
deployment_add_parser.add_argument(
"-v", dest="inference_version", help="inference server version (default: latest)", default="latest"
)

deployment_get_parser.set_defaults(func=get_deployment)
deployment_get_parser.add_argument("-a", dest="api_key", help="api key")
deployment_get_parser.add_argument("-d", dest="deployment_id", help="deployment id")

deployment_list_parser.set_defaults(func=list_deployment)
deployment_list_parser.add_argument("-a", dest="api_key", help="api key")

deployment_delete_parser.set_defaults(func=delete_deployment)
deployment_delete_parser.add_argument("-a", dest="api_key", help="api key")
deployment_delete_parser.add_argument("-d", dest="deployment_id", help="deployment id")


def list_machine_types(args):
api_key = args.api_key or load_roboflow_api_key(None)
ret_json = deploymentapi.list_machine_types(api_key)
print(json.dumps(ret_json, indent=2))


def add_deployment(args):
api_key = args.api_key or load_roboflow_api_key(None)
ret_json = deploymentapi.add_deployment(
api_key,
# args.security_level,
args.machine_type,
args.deployment_name,
args.inference_version,
)
print(json.dumps(ret_json, indent=2))


def get_deployment(args):
api_key = args.api_key or load_roboflow_api_key(None)
ret_json = deploymentapi.get_deployment(api_key, args.deployment_id)
print(json.dumps(ret_json, indent=2))


def list_deployment(args):
api_key = args.api_key or load_roboflow_api_key(None)
ret_json = deploymentapi.list_deployment(api_key)
print(json.dumps(ret_json, indent=2))


def delete_deployment(args):
api_key = args.api_key or load_roboflow_api_key(None)
ret_json = deploymentapi.delete_deployment(api_key, args.deployment_id)
print(json.dumps(ret_json, indent=2))
3 changes: 3 additions & 0 deletions roboflow/roboflowpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import roboflow
from roboflow import config as roboflow_config
from roboflow import deployment
from roboflow.adapters import rfapi
from roboflow.config import APP_URL, get_conditional_configuration_variable, load_roboflow_api_key
from roboflow.models.classification import ClassificationModel
Expand Down Expand Up @@ -192,6 +193,8 @@ def _argparser():
_add_upload_model_parser(subparsers)
_add_get_workspace_project_version_parser(subparsers)
_add_run_video_inference_api_parser(subparsers)
deployment.add_deployment_parser(subparsers)


return parser

Expand Down
3 changes: 2 additions & 1 deletion tests/manual/debugme.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
# f"import {thisdir}/data/cultura-pepino-coco -w wolfodorpythontests -p yellow-auto -c 100".split() # noqa: E501 // docs
# f"import {thisdir}/data/cultura-pepino-yolov8 -w wolfodorpythontests -p yellow-auto -c 100".split() # noqa: E501 // docs
# f"import {thisdir}/data/cultura-pepino-yolov8_voc -w wolfodorpythontests -p yellow-auto -c 100".split() # noqa: E501 // docs
f"import {thisdir}/data/cultura-pepino-yolov5pytorch -w wolfodorpythontests -p yellow-auto -c 100 -n papaiasso".split() # noqa: E501 // docs
# f"import {thisdir}/data/cultura-pepino-yolov5pytorch -w wolfodorpythontests -p yellow-auto -c 100 -n papaiasso".split() # noqa: E501 // docs
# f"import {thisdir}/../datasets/mosquitos -w wolfodorpythontests -p yellow-auto -n papaiasso".split() # noqa: E501 // docs
f"deployment list".split() # noqa: E501 // docs
)
args.func(args)
1 change: 1 addition & 0 deletions tests/manual/useprod
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ cp data/.config-prod data/.config
export API_URL=https://api.roboflow.com
export APP_URL=https://app.roboflow.com
export OBJECT_DETECTION_URL=https://detect.roboflow.one
export DEDICATED_DEPLOYMENT_URL=https://deployment.svc.roboflow.com
1 change: 1 addition & 0 deletions tests/manual/usestaging
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ cp data/.config-staging data/.config
export API_URL=https://api.roboflow.one
export APP_URL=https://app.roboflow.one
export OBJECT_DETECTION_URL=https://lambda-object-detection.staging.roboflow.com
export DEDICATED_DEPLOYMENT_URL=https://deployment.svc.roboflow.one

0 comments on commit dbbc8b3

Please sign in to comment.