Skip to content

Commit db0c449

Browse files
committed
initial version
1 parent 5c2e4c8 commit db0c449

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

roboflow/adapters/rfapi.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import requests
77
from requests_toolbelt.multipart.encoder import MultipartEncoder
88

9-
from roboflow.config import API_URL, DEFAULT_BATCH_NAME, DEFAULT_JOB_NAME
9+
from roboflow.config import API_URL, DEFAULT_BATCH_NAME, DEFAULT_JOB_NAME, ROBOFLOW_RUNNER_URL
1010
from roboflow.util import image_utils
1111

1212

@@ -205,3 +205,42 @@ def _save_annotation_error(image_id, response):
205205
else:
206206
errmsg += f"bad response: {response.status_code}: {responsejson}"
207207
return UploadError(errmsg)
208+
209+
210+
def add_runner(api_key, security_level, cloud_provider, machine_type, runner_name, inference_version):
211+
url = f"{ROBOFLOW_RUNNER_URL}/create"
212+
response = requests.post(url, json={'api_key': api_key, 'security_level': security_level,
213+
'cloud_provider': cloud_provider, 'machine_type': machine_type,
214+
'runner_name': runner_name, 'inference_version': inference_version})
215+
if response.status_code != 200:
216+
raise RoboflowError(response.text)
217+
result = response.json()
218+
return result
219+
220+
221+
def get_runner(api_key, runner_id):
222+
url = f"{ROBOFLOW_RUNNER_URL}/get"
223+
response = requests.get(url, json={'api_key': api_key, 'runner_id': runner_id})
224+
if response.status_code != 200:
225+
raise RoboflowError(response.text)
226+
result = response.json()
227+
return result
228+
229+
230+
def list_runner(api_key):
231+
url = f"{ROBOFLOW_RUNNER_URL}/list"
232+
response = requests.get(url, json={'api_key': api_key})
233+
if response.status_code != 200:
234+
raise RoboflowError(response.text)
235+
result = response.json()
236+
return result
237+
238+
239+
def delete_runner(api_key, runner_id):
240+
url = f"{ROBOFLOW_RUNNER_URL}/delete"
241+
response = requests.post(url, json={'api_key': api_key, 'runner_id': runner_id})
242+
if response.status_code != 200:
243+
raise RoboflowError(response.text)
244+
result = response.json()
245+
return result
246+

roboflow/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ def get_conditional_configuration_variable(key, default):
6363
CLIP_FEATURIZE_URL = get_conditional_configuration_variable("CLIP_FEATURIZE_URL", "CLIP FEATURIZE URL NOT IN ENV")
6464
OCR_URL = get_conditional_configuration_variable("OCR_URL", "OCR URL NOT IN ENV")
6565

66+
ROBOFLOW_RUNNER_URL = get_conditional_configuration_variable("ROBOFLOW_RUNNER_URL", "https://runner.svc.roboflow.one")
67+
6668
DEMO_KEYS = ["coco-128-sample", "chess-sample-only-api-key"]
6769

6870
TYPE_CLASSICATION = "classification"

roboflow/roboflowpy.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,23 @@ def infer(args):
161161
print(group)
162162

163163

164+
def add_runner(args):
165+
runner_json = rfapi.add_runner(args.api_key, args.security_level, args.cloud_provider, args.machine_type, args.runner_name, args.inference_version)
166+
print(json.dumps(runner_json, indent=2))
167+
168+
def get_runner(args):
169+
runner_json = rfapi.get_runner(args.api_key, args.runner_id)
170+
print(json.dumps(runner_json, indent=2))
171+
172+
def list_runner(args):
173+
runner_json = rfapi.list_runner(args.vapi_key)
174+
print(json.dumps(runner_json, indent=2))
175+
176+
def delete_runner(args):
177+
runner_json = rfapi.delete_runner(args.api_key, args.runner_id)
178+
print(json.dumps(runner_json, indent=2))
179+
180+
164181
def _argparser():
165182
parser = argparse.ArgumentParser(description="Welcome to the roboflow CLI: computer vision at your fingertips 🪄")
166183
subparsers = parser.add_subparsers(title="subcommands")
@@ -173,6 +190,7 @@ def _argparser():
173190
_add_workspaces_parser(subparsers)
174191
_add_upload_model_parser(subparsers)
175192
_add_get_workspace_project_version_parser(subparsers)
193+
_add_runner_parser(subparsers)
176194

177195
return parser
178196

@@ -458,6 +476,37 @@ def _add_login_parser(subparsers):
458476
login_parser.set_defaults(func=login)
459477

460478

479+
def _add_runner_parser(subparsers):
480+
runner_parser = subparsers.add_parser(
481+
"runner",
482+
help="runner related commands. type 'roboflow runner' to see detailed command help",
483+
)
484+
runner_subparsers = runner_parser.add_subparsers(title="runner subcommands")
485+
runner_add_parser = runner_subparsers.add_parser("add", help="create a new runner")
486+
runner_get_parser = runner_subparsers.add_parser("get", help="show detailed info for a runner")
487+
runner_list_parser = runner_subparsers.add_parser("list", help="list runners in a workspace")
488+
runner_delete_parser = runner_subparsers.add_parser("delete", help="delete a runner")
489+
490+
runner_add_parser.set_defaults(func=add_runner)
491+
runner_add_parser.add_argument("api_key", help="api key")
492+
runner_add_parser.add_argument("security_level", help="security level (protected)", default="protected")
493+
runner_add_parser.add_argument("cloud_provider", help="cloud provider (gcp)", default="gcp")
494+
runner_add_parser.add_argument("machine_type", help="machine type (n1-standard-4-cpu, g2-standard-8-cpu)", default="n1-standard-4-cpu")
495+
runner_add_parser.add_argument("runner_name", help="runner name")
496+
runner_add_parser.add_argument("inference_version", help="inference server version (docker image tag)", default="latest")
497+
498+
runner_get_parser.set_defaults(func=get_runner)
499+
runner_get_parser.add_argument("api_key", help="api key")
500+
runner_get_parser.add_argument("runner_id", help="runner id")
501+
502+
runner_list_parser.set_defaults(func=list_runner)
503+
runner_list_parser.add_argument("api_key", help="api key")
504+
505+
runner_delete_parser.set_defaults(func=delete_runner)
506+
runner_delete_parser.add_argument("api_key", help="api key")
507+
runner_delete_parser.add_argument("runner_id", help="runner id")
508+
509+
461510
def main():
462511
parser = _argparser()
463512
args = parser.parse_args()

0 commit comments

Comments
 (0)